use of org.languagetool.rules.bitext.BitextRule in project languagetool by languagetool-org.
the class Tools method getBitextRules.
/**
* Gets default bitext rules for a given pair of languages
* @param source Source language.
* @param target Target language.
* @param externalBitextRuleFile external file with bitext rules
* @return List of Bitext rules
* @since 2.9
*/
public static List<BitextRule> getBitextRules(Language source, Language target, File externalBitextRuleFile) throws IOException, ParserConfigurationException, SAXException {
List<BitextRule> bRules = new ArrayList<>();
//try to load the bitext pattern rules for the language...
BitextPatternRuleLoader ruleLoader = new BitextPatternRuleLoader();
String name = "/" + target.getShortCode() + "/bitext.xml";
if (JLanguageTool.getDataBroker().ruleFileExists(name)) {
InputStream is = JLanguageTool.getDataBroker().getFromRulesDirAsStream(name);
if (is != null) {
bRules.addAll(ruleLoader.getRules(is, name));
}
}
if (externalBitextRuleFile != null) {
bRules.addAll(ruleLoader.getRules(new FileInputStream(externalBitextRuleFile), externalBitextRuleFile.getAbsolutePath()));
}
//load the false friend rules in the bitext mode:
FalseFriendsAsBitextLoader fRuleLoader = new FalseFriendsAsBitextLoader();
String falseFriendsFile = "/false-friends.xml";
List<BitextPatternRule> rules = fRuleLoader.getFalseFriendsAsBitext(falseFriendsFile, source, target);
bRules.addAll(rules);
//load Java bitext rules:
bRules.addAll(getAllBuiltinBitextRules(source, null));
return bRules;
}
Aggregations