Go to the documentation of this file.00001
00002
00003
00005
00006 #ifndef QUERY_NODE_H
00007 #define QUERY_NODE_H
00008
00009 #include "../common/utilit.h"
00010 #include "ConcHolder.h"
00011 #include "../PCRE/pcre_rml.h"
00012
00013
00019 class CQueryNode
00020 {
00021 public:
00023 bool m_bAtomic;
00024
00026 bool m_bNegated;
00027
00029 string m_Source;
00031 vector<CTokenNo> m_Occurrences;
00032
00034 bool m_bUseNodeIndices;
00036 vector<BYTE> m_OccurrenceNodeIndices;
00037
00039 bool m_bUseTokenIdxs;
00041 vector<DWORD> m_OccurrenceTokenIdxs;
00042
00044 vector<CHit> m_Hits;
00046 const CConcHolder* m_pHolder;
00048 vector<size_t> m_ChunkLengths;
00050 vector<int> m_CacheIds;
00051
00052
00053 CQueryNode(bool bUseNodeIndices=false, bool bUseTokenIdxs=false, const CConcHolder *holder=NULL)
00054 : m_bAtomic(false),
00055 m_bNegated(false),
00056 m_bUseNodeIndices(bUseNodeIndices),
00057 m_bUseTokenIdxs(bUseTokenIdxs),
00058 m_pHolder(holder)
00059 {};
00060 virtual ~CQueryNode();
00061
00062 virtual void Evaluate();
00063 virtual void EvaluateWithoutHits();
00064
00066 void SetNegation(bool Value);
00068 bool GetNegation() const;
00069 void AddOccurrences(const CQueryNode& FromNode, int start, int end);
00070 void ClearAndReserveOccurrences(int size);
00071 void SwapOccurrences(CQueryNode& Node);
00072
00074 void ConvertOccurrencesToHits (bool bUniqueHits);
00076 void ConvertOccurrencesToHitsForPatterns (bool bUniqueHits);
00078 void SetHolder(const CConcHolder* pHolder);
00079 virtual size_t GetNodeFrequenceByNodeIndex(size_t NodeIndex) const;
00080 };
00081
00086 class CQueryBinaryOperationNode : public CQueryNode
00087 {
00089 void hits_add(const CQueryNode& NodeFrom, vector<CHit>::const_iterator First);
00090
00091 protected:
00093 CQueryNode* m_pChild1;
00095 CQueryNode* m_pChild2;
00096 public:
00097 CQueryBinaryOperationNode() : m_pChild1(NULL), m_pChild2(NULL) {};
00098 CQueryBinaryOperationNode(CQueryNode *dtr1, CQueryNode *dtr2)
00099 : CQueryNode(false,false), m_pChild1(dtr1), m_pChild2(dtr2)
00100 {};
00101
00102 void Create(const CConcHolder* pHolder, CQueryNode* child1, CQueryNode* child2, string Operation);
00103 virtual ~CQueryBinaryOperationNode();
00104
00106 void hits_and_positions_union();
00108 void hits_and_positions_intersection();
00110 void hits_and_positions_difference();
00111
00112 size_t GetNodeFrequenceByNodeIndex(size_t NodeIndex) const;
00113 };
00114
00116 class CQueryAndOperation : public CQueryBinaryOperationNode
00117 {
00118 public:
00119 CQueryAndOperation();
00120 void Evaluate();
00121 };
00122
00124 class CQueryOrOperation : public CQueryBinaryOperationNode
00125 {
00126 public:
00127 CQueryOrOperation();
00128 void Evaluate( );
00129 };
00130
00132 class CQueryTokenNode : public CQueryNode
00133 {
00135 vector<DWORD> m_IndexItems;
00136
00137 string m_IndexName;
00138
00139 bool m_bChunk;
00140
00141
00142 bool BuildRegExp(string RegExpStr, vector<DWORD>& IndexItems);
00143 public:
00144
00145 BYTE m_NodeIndex;
00146
00147 CQueryTokenNode(int NodeIndex);
00148 virtual ~CQueryTokenNode();
00149
00151 bool CreateTokenPattern(const CConcHolder* pHolder, const char* src, bool bRegularExpession, bool bExact=false);
00153 bool CreateThesPattern(const CConcHolder* pHolder,const char* src);
00155 bool CreateMorphAnnotationPattern(const CConcHolder* pHolder,const char* src, const char* IndexName);
00157 bool CreateFileList(const CConcHolder* pHolder,const char* src);
00159 bool CreateChunkPattern(const CConcHolder* pHolder, const char* ChunkTypeStr);
00161 bool CreateNodeByIndexName(const CConcHolder* pHolder, const char* IndexName, const char* Value, bool bRegularExpession);
00162
00163 void EvaluateWithoutHits();
00164 void Evaluate();
00165 size_t GetNodeFrequenceByNodeIndex(size_t NodeIndex) const;
00166
00167 };
00168
00169
00174 class CQuerySequenceNode : public CQueryNode
00175 {
00176 vector<BYTE> m_Distances;
00177 vector<CQueryTokenNode*> m_Items;
00178
00180 bool AddDistance(const char* s);
00181
00182 public:
00183
00184 CQuerySequenceNode();
00185 virtual ~CQuerySequenceNode();
00187 bool Create(const CConcHolder* pHolder, const vector<const CQueryNode*>& SequenceObj, const vector<string>& Distances);
00188
00189 void EvaluateWithoutHits();
00190 void Evaluate();
00191 size_t GetNodeFrequenceByNodeIndex(size_t NodeIndex) const;
00192 };
00193
00198 class CQueryNearNode : public CQueryNode
00199 {
00201 CQueryNode* m_pChild1;
00203 CQueryNode* m_pMiddleChild;
00205 CQueryNode* m_pChild2;
00207 BYTE m_Distance;
00208
00210 bool ReadDistanceFromString(const char* s);
00211
00212
00213 public:
00214
00215 CQueryNearNode();
00216 virtual ~CQueryNearNode();
00218 bool Create(const CConcHolder* pHolder, const char* distance_str, CQueryNode* child1, CQueryNode* child2, CQueryNode* child3 = 0);
00219 void Evaluate();
00220 size_t GetNodeFrequenceByNodeIndex(size_t NodeIndex) const;
00221
00222 };
00223
00227 class CQueryWithNode : public CQueryBinaryOperationNode
00228 {
00229 void OccurIntersectionWithTokenIds();
00230 public:
00231 CQueryWithNode();
00233 bool Create(const CConcHolder* pHolder, CQueryNode* child1, CQueryNode* child2);
00234 void EvaluateWithoutHits();
00235 void Evaluate();
00236 };
00237
00247 extern void GetWordForms (const MorphLanguageEnum Langua, const string& src, set<string>& WordForms);
00248
00249
00250 #endif