-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuery.cpp
More file actions
117 lines (105 loc) · 2.58 KB
/
Query.cpp
File metadata and controls
117 lines (105 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Query.cpp: implementation of the CQuery class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ARS.h"
#include "KeyWord.h"
#include "ARSDocument.h"
#include "IndexTermsInDoc.h"
#include "FilePrepare.h"
#include "DBManpulation.h"
#include "Indexer.h"
#include "Query.h"
#include "SearchEngine.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
extern CDBManpulation ARSdb;
extern CFilePrepare fpDocs;
extern CSearchEngine ARSsearcher;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CQuery::CQuery()
{
}
CQuery::~CQuery()
{
delete [] SimDocList;
delete [] SimTermList;
}
BOOL CQuery::ProcessQuery(char* QueryValue, BOOL bSearchType)
{
char* token;
BOOL bState = TRUE, bEmpty = TRUE;
LONG Index;
double* QueryVector = new double[ARSdb.MaxTerm+1];
if(QueryVector == NULL)
{
AfxMessageBox("FAIL WITH Allocating DocVector");
exit(0);
}
memset( QueryVector, 0, (ARSdb.MaxTerm+1)*8);
token = ::strtok(QueryValue, (char*)fpDocs.seps);
while(token != NULL && strlen(token) > 14)
token = ::strtok(NULL, (char*)fpDocs.seps);
while(token != NULL)
{
if( !ARSdb.MatchCommonWord(token) )
{ // if the token not in the StopList do ...
if( ARSdb.GetTermInfoByName(token, Index) )
{
bEmpty = FALSE;
QueryVector[Index-1] = 1;
}
}
do{
token = ::strtok(NULL, (char*)fpDocs.seps);
}
while(token != NULL && strlen(token) > 14);
}
if(!bEmpty)
{// Query_hh now is Qtransposed, because the of passing data
Query_hh = mwArray(1,ARSdb.MaxTerm, QueryVector);
//Query_hh = //m_V(223, colon())+
// m_V(498, colon());
FoldInQuery();
//SimDocList[0].nItem = -1;
//SimTermList[0].nItem = -1;
if(bSearchType == 0)
{
bState = ARSsearcher.FindSimilarDoc(SimDocList, m_V);
}
else
{
if(bSearchType == 1)
{
bState = ARSsearcher.FindSimilarTerm(SimTermList, m_U);
}
else
{
bState = ARSsearcher.FindSimilarDoc(SimDocList, m_V);
bState = ARSsearcher.FindSimilarTerm(SimTermList, m_U);
}
}
}
else
{
AfxMessageBox("Query is out of domain to document collection");
bState = FALSE;
}
delete[] QueryVector;
return bState;
}
BOOL CQuery::FoldInQuery()
{
BOOL bState = TRUE;
Query_hh = Query_hh * mwScaleofTerms;
return bState;
}
void CQuery::DoScaleofTerms()
{
mwScaleofTerms = m_U * inv(m_S);
}