00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #pragma once
00021
00022 #include <string>
00023 #include <vector>
00024 #include <list>
00025 #include <memory>
00026 #include <iostream>
00027
00028 #include "Alignment.h"
00029 #include "Rule.h"
00030 #include "SyntaxNodeCollection.h"
00031
00032 namespace MosesTraining
00033 {
00034 namespace Syntax
00035 {
00036 namespace GHKM
00037 {
00038
00039 class Node;
00040 class Subgraph;
00041
00042 class ScfgRule : public Rule
00043 {
00044 public:
00045 ScfgRule(const Subgraph &fragment,
00046 const SyntaxNodeCollection *sourceNodeCollection = 0);
00047
00048 const Subgraph &GetGraphFragment() const {
00049 return m_graphFragment;
00050 }
00051 const Symbol &GetSourceLHS() const {
00052 return m_sourceLHS;
00053 }
00054 const Symbol &GetTargetLHS() const {
00055 return m_targetLHS;
00056 }
00057 const std::vector<Symbol> &GetSourceRHS() const {
00058 return m_sourceRHS;
00059 }
00060 const std::vector<Symbol> &GetTargetRHS() const {
00061 return m_targetRHS;
00062 }
00063 float GetPcfgScore() const {
00064 return m_pcfgScore;
00065 }
00066 bool HasSourceLabels() const {
00067 return m_hasSourceLabels;
00068 }
00069 void PrintSourceLabels(std::ostream &out) const {
00070 for (std::vector<std::string>::const_iterator it = m_sourceLabels.begin();
00071 it != m_sourceLabels.end(); ++it) {
00072 out << " " << (*it);
00073 }
00074 }
00075 void UpdateSourceLabelCoocCounts(std::map< std::string, std::map<std::string,float>* > &coocCounts,
00076 float count) const;
00077
00078 int Scope() const {
00079 return Rule::Scope(m_sourceRHS);
00080 }
00081
00082 private:
00083 void PushSourceLabel(const SyntaxNodeCollection *sourceNodeCollection,
00084 const Node *node, const std::string &nonMatchingLabel);
00085
00086 const Subgraph& m_graphFragment;
00087 Symbol m_sourceLHS;
00088 Symbol m_targetLHS;
00089 std::vector<Symbol> m_sourceRHS;
00090 std::vector<Symbol> m_targetRHS;
00091 float m_pcfgScore;
00092 bool m_hasSourceLabels;
00093 std::vector<std::string> m_sourceLabels;
00094 unsigned m_numberOfNonTerminals;
00095 };
00096
00097 }
00098 }
00099 }