从 下载主干代码后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.