00001 /*********************************************************************** 00002 Moses - statistical machine translation system 00003 Copyright (C) 2006-2011 University of Edinburgh 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 ***********************************************************************/ 00019 00020 #pragma once 00021 #ifndef EXTRACT_GHKM_COMPOSED_RULE_H_ 00022 #define EXTRACT_GHKM_COMPOSED_RULE_H_ 00023 00024 #include <vector> 00025 #include <queue> 00026 00027 #include "Subgraph.h" 00028 00029 namespace MosesTraining 00030 { 00031 namespace Syntax 00032 { 00033 namespace GHKM 00034 { 00035 00036 class Node; 00037 struct Options; 00038 00039 class ComposedRule 00040 { 00041 public: 00042 // Form a 'trivial' ComposedRule from a single existing rule. 00043 ComposedRule(const Subgraph &baseRule); 00044 00045 // Returns the first open attachment point if any exist or 0 otherwise. 00046 const Node *GetOpenAttachmentPoint(); 00047 00048 // Close the first open attachment point without attaching a rule. 00049 void CloseAttachmentPoint(); 00050 00051 // Attempts to produce a new composed rule by attaching a given rule at the 00052 // first open attachment point. This will fail if the proposed rule violates 00053 // the constraints set in the Options object, in which case the function 00054 // returns 0. 00055 ComposedRule *AttemptComposition(const Subgraph &, const Options &) const; 00056 00057 // Constructs a Subgraph object corresponding to the composed rule. 00058 Subgraph CreateSubgraph(); 00059 00060 private: 00061 ComposedRule(const ComposedRule &, const Subgraph &, int); 00062 00063 const Subgraph &m_baseRule; 00064 std::vector<const Subgraph *> m_attachedRules; 00065 std::queue<const Node *> m_openAttachmentPoints; 00066 int m_depth; 00067 int m_size; 00068 int m_nodeCount; 00069 }; 00070 00071 } // namespace GHKM 00072 } // namespace Syntax 00073 } // namespace MosesTraining 00074 00075 #endif