Download tools/mosesdecoder/moses/Syntax/S2T/DerivationWriter.cpp from Quagmire1/wiki-cased: direct link, hf CLI and curl.
- Browser
- Download file 2.56 kB
-
https://huggingface.co/Quagmire1/wiki-cased/resolve/main/tools/mosesdecoder/moses/Syntax/S2T/DerivationWriter.cpp
- Command line
-
hf download hf://Quagmire1/wiki-cased/tools/mosesdecoder/moses/Syntax/S2T/DerivationWriter.cpp
-
curl -L -o DerivationWriter.cpp https://huggingface.co/Quagmire1/wiki-cased/resolve/main/tools/mosesdecoder/moses/Syntax/S2T/DerivationWriter.cpp
2.56 kB
| namespace Moses | |
| { | |
| namespace Syntax | |
| { | |
| namespace S2T | |
| { | |
| // 1-best version. | |
| 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); | |
| } | |
| } | |
| } | |
| // k-best derivation. | |
| 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) | |
| { | |
| // Sentence number. | |
| out << sentNum << " |||"; | |
| // Source LHS. | |
| out << " [X] ->"; | |
| // Source RHS symbols. | |
| 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 << " |||"; | |
| // Target RHS. | |
| out << " "; | |
| WriteSymbol(shyperedge.head->pvertex->symbol, out); | |
| out << " ->"; | |
| // Target RHS symbols. | |
| const TargetPhrase &phrase = *(shyperedge.label.translation); | |
| for (std::size_t i = 0; i < phrase.GetSize(); ++i) { | |
| out << " "; | |
| WriteSymbol(phrase.GetWord(i), out); | |
| } | |
| out << " |||"; | |
| // Non-terminal alignments | |
| const AlignmentInfo &a = phrase.GetAlignNonTerm(); | |
| for (AlignmentInfo::const_iterator p = a.begin(); p != a.end(); ++p) { | |
| out << " " << p->first << "-" << p->second; | |
| } | |
| out << " |||"; | |
| // Spans covered by source RHS symbols. | |
| 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(); | |
| } | |
| } | |
| } // namespace S2T | |
| } // namespace Syntax | |
| } // namespace Moses | |