After downloading the trunk code from http://code.google.com/p/berkeleyaligner/, I added the project into my build path on Eclipse. Then with the code below i can extract the alignments for each sentence pair that i’ve read from the sourceFile and targetFile.
After the alignment, how to read the Alignment type from the 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???
}
}
e.g. sourceFile:
this is the first line in the textfile.
that is the second line.
foo bar likes to eat bar foo.
e.g. targetFile:
Dies ist die erste Textzeile in der Datei.
das ist die zweite Zeile.
foo bar gerne bar foo essen.
Print the GIZA. Alignment has a method for that:
GIZA is:
idxis just the sentence pair id.outis just where you want to print it.