Search in sources :

Example 1 with FalseFriendsAsBitextLoader

use of org.languagetool.rules.patterns.bitext.FalseFriendsAsBitextLoader in project languagetool by languagetool-org.

the class FalseFriendsAsBitextLoaderTest method testHintsForPolishTranslators.

@Test
public void testHintsForPolishTranslators() throws IOException, ParserConfigurationException, SAXException {
    Polish polish = new Polish();
    English english = new English();
    JLanguageTool langTool = new JLanguageTool(english, polish);
    JLanguageTool trgTool = new JLanguageTool(polish);
    FalseFriendsAsBitextLoader ruleLoader = new FalseFriendsAsBitextLoader();
    String name = "/false-friends.xml";
    List<BitextPatternRule> rules = ruleLoader.getFalseFriendsAsBitext(name, english, polish);
    assertErrors(1, rules, "This is an absurd.", "To absurd.", langTool, trgTool);
    assertErrors(1, rules, "I have to speak to my advocate.", "Muszę porozmawiać z adwokatem.", langTool, trgTool);
    assertErrors(1, rules, "This is not actual.", "To nie jest aktualne.", langTool, trgTool);
    assertErrors(0, rules, "This is not actual.", "To nie jest rzeczywiste.", langTool, trgTool);
}
Also used : English(org.languagetool.language.English) Polish(org.languagetool.language.Polish) JLanguageTool(org.languagetool.JLanguageTool) BitextPatternRule(org.languagetool.rules.patterns.bitext.BitextPatternRule) FalseFriendsAsBitextLoader(org.languagetool.rules.patterns.bitext.FalseFriendsAsBitextLoader) Test(org.junit.Test)

Example 2 with FalseFriendsAsBitextLoader

use of org.languagetool.rules.patterns.bitext.FalseFriendsAsBitextLoader 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

BitextPatternRule (org.languagetool.rules.patterns.bitext.BitextPatternRule)2 FalseFriendsAsBitextLoader (org.languagetool.rules.patterns.bitext.FalseFriendsAsBitextLoader)2 Test (org.junit.Test)1 JLanguageTool (org.languagetool.JLanguageTool)1 English (org.languagetool.language.English)1 Polish (org.languagetool.language.Polish)1 BitextRule (org.languagetool.rules.bitext.BitextRule)1 BitextPatternRuleLoader (org.languagetool.rules.patterns.bitext.BitextPatternRuleLoader)1