BufferedReader brIn = new BufferedReader(new InputStreamReader(System.in, encoding));
TreeReaderFactory trf = new ArabicTreeReaderFactory.ArabicRawTreeReaderFactory(true);
int nTrees = 0;
for(String line; (line = brIn.readLine()) != null; ++nTrees) {
Tree tree = trf.newTreeReader(new StringReader(line)).readTree();
List<Tree> leaves = tree.getLeaves();
if(!morphIter.hasNext()) {
throw new RuntimeException("Mismatch between number of morpho analyses and number of input lines.");
}
List<String> morphTags = morphIter.next();
if (!lemmaIter.hasNext()) {
throw new RuntimeException("Mismatch between number of lemmas and number of input lines.");
}
List<String> lemmas = lemmaIter.next();
// Sanity checks
assert morphTags.size() == lemmas.size();
assert lemmas.size() == leaves.size();
for(int i = 0; i < leaves.size(); ++i) {
String morphTag = morphTags.get(i);
if (pParenStripper.matcher(morphTag).find()) {
morphTag = pParenStripper.matcher(morphTag).replaceAll("");
}
String newLeaf = String.format("%s%s%s%s%s", leaves.get(i).value(),
MorphoFeatureSpecification.MORPHO_MARK,
lemmas.get(i),
MorphoFeatureSpecification.LEMMA_MARK,
morphTag);
leaves.get(i).setValue(newLeaf);
}
System.out.println(tree.toString());
}
// Sanity checks
assert !morphIter.hasNext();
assert !lemmaIter.hasNext();