1

从 下载主干代码后http://code.google.com/p/berkeleyaligner/,我将项目添加到我在 Eclipse 上的构建路径中。然后使用下面的代码,我可以提取我从 sourceFile 和 targetFile 中读取的每个句子对的对齐方式。对齐后,如何Alignment从 BerkeleyAligner 读取类型?

import edu.berkeley.nlp.wa.mt.Alignment;
import edu.berkeley.nlp.wa.mt.SentencePair;
import edu.berkeley.nlp.wordAlignment.combine.WordAlignerCombined;
public static void main(String[] args) {
BufferedReader brSrc = new BufferedReader(new FileReader ("sourceFile"));
BufferedReader brTrg = new BufferedReader(new FileReader ("targetFile"));
while ((currentSrcLine = brSrc.readLine()) !=null) {
    String currentTrgLine = brTrg.readline();
    // Reads into BerkeleyAligner SentencePair format.
    SentencePair src2trg = new SentencePair(sentCounter, params.get("source"),
        Arrays.asList(srcLine.split(" ")), Arrays.asList(trgLine.split(" ")));
    // Generate Alignment type from SentencePair
    WordAlignerCombined aligner;
    Alignment alignedPair = aligner.alignSentencePair(src2trg);
    // How do i print out the Alignment???
    }
}

例如源文件:

this is the first line in the textfile.
that is the second line.
foo bar likes to eat bar foo.

例如目标文件:

Dies ist die erste Textzeile in der Datei.
das ist die zweite Zeile.
foo bar gerne bar foo essen.
4

1 回答 1

1

打印吉萨。对齐有一个方法:

public void writeGIZA(PrintWriter out, int idx)

吉萨是:

"# sentence pair (%d) source length %d target length %d alignment score : 0\n"
"NULL ({ %s })"
" %s ({ %s })" (englishSentence.get(i), StrUtils.join(alignments))

idx只是句子对 id。

out就是你想打印的地方。

于 2012-01-02T23:16:05.597 回答