use of org.omegat.core.data.ParseEntry.ParseEntryResult in project omegat by omegat-org.
the class Aligner method parseFile.
/**
* Parse the specified file and return the contents as a pair of lists:
* <ul>
* <li>Key: A list of IDs for the parsed text units
* <li>Value: A list of parsed text units
* </ul>
*
* @param file
* Path to input file
* @return Pair of lists
* @throws Exception
* If parsing fails
*/
private Entry<List<String>, List<String>> parseFile(String file) throws Exception {
final List<String> ids = new ArrayList<>();
final List<String> rawSegs = new ArrayList<>();
Core.getFilterMaster().loadFile(file, new FilterContext(srcLang, trgLang, true).setRemoveAllTags(removeTags), new IParseCallback() {
@Override
public void linkPrevNextSegments() {
}
@Override
public void addEntry(String id, String source, String translation, boolean isFuzzy, String comment, IFilter filter) {
process(source, id);
}
@Override
public void addEntry(String id, String source, String translation, boolean isFuzzy, String comment, String path, IFilter filter, List<ProtectedPart> protectedParts) {
process(source, id != null ? id : path != null ? path : null);
}
@Override
public void addEntryWithProperties(String id, String source, String translation, boolean isFuzzy, String[] props, String path, IFilter filter, List<ProtectedPart> protectedParts) {
process(source, id != null ? id : path != null ? path : null);
}
private void process(String text, String id) {
boolean removeSpaces = Core.getFilterMaster().getConfig().isRemoveSpacesNonseg();
text = StringUtil.normalizeUnicode(ParseEntry.stripSomeChars(text, new ParseEntryResult(), removeTags, removeSpaces));
if (!text.trim().isEmpty()) {
if (id != null) {
ids.add(id);
}
rawSegs.add(text);
}
}
});
return new AbstractMap.SimpleImmutableEntry<>(ids, rawSegs);
}
Aggregations