资源简介
文本搜索引擎,c++实现,南大数据结构期末大作业
代码片段和文件信息
#include “SearchEngine.h“
#include “iostream“
using namespace std;
//extern linkTable *lkhead;
double *matrix_mul(SMatrix *sm double *pr);
bool matrix_equal(double * double *);
static int sm_sum = 0;
double average = 1.0 / FILE_SUM;
SMatrix *create_sm(linkNodeTable *node) {
if (node == NULL)
return NULL;
int count = 0;
linkTable *pnode = node;
while (pnode) {
sm_sum += pnode->indegree;
pnode = pnode->next;
}
SMatrix *sm = new SMatrix[sm_sum];
int outdegree[FILE_SUM];
for (int i = 0; i < FILE_SUM; ++i)
outdegree[i] = 0;
while (node) {
for (int i = 0; i < node->indegree; ++i) {
sm[count].row = node->index;
sm[count].col = node->link_text[i];
outdegree[sm[count].col]++;
count++;
}
node = node->next;
}
for (int i = 0; i < sm_sum; ++i)
sm[i].value = 1 / outdegree[sm[i].col];
return sm;
}
double *page_rank(linkTable *lkh) {
SMatrix *smatrix = create_sm(lkh);
double *PRresult = new double[FILE_SUM];
for (int i = 0; i < FILE_SUM; ++i)
PRresult[i] = average;
double *newPRresult = matrix_mul(smatrix PRresult);
while (!matrix_equal(PRresult newPRresult)) {
double *tmp = newPRresult;
newPRresult = NULL;
delete tmp;
newPRresult = matrix_mul(smatrix PRresult);
}
delete newPRresult;
return PRresult;
}
double *matrix_mul(SMatrix *sm double *pr) {
double *result = new double[FILE_SUM];
for (int i = 0; i < FILE_SUM; ++i)
result[i] = 0;
for (int i = 0; i < sm_sum; ++i)
result[sm[i].row] = result[sm[i].row] + 0.85 * sm[i].value * pr[sm[i].col] + 0.15 * average;
return result;
}
bool matrix_equal(double *mdest double *msrc) {
bool equal = true;
for (int i = 0; i < FILE_SUM; ++i)
if (mdest[i] != msrc[i]) {
equal = false;
mdest[i] = msrc[i];
}
return equal;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 116224 2016-01-10 04:12 SearchEngine\Debug\SearchEngine.exe
文件 887024 2016-01-10 04:12 SearchEngine\Debug\SearchEngine.ilk
文件 1249280 2016-01-10 04:12 SearchEngine\Debug\SearchEngine.pdb
文件 112316 2016-01-10 04:01 SearchEngine\SearchEngine\Debug\PageRank.obj
文件 244515 2016-01-10 04:08 SearchEngine\SearchEngine\Debug\ReadDoc.obj
文件 147224 2016-01-10 04:12 SearchEngine\SearchEngine\Debug\RunSearch.obj
文件 1619 2016-01-10 04:12 SearchEngine\SearchEngine\Debug\SearchEngine.log
文件 106508 2016-01-10 04:01 SearchEngine\SearchEngine\Debug\SearchEngine.obj
文件 3974 2016-01-10 04:12 SearchEngine\SearchEngine\Debug\SearchEngine.tlog\cl.command.1.tlog
文件 22132 2016-01-10 04:12 SearchEngine\SearchEngine\Debug\SearchEngine.tlog\CL.read.1.tlog
文件 4572 2016-01-10 04:12 SearchEngine\SearchEngine\Debug\SearchEngine.tlog\CL.write.1.tlog
文件 1986 2016-01-10 04:12 SearchEngine\SearchEngine\Debug\SearchEngine.tlog\li
文件 3606 2016-01-10 04:12 SearchEngine\SearchEngine\Debug\SearchEngine.tlog\li
文件 1090 2016-01-10 04:12 SearchEngine\SearchEngine\Debug\SearchEngine.tlog\li
文件 185 2016-01-10 04:12 SearchEngine\SearchEngine\Debug\SearchEngine.tlog\SearchEngine.lastbuildstate
文件 125037 2016-01-10 04:01 SearchEngine\SearchEngine\Debug\SearchTreeFunc.obj
文件 125159 2016-01-10 04:07 SearchEngine\SearchEngine\Debug\SEMain.obj
文件 379904 2016-01-10 04:12 SearchEngine\SearchEngine\Debug\vc120.idb
文件 413696 2016-01-10 04:12 SearchEngine\SearchEngine\Debug\vc120.pdb
文件 22408777 2015-12-14 15:44 SearchEngine\SearchEngine\documents.txt
文件 409930 2015-12-14 15:47 SearchEngine\SearchEngine\li
文件 1829 2016-01-10 03:50 SearchEngine\SearchEngine\PageRank.cpp
文件 3247 2016-01-10 04:08 SearchEngine\SearchEngine\ReadDoc.cpp
文件 7346 2016-01-10 04:12 SearchEngine\SearchEngine\RunSearch.cpp
文件 968 2016-01-10 03:31 SearchEngine\SearchEngine\SearchEngine.h
文件 4309 2016-01-10 03:21 SearchEngine\SearchEngine\SearchEngine.vcxproj
文件 1415 2016-01-10 03:21 SearchEngine\SearchEngine\SearchEngine.vcxproj.filters
文件 1596 2016-01-09 14:45 SearchEngine\SearchEngine\SearchTreeFunc.cpp
文件 911 2016-01-10 04:05 SearchEngine\SearchEngine\SEMain.cpp
文件 8192000 2016-01-10 04:18 SearchEngine\SearchEngine.sdf
............此处省略10个文件信息
评论
共有 条评论