use of org.omegat.util.TagUtil.Tag in project omegat by omegat-org.
the class TagValidationTool method logTagValidationErrors.
@Override
public synchronized void logTagValidationErrors(List<ErrorReport> suspects) {
if (suspects != null && !suspects.isEmpty()) {
for (ErrorReport report : suspects) {
System.out.println(report.entryNum);
System.out.println(report.source);
System.out.println(report.translation);
for (Map.Entry<TagError, List<Tag>> e : report.inverseReport().entrySet()) {
System.out.print(" ");
System.out.print(ErrorReport.localizedTagError(e.getKey()));
System.out.print(": ");
for (Tag tag : e.getValue()) {
System.out.print(tag);
System.out.print(" ");
}
System.out.println();
}
}
}
}
use of org.omegat.util.TagUtil.Tag in project omegat by omegat-org.
the class EditorUtils method addBidiAroundTags.
/**
* Add RTL+LTR around tags. Used for display tags better in RTL text.
*/
public static String addBidiAroundTags(String text, SourceTextEntry ste) {
List<Tag> tags = TagUtil.buildTagList(text, ste.getProtectedParts());
int pos = 0;
StringBuilder s = new StringBuilder(text.length() * 12 / 10);
for (Tag t : tags) {
if (pos < t.pos) {
s.append(text.substring(pos, t.pos));
}
s.append(SegmentBuilder.BIDI_RLM_CHAR);
s.append(SegmentBuilder.BIDI_LRM_CHAR);
s.append(t.tag);
s.append(SegmentBuilder.BIDI_LRM_CHAR);
s.append(SegmentBuilder.BIDI_RLM_CHAR);
pos = t.pos + t.tag.length();
}
if (pos < text.length()) {
s.append(text.substring(pos));
}
return s.toString();
}
use of org.omegat.util.TagUtil.Tag in project omegat by omegat-org.
the class TagAutoCompleterView method computeListData.
@Override
public List<AutoCompleterItem> computeListData(String prevText, boolean contextualOnly) {
String wordChunk = getLastToken(prevText);
List<String> missingGroups = TagUtil.getGroupedMissingTagsFromTarget();
// If wordChunk is a tag, pretend we have a blank wordChunk.
for (Tag tag : TagUtil.getAllTagsInSource()) {
if (tag.tag.equals(wordChunk)) {
wordChunk = "";
break;
}
}
List<String> matchGroups = new ArrayList<String>();
if (!"".equals(wordChunk)) {
// Check for partial matches among missing tag groups.
for (String g : missingGroups) {
if (g.startsWith(wordChunk)) {
matchGroups.add(g);
}
}
}
// If there are no partial matches, show all missing tags as suggestions.
if (matchGroups.isEmpty() && !contextualOnly) {
return convertList(missingGroups, 0);
}
return convertList(matchGroups, wordChunk.length());
}
use of org.omegat.util.TagUtil.Tag in project omegat by omegat-org.
the class TagRepairTest method testRepairTags.
@Test
public void testRepairTags() {
// Fix extraneous
StringBuilder text = new StringBuilder("Foo bar baz bar bonkers");
TagRepair.fixExtraneous(text, new Tag(-1, "bar"));
TagRepair.fixExtraneous(text, new Tag(-1, "bar"));
assertEquals("Foo baz bonkers", text.toString());
// Fix missing: before
text = new StringBuilder("Foo bar {tag2}baz");
String[] tags = { "{tag1}", "{tag2}" };
TagRepair.fixMissing(TagValidationTest.getList(tags), text, new Tag(-1, "{tag1}"));
assertEquals("Foo bar {tag1}{tag2}baz", text.toString());
// Fix missing: after
text = new StringBuilder("Foo bar {tag2}baz");
String[] tags2 = { "{tag2}", "{tag1}" };
TagRepair.fixMissing(TagValidationTest.getList(tags2), text, new Tag(-1, "{tag1}"));
assertEquals("Foo bar {tag2}{tag1}baz", text.toString());
// Fix missing: no anchor
text = new StringBuilder("Foo bar baz");
String[] tags3 = { "{tag1}" };
TagRepair.fixMissing(TagValidationTest.getList(tags3), text, new Tag(-1, "{tag1}"));
assertEquals("Foo bar baz{tag1}", text.toString());
// Fix malformed
text = new StringBuilder("Foo bar {tag2}baz{tag1}");
String[] tags4 = { "{tag1}", "{tag2}" };
TagRepair.fixMalformed(TagValidationTest.getList(tags4), text, new Tag(-1, "{tag1}"));
assertEquals("Foo bar {tag1}{tag2}baz", text.toString());
// Fix whitespace
text = new StringBuilder("\nFoo\n");
TagRepair.fixWhitespace(text, "Foo");
assertEquals("Foo", text.toString());
// Fix whitespace
text = new StringBuilder("Foo");
TagRepair.fixWhitespace(text, "\nFoo\n");
assertEquals("\nFoo\n", text.toString());
}
use of org.omegat.util.TagUtil.Tag in project omegat by omegat-org.
the class TagValidationTest method testRemovePattern.
@Test
public void testRemovePattern() throws Exception {
TestPreferencesInitializer.init();
Preferences.setPreference(Preferences.CHECK_REMOVE_PATTERN, "foo");
// No error
ErrorReport report = new ErrorReport("foo bar baz", "bar baz");
TagValidation.inspectRemovePattern(report);
assertTrue(report.srcErrors.isEmpty());
assertTrue(report.transErrors.isEmpty());
// Extraneous foo
report = new ErrorReport("foo bar baz", "foo bar baz");
TagValidation.inspectRemovePattern(report);
assertTrue(report.srcErrors.isEmpty());
assertTrue(report.transErrors.get(new Tag(0, "foo")) == TagError.EXTRANEOUS);
}
Aggregations