public String toString() { StringBuilder sb = new StringBuilder(); for (int position = 0; position < words.size(); position++) { String word = words.get(position); String tag = tags.get(position); sb.append(word); sb.append("_"); sb.append(tag); } return sb.toString(); }
public String toString() { StringBuilder sb = new StringBuilder(); for (int englishPosition = 0; englishPosition < englishWords.size(); englishPosition++) { String englishWord = englishWords.get(englishPosition); sb.append(englishPosition); sb.append(":"); sb.append(englishWord); sb.append(" "); } sb.append("\n"); for (int frenchPosition = 0; frenchPosition < frenchWords.size(); frenchPosition++) { String frenchWord = frenchWords.get(frenchPosition); sb.append(frenchPosition); sb.append(":"); sb.append(frenchWord); sb.append(" "); } sb.append("\n"); return sb.toString(); }
// pretty-print a pair of taggings for a sentence, possibly suppressing the tags which correctly // match private static String alignedTaggings( List<String> words, List<String> goldTags, List<String> guessedTags, boolean suppressCorrectTags) { StringBuilder goldSB = new StringBuilder("Gold Tags: "); StringBuilder guessedSB = new StringBuilder("Guessed Tags: "); StringBuilder wordSB = new StringBuilder("Words: "); for (int position = 0; position < words.size(); position++) { equalizeLengths(wordSB, goldSB, guessedSB); String word = words.get(position); String gold = goldTags.get(position); String guessed = guessedTags.get(position); wordSB.append(word); if (position < words.size() - 1) wordSB.append(' '); boolean correct = (gold.equals(guessed)); if (correct && suppressCorrectTags) continue; guessedSB.append(guessed); goldSB.append(gold); } return goldSB + "\n" + guessedSB + "\n" + wordSB; }
private static void ensureLength(StringBuilder sb, int length) { while (sb.length() < length) { sb.append(' '); } }
public static String render(Alignment reference, Alignment proposed, SentencePair sentencePair) { StringBuilder sb = new StringBuilder(); for (int frenchPosition = 0; frenchPosition < sentencePair.getFrenchWords().size(); frenchPosition++) { for (int englishPosition = 0; englishPosition < sentencePair.getEnglishWords().size(); englishPosition++) { boolean sure = reference.containsSureAlignment(englishPosition, frenchPosition); boolean possible = reference.containsPossibleAlignment(englishPosition, frenchPosition); char proposedChar = ' '; if (proposed.containsSureAlignment(englishPosition, frenchPosition)) proposedChar = '#'; if (sure) { sb.append('['); sb.append(proposedChar); sb.append(']'); } else { if (possible) { sb.append('('); sb.append(proposedChar); sb.append(')'); } else { sb.append(' '); sb.append(proposedChar); sb.append(' '); } } } sb.append("| "); sb.append(sentencePair.getFrenchWords().get(frenchPosition)); sb.append('\n'); } for (int englishPosition = 0; englishPosition < sentencePair.getEnglishWords().size(); englishPosition++) { sb.append("---"); } sb.append("'\n"); boolean printed = true; int index = 0; while (printed) { printed = false; StringBuilder lineSB = new StringBuilder(); for (int englishPosition = 0; englishPosition < sentencePair.getEnglishWords().size(); englishPosition++) { String englishWord = sentencePair.getEnglishWords().get(englishPosition); if (englishWord.length() > index) { printed = true; lineSB.append(' '); lineSB.append(englishWord.charAt(index)); lineSB.append(' '); } else { lineSB.append(" "); } } index += 1; if (printed) { sb.append(lineSB); sb.append('\n'); } } return sb.toString(); }