diff --git a/phrase-extract/SentenceAlignmentWithSyntax.h b/phrase-extract/SentenceAlignmentWithSyntax.h index a603f7722..604b6d0e2 100644 --- a/phrase-extract/SentenceAlignmentWithSyntax.h +++ b/phrase-extract/SentenceAlignmentWithSyntax.h @@ -28,7 +28,7 @@ #include "RuleExtractionOptions.h" #include "SentenceAlignment.h" -#include "SyntaxTree.h" +#include "SyntaxNodeCollection.h" namespace MosesTraining { diff --git a/phrase-extract/SyntaxNode.h b/phrase-extract/SyntaxNode.h new file mode 100644 index 000000000..46e0f456f --- /dev/null +++ b/phrase-extract/SyntaxNode.h @@ -0,0 +1,75 @@ +/*********************************************************************** + Moses - factored phrase-based language decoder + Copyright (C) 2009 University of Edinburgh + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + ***********************************************************************/ + +#pragma once + +#include +#include +#include +#include + +namespace MosesTraining +{ + +class SyntaxNode +{ +protected: + int m_start, m_end; + std::string m_label; + std::vector< SyntaxNode* > m_children; + SyntaxNode* m_parent; + float m_pcfgScore; +public: + SyntaxNode( int startPos, int endPos, std::string label ) + :m_start(startPos) + ,m_end(endPos) + ,m_label(label) + ,m_parent(0) + ,m_pcfgScore(0.0f) { + } + int GetStart() const { + return m_start; + } + int GetEnd() const { + return m_end; + } + std::string GetLabel() const { + return m_label; + } + float GetPcfgScore() const { + return m_pcfgScore; + } + void SetPcfgScore(float score) { + m_pcfgScore = score; + } + SyntaxNode *GetParent() { + return m_parent; + } + void SetParent(SyntaxNode *parent) { + m_parent = parent; + } + void AddChild(SyntaxNode* child) { + m_children.push_back(child); + } + const std::vector< SyntaxNode* > &GetChildren() const { + return m_children; + } +}; + +} // namespace MosesTraining diff --git a/phrase-extract/SyntaxTree.cpp b/phrase-extract/SyntaxNodeCollection.cpp similarity index 96% rename from phrase-extract/SyntaxTree.cpp rename to phrase-extract/SyntaxNodeCollection.cpp index 7f641125e..099a5697f 100644 --- a/phrase-extract/SyntaxTree.cpp +++ b/phrase-extract/SyntaxNodeCollection.cpp @@ -18,7 +18,7 @@ ***********************************************************************/ -#include "SyntaxTree.h" +#include "SyntaxNodeCollection.h" #include #include @@ -42,7 +42,8 @@ void SyntaxNodeCollection::Clear() m_index.clear(); } -SyntaxNode *SyntaxNodeCollection::AddNode( int startPos, int endPos, std::string label ) +SyntaxNode *SyntaxNodeCollection::AddNode(int startPos, int endPos, + const std::string &label) { SyntaxNode* newNode = new SyntaxNode( startPos, endPos, label ); m_nodes.push_back( newNode ); @@ -151,4 +152,4 @@ void SyntaxNodeCollection::ConnectNodes() } } -} +} // namespace MosesTraining diff --git a/phrase-extract/SyntaxTree.h b/phrase-extract/SyntaxNodeCollection.h similarity index 69% rename from phrase-extract/SyntaxTree.h rename to phrase-extract/SyntaxNodeCollection.h index 649a6197b..70b14206d 100644 --- a/phrase-extract/SyntaxTree.h +++ b/phrase-extract/SyntaxNodeCollection.h @@ -24,55 +24,11 @@ #include #include +#include "SyntaxNode.h" + namespace MosesTraining { -class SyntaxNode -{ -protected: - int m_start, m_end; - std::string m_label; - std::vector< SyntaxNode* > m_children; - SyntaxNode* m_parent; - float m_pcfgScore; -public: - SyntaxNode( int startPos, int endPos, std::string label ) - :m_start(startPos) - ,m_end(endPos) - ,m_label(label) - ,m_parent(0) - ,m_pcfgScore(0.0f) { - } - int GetStart() const { - return m_start; - } - int GetEnd() const { - return m_end; - } - std::string GetLabel() const { - return m_label; - } - float GetPcfgScore() const { - return m_pcfgScore; - } - void SetPcfgScore(float score) { - m_pcfgScore = score; - } - SyntaxNode *GetParent() { - return m_parent; - } - void SetParent(SyntaxNode *parent) { - m_parent = parent; - } - void AddChild(SyntaxNode* child) { - m_children.push_back(child); - } - const std::vector< SyntaxNode* > &GetChildren() const { - return m_children; - } -}; - - typedef std::vector< int > SplitPoints; typedef std::vector< SplitPoints > ParentNodes; @@ -97,7 +53,7 @@ public: ~SyntaxNodeCollection(); - SyntaxNode *AddNode( int startPos, int endPos, std::string label ); + SyntaxNode *AddNode( int startPos, int endPos, const std::string &label ); SyntaxNode *GetTop() { return m_top; diff --git a/phrase-extract/XmlTree.cpp b/phrase-extract/XmlTree.cpp index d45fd99eb..0f068fca7 100644 --- a/phrase-extract/XmlTree.cpp +++ b/phrase-extract/XmlTree.cpp @@ -24,7 +24,8 @@ #include #include #include -#include "SyntaxTree.h" + +#include "SyntaxNodeCollection.h" #include "XmlException.h" using namespace std; diff --git a/phrase-extract/XmlTree.h b/phrase-extract/XmlTree.h index 392192ae6..3b5afd4dd 100644 --- a/phrase-extract/XmlTree.h +++ b/phrase-extract/XmlTree.h @@ -1,6 +1,3 @@ -// $Id: XmlOption.cpp 1960 2008-12-15 12:52:38Z phkoehn $ -// vim:tabstop=2 - /*********************************************************************** Moses - factored phrase-based language decoder Copyright (C) 2006 University of Edinburgh @@ -21,11 +18,13 @@ ***********************************************************************/ #pragma once + #include #include #include #include -#include "SyntaxTree.h" + +#include "SyntaxNodeCollection.h" namespace MosesTraining { @@ -39,5 +38,4 @@ bool ProcessAndStripXMLTags(std::string &line, SyntaxNodeCollection &tree, std:: std::string unescape(const std::string &str); -} // namespace - +} // namespace MosesTraining diff --git a/phrase-extract/extract-ghkm/ExtractGHKM.cpp b/phrase-extract/extract-ghkm/ExtractGHKM.cpp index 9e6aacc20..937d88030 100644 --- a/phrase-extract/extract-ghkm/ExtractGHKM.cpp +++ b/phrase-extract/extract-ghkm/ExtractGHKM.cpp @@ -33,7 +33,8 @@ #include "Span.h" #include "StsgRule.h" #include "StsgRuleWriter.h" -#include "SyntaxTree.h" +#include "SyntaxNode.h" +#include "SyntaxNodeCollection.h" #include "tables-core.h" #include "XmlException.h" #include "XmlTree.h" diff --git a/phrase-extract/extract-ghkm/ScfgRule.cpp b/phrase-extract/extract-ghkm/ScfgRule.cpp index 94ff3c605..918c88eeb 100644 --- a/phrase-extract/extract-ghkm/ScfgRule.cpp +++ b/phrase-extract/extract-ghkm/ScfgRule.cpp @@ -19,11 +19,12 @@ #include "ScfgRule.h" +#include + #include "Node.h" #include "Subgraph.h" -#include "SyntaxTree.h" - -#include +#include "SyntaxNode.h" +#include "SyntaxNodeCollection.h" namespace Moses { diff --git a/phrase-extract/extract-ghkm/ScfgRule.h b/phrase-extract/extract-ghkm/ScfgRule.h index b3d8ad017..c8b76114a 100644 --- a/phrase-extract/extract-ghkm/ScfgRule.h +++ b/phrase-extract/extract-ghkm/ScfgRule.h @@ -19,16 +19,16 @@ #pragma once -#include "Alignment.h" -#include "Rule.h" -#include "SyntaxTree.h" - #include #include #include #include #include +#include "Alignment.h" +#include "Rule.h" +#include "SyntaxNodeCollection.h" + namespace Moses { namespace GHKM @@ -95,4 +95,3 @@ private: } // namespace GHKM } // namespace Moses - diff --git a/phrase-extract/extract-ghkm/XmlTreeParser.h b/phrase-extract/extract-ghkm/XmlTreeParser.h index 03450383a..db9fa8bf2 100644 --- a/phrase-extract/extract-ghkm/XmlTreeParser.h +++ b/phrase-extract/extract-ghkm/XmlTreeParser.h @@ -23,14 +23,15 @@ #include "Exception.h" -#include "SyntaxTree.h" - #include #include #include #include #include +#include "SyntaxNode.h" +#include "SyntaxNodeCollection.h" + namespace Moses { namespace GHKM diff --git a/phrase-extract/extract-rules-main.cpp b/phrase-extract/extract-rules-main.cpp index 50baa4e0d..825f12d89 100644 --- a/phrase-extract/extract-rules-main.cpp +++ b/phrase-extract/extract-rules-main.cpp @@ -41,7 +41,7 @@ #include "HoleCollection.h" #include "RuleExist.h" #include "SentenceAlignmentWithSyntax.h" -#include "SyntaxTree.h" +#include "SyntaxNode.h" #include "tables-core.h" #include "XmlTree.h" #include "InputFileStream.h" diff --git a/phrase-extract/pcfg-common/xml_tree_parser.h b/phrase-extract/pcfg-common/xml_tree_parser.h index 69754bb56..8605c0691 100644 --- a/phrase-extract/pcfg-common/xml_tree_parser.h +++ b/phrase-extract/pcfg-common/xml_tree_parser.h @@ -28,7 +28,8 @@ #include #include "pcfg_tree.h" -#include "SyntaxTree.h" +#include "SyntaxNode.h" +#include "SyntaxNodeCollection.h" namespace MosesTraining { namespace Syntax { diff --git a/phrase-extract/relax-parse.h b/phrase-extract/relax-parse.h index af41b0945..a00aa6deb 100644 --- a/phrase-extract/relax-parse.h +++ b/phrase-extract/relax-parse.h @@ -28,7 +28,7 @@ #include #include -#include "SyntaxTree.h" +#include "SyntaxNodeCollection.h" #include "XmlTree.h" #define LINE_MAX_LENGTH 1000000 diff --git a/phrase-extract/syntax-common/xml_tree_parser.h b/phrase-extract/syntax-common/xml_tree_parser.h index e530b84ef..c84ea25ec 100644 --- a/phrase-extract/syntax-common/xml_tree_parser.h +++ b/phrase-extract/syntax-common/xml_tree_parser.h @@ -5,7 +5,8 @@ #include #include -#include "SyntaxTree.h" +#include "SyntaxNode.h" +#include "SyntaxNodeCollection.h" #include "exception.h" #include "string_tree.h"