diff --git a/contrib/other-builds/extract-mixed-syntax/Main.cpp b/contrib/other-builds/extract-mixed-syntax/Main.cpp index 721cf66b9..d23e5e3dc 100644 --- a/contrib/other-builds/extract-mixed-syntax/Main.cpp +++ b/contrib/other-builds/extract-mixed-syntax/Main.cpp @@ -39,6 +39,7 @@ int main(int argc, char** argv) Moses::InputFileStream strmSource(pathSource); Moses::InputFileStream strmAlignment(pathAlignment); Moses::OutputFileStream m_extractFile(pathExtract); + Moses::OutputFileStream m_extractInvFile(pathExtract + ".inv"); // MAIN LOOP @@ -69,7 +70,8 @@ int main(int argc, char** argv) rules.Consolidate(params); //cerr << rules.Debug(); - rules.Output(m_extractFile); + rules.Output(m_extractFile, true); + rules.Output(m_extractInvFile, false); } diff --git a/contrib/other-builds/extract-mixed-syntax/Rule.cpp b/contrib/other-builds/extract-mixed-syntax/Rule.cpp index 353697cf9..e7aaf4e2e 100644 --- a/contrib/other-builds/extract-mixed-syntax/Rule.cpp +++ b/contrib/other-builds/extract-mixed-syntax/Rule.cpp @@ -121,25 +121,30 @@ std::string Rule::Debug() const return out.str(); } -void Rule::Output(std::ostream &out) const +void Rule::Output(std::ostream &out, bool forward) const { - // source - for (size_t i = 0; i < m_source.GetSize(); ++i) { - const RuleSymbol &symbol = *m_source[i]; - symbol.Output(out); - out << " "; - } - m_lhs.Output(out, Moses::Input); + if (forward) { + // source + m_source.Output(out); + m_lhs.Output(out, Moses::Input); - out << " ||| "; + out << " ||| "; - // target - for (size_t i = 0; i < m_target.GetSize(); ++i) { - const RuleSymbol &symbol = *m_target[i]; - symbol.Output(out); - out << " "; + // target + m_target.Output(out); + m_lhs.Output(out, Moses::Output); + } + else { + // target + m_target.Output(out); + m_lhs.Output(out, Moses::Output); + + out << " ||| "; + + // source + m_source.Output(out); + m_lhs.Output(out, Moses::Input); } - m_lhs.Output(out, Moses::Output); out << " ||| "; @@ -147,7 +152,13 @@ void Rule::Output(std::ostream &out) const Alignments::const_iterator iterAlign; for (iterAlign = m_alignments.begin(); iterAlign != m_alignments.end(); ++iterAlign) { const std::pair &alignPair = *iterAlign; - out << alignPair.first << "-" << alignPair.second << " "; + + if (forward) { + out << alignPair.first << "-" << alignPair.second << " "; + } + else { + out << alignPair.second << "-" << alignPair.first << " "; + } } out << "||| "; diff --git a/contrib/other-builds/extract-mixed-syntax/Rule.h b/contrib/other-builds/extract-mixed-syntax/Rule.h index 719a3f6c6..6078b38e9 100644 --- a/contrib/other-builds/extract-mixed-syntax/Rule.h +++ b/contrib/other-builds/extract-mixed-syntax/Rule.h @@ -52,7 +52,7 @@ public: { return m_alignments; } std::string Debug() const; - void Output(std::ostream &out) const; + void Output(std::ostream &out, bool forward) const; void Prevalidate(const Parameter ¶ms); void CreateTarget(const Parameter ¶ms); diff --git a/contrib/other-builds/extract-mixed-syntax/RulePhrase.cpp b/contrib/other-builds/extract-mixed-syntax/RulePhrase.cpp index 1cc974ba0..c357c6409 100644 --- a/contrib/other-builds/extract-mixed-syntax/RulePhrase.cpp +++ b/contrib/other-builds/extract-mixed-syntax/RulePhrase.cpp @@ -30,3 +30,12 @@ int RulePhrase::Compare(const RulePhrase &other) const return 0; } + +void RulePhrase::Output(std::ostream &out) const +{ + for (size_t i = 0; i < m_coll.size(); ++i) { + const RuleSymbol &symbol = *m_coll[i]; + symbol.Output(out); + out << " "; + } +} diff --git a/contrib/other-builds/extract-mixed-syntax/RulePhrase.h b/contrib/other-builds/extract-mixed-syntax/RulePhrase.h index 4f2183d94..382b50d37 100644 --- a/contrib/other-builds/extract-mixed-syntax/RulePhrase.h +++ b/contrib/other-builds/extract-mixed-syntax/RulePhrase.h @@ -10,6 +10,7 @@ #include #include +#include class RuleSymbol; @@ -33,6 +34,7 @@ public: int Compare(const RulePhrase &other) const; + void Output(std::ostream &out) const; }; #endif /* RULEPHRASE_H_ */ diff --git a/contrib/other-builds/extract-mixed-syntax/Rules.cpp b/contrib/other-builds/extract-mixed-syntax/Rules.cpp index 4ede877d7..bbd8c0c9b 100644 --- a/contrib/other-builds/extract-mixed-syntax/Rules.cpp +++ b/contrib/other-builds/extract-mixed-syntax/Rules.cpp @@ -138,12 +138,12 @@ std::string Rules::Debug() const return out.str(); } -void Rules::Output(std::ostream &out) const +void Rules::Output(std::ostream &out, bool forward) const { std::set::const_iterator iter; for (iter = m_mergeRules.begin(); iter != m_mergeRules.end(); ++iter) { const Rule &rule = **iter; - rule.Output(out); + rule.Output(out, forward); out << endl; } } diff --git a/contrib/other-builds/extract-mixed-syntax/Rules.h b/contrib/other-builds/extract-mixed-syntax/Rules.h index 056c0e619..9ca41cf6e 100644 --- a/contrib/other-builds/extract-mixed-syntax/Rules.h +++ b/contrib/other-builds/extract-mixed-syntax/Rules.h @@ -48,7 +48,7 @@ public: void Consolidate(const Parameter ¶ms); std::string Debug() const; - void Output(std::ostream &out) const; + void Output(std::ostream &out, bool forward) const; protected: const AlignedSentence &m_alignedSentence;