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

ContextCountGraphCopier.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 // ContextCountGraphCopier
00015 //
00016 // 5 March 2004 -- tds
00017 //
00018 
00019 #ifndef INDRI_CONTEXTCOUNTGRAPHCOPIER_HPP
00020 #define INDRI_CONTEXTCOUNTGRAPHCOPIER_HPP
00021 namespace indri 
00022 {
00023   namespace lang
00024   {
00025     
00026     class ContextCountGraphCopier : public indri::lang::Copier {
00027     private:
00028       std::vector<indri::lang::Node*> _newNodes;
00029       std::vector<indri::lang::ContextCounterNode*> _contextCounters;
00030 
00031     public:
00032       ~ContextCountGraphCopier() {
00033         indri::utility::delete_vector_contents<indri::lang::Node*>( _newNodes );
00034       }
00035 
00036       indri::lang::Node* defaultAfter( indri::lang::Node* oldNode, indri::lang::Node* newNode ) {
00037         _newNodes.push_back( newNode );
00038         return newNode;
00039       }
00040 
00041       indri::lang::Node* after( indri::lang::RawScorerNode* oldNode, indri::lang::RawScorerNode* newNode ) {
00042         indri::lang::RawExtentNode* raw = newNode->getRawExtent();
00043         indri::lang::RawExtentNode* context = newNode->getContext();
00044         delete newNode;
00045 
00046         indri::lang::ContextCounterNode* contextCounter = new indri::lang::ContextCounterNode( raw, context );
00047         // need to match the name of the raw scorer we're counting for
00048         contextCounter->setNodeName( oldNode->nodeName() );
00049         _newNodes.push_back( contextCounter );
00050         _contextCounters.push_back( contextCounter );
00051         return contextCounter;
00052       }
00053 
00054       indri::lang::Node* after( indri::lang::NestedRawScorerNode* oldNode, indri::lang::NestedRawScorerNode* newNode ) {
00055         return after ( (indri::lang::RawScorerNode*) oldNode, (indri::lang::RawScorerNode*) newNode );
00056       }
00057 
00058       indri::lang::Node* after( indri::lang::ShrinkageScorerNode* oldNode, indri::lang::ShrinkageScorerNode* newNode ) {
00059         return after ( (indri::lang::RawScorerNode*) oldNode, (indri::lang::RawScorerNode*) newNode );
00060       }
00061  
00062       std::vector<indri::lang::Node*>& getNodes() {
00063         return _newNodes;
00064       }
00065 
00066       std::vector<indri::lang::ContextCounterNode*>& getContextCounterNodes() {
00067         return _contextCounters;
00068       }
00069     };
00070 
00071     class NoContextCountGraphCopier : public indri::lang::Copier {
00072     private:
00073       std::vector<indri::lang::Node*> _newNodes;
00074       std::vector<indri::lang::ContextCounterNode*> _contextCounters;
00075 
00076     public:
00077       ~NoContextCountGraphCopier() {
00078         indri::utility::delete_vector_contents<indri::lang::Node*>( _newNodes );
00079       }
00080 
00081       indri::lang::Node* defaultAfter( indri::lang::Node* oldNode, indri::lang::Node* newNode ) {
00082         _newNodes.push_back( newNode );
00083         return newNode;
00084       }
00085 
00086       indri::lang::Node* after( indri::lang::RawScorerNode* oldNode, indri::lang::RawScorerNode* newNode ) {
00087         indri::lang::RawExtentNode* raw = newNode->getRawExtent();
00088         indri::lang::RawExtentNode* context = newNode->getContext();
00089         delete newNode;
00090         context = 0;
00091         
00092         indri::lang::ContextCounterNode* contextCounter = new indri::lang::ContextCounterNode( raw, context );
00093         // need to match the name of the raw scorer we're counting for
00094         contextCounter->setNodeName( oldNode->nodeName() );
00095         _newNodes.push_back( contextCounter );
00096         _contextCounters.push_back( contextCounter );
00097         return contextCounter;
00098       }
00099 
00100       indri::lang::Node* after( indri::lang::NestedRawScorerNode* oldNode, indri::lang::NestedRawScorerNode* newNode ) {
00101         return after ( (indri::lang::RawScorerNode*) oldNode, (indri::lang::RawScorerNode*) newNode );
00102       }
00103 
00104       indri::lang::Node* after( indri::lang::ShrinkageScorerNode* oldNode, indri::lang::ShrinkageScorerNode* newNode ) {
00105         return after ( (indri::lang::RawScorerNode*) oldNode, (indri::lang::RawScorerNode*) newNode );
00106       }
00107 
00108 
00109       indri::lang::Node* after( indri::lang::ExtentRestriction* oldNode, indri::lang::ExtentRestriction* newNode ) {
00110         indri::lang::Node * child = newNode->getChild();
00111         delete newNode;
00112         return child;
00113       }
00114 
00115       std::vector<indri::lang::Node*>& getNodes() {
00116         return _newNodes;
00117       }
00118 
00119       std::vector<indri::lang::ContextCounterNode*>& getContextCounterNodes() {
00120         return _contextCounters;
00121       }
00122     };
00123   }
00124 }
00125 
00126 #endif // INDRI_CONTEXTCOUNTGRAPHCOPIER_HPP
00127 

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