| #include "DerivationWriter.h" |
|
|
| #include "moses/Factor.h" |
| #include "moses/Syntax/PVertex.h" |
| #include "moses/Syntax/SHyperedge.h" |
|
|
| namespace Moses |
| { |
| namespace Syntax |
| { |
| namespace S2T |
| { |
|
|
| |
| void DerivationWriter::Write(const SHyperedge ­peredge, |
| std::size_t sentNum, std::ostream &out) |
| { |
| WriteLine(shyperedge, sentNum, out); |
| for (std::size_t i = 0; i < shyperedge.tail.size(); ++i) { |
| const SVertex &pred = *(shyperedge.tail[i]); |
| if (pred.best) { |
| Write(*pred.best, sentNum, out); |
| } |
| } |
| } |
|
|
| |
| void DerivationWriter::Write(const KBestExtractor::Derivation &derivation, |
| std::size_t sentNum, std::ostream &out) |
| { |
| WriteLine(derivation.edge->shyperedge, sentNum, out); |
| for (std::size_t i = 0; i < derivation.subderivations.size(); ++i) { |
| Write(*(derivation.subderivations[i]), sentNum, out); |
| } |
| } |
|
|
| void DerivationWriter::WriteLine(const SHyperedge ­peredge, |
| std::size_t sentNum, std::ostream &out) |
| { |
| |
| out << sentNum << " |||"; |
|
|
| |
| out << " [X] ->"; |
|
|
| |
| for (std::size_t i = 0; i < shyperedge.tail.size(); ++i) { |
| const Word &symbol = shyperedge.tail[i]->pvertex->symbol; |
| out << " "; |
| if (symbol.IsNonTerminal()) { |
| out << "[X]"; |
| } else { |
| WriteSymbol(symbol, out); |
| } |
| } |
| out << " |||"; |
|
|
| |
| out << " "; |
| WriteSymbol(shyperedge.head->pvertex->symbol, out); |
| out << " ->"; |
|
|
| |
| const TargetPhrase &phrase = *(shyperedge.label.translation); |
| for (std::size_t i = 0; i < phrase.GetSize(); ++i) { |
| out << " "; |
| WriteSymbol(phrase.GetWord(i), out); |
| } |
| out << " |||"; |
|
|
| |
| const AlignmentInfo &a = phrase.GetAlignNonTerm(); |
| for (AlignmentInfo::const_iterator p = a.begin(); p != a.end(); ++p) { |
| out << " " << p->first << "-" << p->second; |
| } |
| out << " |||"; |
|
|
| |
| for (std::size_t i = 0; i < shyperedge.tail.size(); ++i) { |
| const SVertex *child = shyperedge.tail[i]; |
| const Range &span = child->pvertex->span; |
| out << " " << span.GetStartPos() << ".." << span.GetEndPos(); |
| } |
|
|
| out << "\n"; |
| } |
|
|
| void DerivationWriter::WriteSymbol(const Word &symbol, std::ostream &out) |
| { |
| const Factor *f = symbol[0]; |
| if (symbol.IsNonTerminal()) { |
| out << "[" << f->GetString() << "]"; |
| } else { |
| out << f->GetString(); |
| } |
| } |
|
|
| } |
| } |
| } |
|
|