Search in sources :

Example 6 with BitextRule

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;
}
Also used : BitextPatternRule(org.languagetool.rules.patterns.bitext.BitextPatternRule) FalseFriendsAsBitextLoader(org.languagetool.rules.patterns.bitext.FalseFriendsAsBitextLoader) BitextPatternRuleLoader(org.languagetool.rules.patterns.bitext.BitextPatternRuleLoader) BitextRule(org.languagetool.rules.bitext.BitextRule)

Aggregations

BitextRule (org.languagetool.rules.bitext.BitextRule)6 Language (org.languagetool.Language)3 RuleMatch (org.languagetool.rules.RuleMatch)2 BitextPatternRule (org.languagetool.rules.patterns.bitext.BitextPatternRule)2 Constructor (java.lang.reflect.Constructor)1 ArrayList (java.util.ArrayList)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 AnalyzedSentence (org.languagetool.AnalyzedSentence)1 JLanguageTool (org.languagetool.JLanguageTool)1 MultiThreadedJLanguageTool (org.languagetool.MultiThreadedJLanguageTool)1 Rule (org.languagetool.rules.Rule)1 BitextPatternRuleLoader (org.languagetool.rules.patterns.bitext.BitextPatternRuleLoader)1 FalseFriendsAsBitextLoader (org.languagetool.rules.patterns.bitext.FalseFriendsAsBitextLoader)1 StringTools.readerToString (org.languagetool.tools.StringTools.readerToString)1 SAXException (org.xml.sax.SAXException)1