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 00033 class ExtentRestrictionModelAnnotatorCopier : public indri::lang::Copier { 00034 private: 00035 std::vector<indri::lang::Node*> _nodes; 00036 std::stack< indri::lang::ExtentRestriction* > _restrictions; 00037 00038 public: 00039 ~ExtentRestrictionModelAnnotatorCopier() { 00040 delete_vector_contents( _nodes ); 00041 } 00042 00043 indri::lang::Node* defaultAfter( indri::lang::Node* old, indri::lang::Node* newNode ) { 00044 _nodes.push_back( newNode ); 00045 return newNode; 00046 } 00047 00048 void before( indri::lang::ExtentRestriction* old ) { 00049 _restrictions.push( old ); 00050 } 00051 00052 indri::lang::Node* after( indri::lang::ExtentRestriction* oldNode, indri::lang::ExtentRestriction* newNode ) { 00053 _restrictions.pop(); 00054 _nodes.push_back( newNode ); 00055 return newNode; 00056 } 00057 00058 indri::lang::Node* after( indri::lang::RawScorerNode* oldNode, indri::lang::RawScorerNode* newNode ) { 00059 if( newNode->getContext() == 0 && _restrictions.size() ) { 00060 newNode->setContext( _restrictions.top()->getField() ); 00061 } 00062 00063 return newNode; 00064 } 00065 }; 00066 00067 #endif // INDRI_EXTENTRESTRICTIONMODELANNOTATORCOPIER_HPP 00068