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 // ExtentRestrictionModelAnnotatorCopier 00015 // 00016 // 16 August 2004 -- tds 00017 // 00018 // This copier annotates RawScorerNodes with the language models 00019 // of the surrounding ExtentRestrictions. 00020 // 00021 // For example, the query #combine[sentence]( dog cat ) 00022 // should be synonymous with #combine[sentence]( dog.(sentence) cat.(sentence) ). 00023 // We push the sentence language model down the tree and attach it to "dog" and "cat". 00024 // 00025 00026 #ifndef INDRI_EXTENTRESTRICTIONMODELANNOTATORCOPIER_HPP 00027 #define INDRI_EXTENTRESTRICTIONMODELANNOTATORCOPIER_HPP 00028 00029 #include <stack> 00030 #include <vector> 00031 #include "indri/QuerySpec.hpp" 00032 namespace indri 00033 { 00034 namespace lang 00035 { 00036 00037 class ExtentRestrictionModelAnnotatorCopier : public indri::lang::Copier { 00038 private: 00039 std::vector<indri::lang::Node*> _nodes; 00040 std::stack< indri::lang::ExtentRestriction* > _restrictions; 00041 00042 public: 00043 ~ExtentRestrictionModelAnnotatorCopier() { 00044 indri::utility::delete_vector_contents( _nodes ); 00045 } 00046 00047 indri::lang::Node* defaultAfter( indri::lang::Node* old, indri::lang::Node* newNode ) { 00048 _nodes.push_back( newNode ); 00049 return newNode; 00050 } 00051 00052 void before( indri::lang::ExtentRestriction* old ) { 00053 _restrictions.push( old ); 00054 } 00055 00056 void before( indri::lang::ExtentEnforcement* old ) { 00057 before( (indri::lang::ExtentRestriction*) old ); 00058 } 00059 00060 indri::lang::Node* after( indri::lang::ExtentRestriction* oldNode, indri::lang::ExtentRestriction* newNode ) { 00061 _restrictions.pop(); 00062 _nodes.push_back( newNode ); 00063 return newNode; 00064 } 00065 00066 indri::lang::Node* after( indri::lang::ExtentEnforcement* oldNode, indri::lang::ExtentEnforcement* newNode ) { 00067 return after( (indri::lang::ExtentRestriction*) oldNode, (indri::lang::ExtentRestriction*) newNode ); 00068 } 00069 00070 indri::lang::Node* after( indri::lang::RawScorerNode* oldNode, indri::lang::RawScorerNode* newNode ) { 00071 if( newNode->getContext() == 0 && _restrictions.size() ) { 00072 newNode->setContext( _restrictions.top()->getField() ); 00073 } 00074 _nodes.push_back( newNode ); // should track for free. 00075 return newNode; 00076 } 00077 00078 indri::lang::Node* after( indri::lang::NestedRawScorerNode* oldNode, indri::lang::NestedRawScorerNode* newNode ) { 00079 return after( (indri::lang::RawScorerNode*) oldNode, (indri::lang::RawScorerNode*) newNode ); 00080 } 00081 }; 00082 } 00083 } 00084 00085 #endif // INDRI_EXTENTRESTRICTIONMODELANNOTATORCOPIER_HPP 00086