Skip to content

Commit

Permalink
Improved resegmentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rmraya committed Dec 30, 2019
1 parent 7100762 commit 82dfc90
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
Binary file modified lib/openxliff.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/com/maxprograms/converters/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private Constants() {
public static final String TOOLID = "OpenXLIFF";
public static final String TOOLNAME = "OpenXLIFF Filters";
public static final String VERSION = "1.7.0";
public static final String BUILD = "20191230_1446";
public static final String BUILD = "20191230_1657";

public static final String SUCCESS = "0";
public static final String ERROR = "1";
Expand Down
31 changes: 20 additions & 11 deletions src/com/maxprograms/xliff2/Resegmenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,13 @@ private static void recurse(Element root) throws SAXException, IOException, Pars

while (it.hasNext()) {
XMLNode n = it.next();
switch (n.getNodeType()) {
case XMLNode.TEXT_NODE:
TextNode text = (TextNode) n;
System.out.println("Text node found: \\" + text.toString() + "\\");
break;
case XMLNode.ELEMENT_NODE:
if (n.getNodeType() == XMLNode.ELEMENT_NODE) {
Element e = (Element) n;
if ("mrk".equals(e.getName()) && "seg".equals(e.getAttributeValue("mtype"))
&& !e.getContent().isEmpty()) {
if ("mrk".equals(e.getName()) && "seg".equals(e.getAttributeValue("mtype"))) {
Element newSeg = new Element("segment");
if (!hasText(e)) {
newSeg = new Element("ignorable");
}
newSeg.setAttribute("id", root.getAttributeValue("id") + '-' + e.getAttributeValue("mid"));
root.addContent(newSeg);
Element newSource = new Element("source");
Expand All @@ -95,9 +92,6 @@ private static void recurse(Element root) throws SAXException, IOException, Pars
} else {
throw new SAXException("Unexpected element found: " + e.toString());
}
break;
default:
// ignore
}
}
}
Expand All @@ -109,4 +103,19 @@ private static void recurse(Element root) throws SAXException, IOException, Pars
}
}
}

private static boolean hasText(Element e) {
List<XMLNode> content = e.getContent();
Iterator<XMLNode> it = content.iterator();
while (it.hasNext()) {
XMLNode node = it.next();
if (node.getNodeType() == XMLNode.TEXT_NODE) {
TextNode t = (TextNode) node;
if (!t.getText().isBlank()) {
return true;
}
}
}
return false;
}
}

0 comments on commit 82dfc90

Please sign in to comment.