00001 /*========================================================================== 00002 * Copyright (c) 2004 University of Massachusetts. All Rights Reserved. 00003 * 00004 * Use of the Lemur Toolkit for Language Modeling and Information Retrieval 00005 * is subject to the terms of the software license set forth in the LICENSE 00006 * file included with this software, and also available at 00007 * http://www.lemurproject.org/license.html 00008 * 00009 *========================================================================== 00010 */ 00011 00012 00013 // 00014 // InferenceNetworkBuilder 00015 // 00016 // 8 March 2004 -- tds 00017 // 00018 00019 #ifndef INDRI_INFERENCENETWORKBUILDER_HPP 00020 #define INDRI_INFERENCENETWORKBUILDER_HPP 00021 00022 #include "indri/QuerySpec.hpp" 00023 #include "indri/Repository.hpp" 00024 #include "indri/InferenceNetwork.hpp" 00025 #include "indri/ListCache.hpp" 00026 #include <map> 00027 #include <vector> 00028 namespace indri 00029 { 00030 namespace infnet 00031 { 00032 00033 class InferenceNetworkBuilder : public indri::lang::Walker { 00034 private: 00035 std::map< indri::lang::Node*, InferenceNetworkNode* > _nodeMap; 00036 InferenceNetwork* _network; 00037 indri::collection::Repository& _repository; 00038 indri::lang::ListCache& _cache; 00039 int _resultsRequested; 00040 int _maxWildcardTerms; 00041 00042 template<typename _To, typename _From> 00043 std::vector<_To*> _translate( const std::vector<_From*>& children ) { 00044 std::vector<_To*> translation; 00045 00046 for( unsigned int i=0; i<children.size(); i++ ) { 00047 translation.push_back( dynamic_cast<_To*>(_nodeMap[children[i]]) ); 00048 } 00049 00050 return translation; 00051 } 00052 00053 indri::query::TermScoreFunction* _buildTermScoreFunction( const std::string& smoothing, double occurrences, double contextSize, int documentOccurrences, int documentCount ) const; 00054 00055 void _after( indri::lang::NestedExtentInside* extentInside ); 00056 void _after( indri::lang::NestedRawScorerNode* rawScorerNode ); 00057 void _after( indri::lang::ShrinkageScorerNode* shrinkageScorerNode ); 00058 void _after( indri::lang::ExtentEnforcement * eeNode ); 00059 void _after( indri::lang::ExtentDescendant* extentInside ); 00060 void _after( indri::lang::ExtentChild* extentInside ); 00061 void _after( indri::lang::ExtentParent* extentInside ); 00062 00063 public: 00064 static const int DEFAULT_MAX_WILDCARD_TERMS = 100; 00065 00066 InferenceNetworkBuilder( indri::collection::Repository& repository, indri::lang::ListCache& cache, int resultsRequested, int maxWildcardTerms=DEFAULT_MAX_WILDCARD_TERMS ); 00067 ~InferenceNetworkBuilder(); 00068 00069 InferenceNetwork* getNetwork(); 00070 00071 void defaultAfter( indri::lang::Node* node ); 00072 void after( indri::lang::IndexTerm* term ); 00073 void after( indri::lang::Field* field ); 00074 void after( indri::lang::ExtentAnd* extentAnd ); 00075 void after( indri::lang::ExtentOr* extentOr ); 00076 void after( indri::lang::WeightedExtentOr* weightedExtentOr ); 00077 void after( indri::lang::ExtentInside* extentInside ); 00078 void after( indri::lang::BAndNode* uwNode ); 00079 void after( indri::lang::ODNode* odNode ); 00080 void after( indri::lang::UWNode* uwNode ); 00081 void after( indri::lang::FilRejNode* uwNode ); 00082 void after( indri::lang::FilReqNode* uwNode ); 00083 void after( indri::lang::ContextCounterNode* contextCounterNode ); 00084 void after( indri::lang::ContextSimpleCounterNode* contextSimpleCounterNode ); 00085 void after( indri::lang::ListAccumulator* listAccumulator ); 00086 void after( indri::lang::ScoreAccumulatorNode* scoreAccumulatorNode ); 00087 void after( indri::lang::AnnotatorNode* annotatorNode ); 00088 void after( indri::lang::TermFrequencyScorerNode* termScorerNode ); 00089 void after( indri::lang::CachedFrequencyScorerNode* cachedScorerNode ); 00090 void after( indri::lang::RawScorerNode* rawScorerNode ); 00091 void after( indri::lang::ExtentRestriction* erNode ); 00092 void after( indri::lang::FixedPassage* fpNode ); 00093 void after( indri::lang::PriorNode* priorNode ); 00094 void after( indri::lang::WeightNode* weightNode ); 00095 void after( indri::lang::CombineNode* combineNode ); 00096 void after( indri::lang::PlusNode* plusNode ); 00097 void after( indri::lang::WPlusNode* plusNode ); 00098 void after( indri::lang::OrNode* orNode ); 00099 void after( indri::lang::NotNode* notSpecNode ); 00100 void after( indri::lang::MaxNode* maxNode ); 00101 void after( indri::lang::WAndNode* wandNode ); 00102 void after( indri::lang::WSumNode* wsumNode ); 00103 void after( indri::lang::FieldLessNode* flNode ); 00104 void after( indri::lang::FieldGreaterNode* fgNode ); 00105 void after( indri::lang::FieldBetweenNode* fbNode ); 00106 void after( indri::lang::FieldEqualsNode* fbNode ); 00107 void after( indri::lang::FilterNode* filterNode ); 00108 void after( indri::lang::FieldWildcard* fieldWildcard ); 00109 void after( indri::lang::ContextInclusionNode* contextInclusionNode ); 00110 void after( indri::lang::LengthPrior* lengthPrior ); 00111 void after( indri::lang::DocumentStructureNode * docStruct ); 00112 void after( indri::lang::ShrinkageScorerNode* shrinkageScorerNode ); 00113 void after( indri::lang::ExtentDescendant* extentInside ); 00114 void after( indri::lang::ExtentChild* extentInside ); 00115 void after( indri::lang::ExtentParent* extentInside ); 00116 void after( indri::lang::WildcardTerm* wildcardTerm ); 00117 }; 00118 } 00119 } 00120 00121 #endif // INDRI_INFERENCENETWORKBUILDER 00122 00123