00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "Node.h"
00021
00022 #include "Subgraph.h"
00023
00024 namespace MosesTraining
00025 {
00026 namespace Syntax
00027 {
00028 namespace GHKM
00029 {
00030
00031 Node::~Node()
00032 {
00033 for (std::vector<const Subgraph*>::const_iterator p(m_rules.begin());
00034 p != m_rules.end(); ++p) {
00035 delete *p;
00036 }
00037 }
00038
00039 bool Node::IsPreterminal() const
00040 {
00041 return (m_type == TREE
00042 && m_children.size() == 1
00043 && m_children[0]->m_type == TARGET);
00044 }
00045
00046 void Node::PropagateIndex(int index)
00047 {
00048 m_span.insert(index);
00049 for (std::vector<Node *>::const_iterator p(m_parents.begin());
00050 p != m_parents.end(); ++p) {
00051 (*p)->PropagateIndex(index);
00052 }
00053 }
00054
00055 std::vector<std::string> Node::GetTargetWords() const
00056 {
00057 std::vector<std::string> targetWords;
00058 GetTargetWords(targetWords);
00059 return targetWords;
00060 }
00061
00062 void Node::GetTargetWords(std::vector<std::string> &targetWords) const
00063 {
00064 if (m_type == TARGET) {
00065 targetWords.push_back(m_label);
00066 } else {
00067 for (std::vector<Node *>::const_iterator p(m_children.begin());
00068 p != m_children.end(); ++p) {
00069 (*p)->GetTargetWords(targetWords);
00070 }
00071 }
00072 }
00073
00074 }
00075 }
00076 }