gpt4 book ai didi

java - 如何从 Berkeley Aligner 读取 Alignment 类型? - java

转载 作者:太空宇宙 更新时间:2023-11-04 08:25:13 28 4
gpt4 key购买 nike

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

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.

最佳答案

打印 GIZA。 Alignment有一个方法:

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 正是您想要打印它的位置。

关于java - 如何从 Berkeley Aligner 读取 Alignment 类型? - java ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8704185/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com