Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

DagCopier.hpp

Go to the documentation of this file.
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 // DagCopier
00015 //
00016 // 5 March 2004 -- tds
00017 //
00018 
00019 #ifndef INDRI_DAGCOPIER_HPP
00020 #define INDRI_DAGCOPIER_HPP
00021 
00022 #include <vector>
00023 #include "indri/delete_range.hpp"
00024 namespace indri 
00025 {
00026   namespace lang
00027   {
00028     
00029     class DagCopier : public indri::lang::Copier {
00030     private:
00031       std::vector<indri::lang::IndexTerm*> _terms;
00032       std::vector<indri::lang::Field*> _fields;
00033       std::vector<indri::lang::ExtentOr*> _extentOrs;
00034       std::vector<indri::lang::ExtentAnd*> _extentAnds;
00035       std::vector<indri::lang::ExtentInside*> _extentInsides;
00036       std::vector<indri::lang::ODNode*> _odNodes;
00037       std::vector<indri::lang::UWNode*> _uwNodes;
00038       std::vector<indri::lang::FieldWildcard*> _fieldWildcardNodes;
00039       std::vector<indri::lang::DocumentStructureNode*> _documentStructureNodes;
00040 
00041       std::vector<indri::lang::Node*> _newNodes;
00042 
00043       template<class T>
00044       T* _findReplacement( std::vector<T*>& replacements, T* candidate ) {
00045         T* replacement = 0;
00046     
00047         for( unsigned int i=0; i<replacements.size(); i++ ) {
00048           if( (*candidate) == (*replacements[i]) ) {
00049             replacement = replacements[i];
00050             break;
00051           }
00052         }
00053 
00054         if( replacement ) {
00055           delete candidate;
00056           candidate = replacement;
00057         } else {
00058           _newNodes.push_back( candidate );
00059           replacements.push_back( candidate );
00060         }
00061 
00062         return candidate;
00063       }
00064 
00065     public:
00066       ~DagCopier() {
00067         indri::utility::delete_vector_contents( _newNodes );
00068       }
00069 
00070       indri::lang::Node* defaultAfter( indri::lang::Node* oldNode, indri::lang::Node* newNode ) {
00071         _newNodes.push_back( newNode );
00072         return newNode;
00073       }
00074 
00075       indri::lang::Node* after( indri::lang::IndexTerm* indexTerm, indri::lang::IndexTerm* newIndexTerm ) {
00076         return _findReplacement<indri::lang::IndexTerm>( _terms, newIndexTerm );
00077       }
00078 
00079       indri::lang::Node* after( indri::lang::Field* field, indri::lang::Field* newField ) {
00080         return _findReplacement<indri::lang::Field>( _fields, newField );
00081       }
00082 
00083       indri::lang::Node* after( indri::lang::ExtentOr* oldExtentOr, indri::lang::ExtentOr* newExtentOr ) {
00084         return _findReplacement<indri::lang::ExtentOr>( _extentOrs, newExtentOr );
00085       }
00086 
00087       indri::lang::Node* after( indri::lang::ExtentAnd* oldExtentAnd, indri::lang::ExtentAnd* newExtentAnd ) {
00088         return _findReplacement<indri::lang::ExtentAnd>( _extentAnds, newExtentAnd );
00089       }
00090 
00091       indri::lang::Node* after( indri::lang::ExtentInside* oldExtentInside, indri::lang::ExtentInside* newExtentInside ) {      
00092         return _findReplacement<indri::lang::ExtentInside>( _extentInsides, newExtentInside );
00093       }
00094 
00095       indri::lang::Node* after( indri::lang::NestedExtentInside* oldExtentInside, indri::lang::NestedExtentInside* newExtentInside ) {  
00096         return after((indri::lang::ExtentInside*) oldExtentInside, (indri::lang::ExtentInside*) newExtentInside );
00097       }
00098  
00099       indri::lang::Node* after( indri::lang::ODNode* oldODNode, indri::lang::ODNode* newODNode ) {
00100         return _findReplacement<indri::lang::ODNode>( _odNodes, newODNode );
00101       }
00102 
00103       indri::lang::Node* after( indri::lang::UWNode* oldUWNode, indri::lang::UWNode* newUWNode ) {
00104         return _findReplacement<indri::lang::UWNode>( _uwNodes, newUWNode );
00105       }
00106 
00107       indri::lang::Node* after( indri::lang::FieldWildcard* fieldWildcard, indri::lang::FieldWildcard* newFieldWildcard ) {
00108         return _findReplacement<indri::lang::FieldWildcard>( _fieldWildcardNodes, newFieldWildcard );
00109       }
00110 
00111       indri::lang::Node* after( indri::lang::DocumentStructureNode* docStruct, indri::lang::DocumentStructureNode* newDocStruct ) {
00112         return _findReplacement<indri::lang::DocumentStructureNode>( _documentStructureNodes, newDocStruct );
00113       }
00114       
00115     };
00116   }
00117 }
00118 
00119 #endif // INDRI_DAGCOPIER_HPP
00120 

Generated on Tue Jun 15 11:02:53 2010 for Lemur by doxygen 1.3.4