Search in sources :

Example 31 with Language

use of org.languagetool.Language in project languagetool by languagetool-org.

the class PatternRuleTest method runGrammarRulesFromXmlTest.

/**
   * To be called from language modules. Languages.get() knows only the languages that's in the classpath.
   * @param ignoredLanguage ignore this language - useful to speed up tests from languages that 
   *                        have another language as a dependency
   */
protected void runGrammarRulesFromXmlTest(Language ignoredLanguage) throws IOException {
    int count = 0;
    for (Language lang : Languages.get()) {
        if (ignoredLanguage.getShortCodeWithCountryAndVariant().equals(lang.getShortCodeWithCountryAndVariant())) {
            continue;
        }
        runGrammarRuleForLanguage(lang);
        count++;
    }
    if (count == 0) {
        System.err.println("Warning: no languages found in classpath - cannot run any grammar rule tests");
    }
}
Also used : FakeLanguage(org.languagetool.FakeLanguage) Language(org.languagetool.Language)

Example 32 with Language

use of org.languagetool.Language in project languagetool by languagetool-org.

the class MorfologikAmericanSpellerRuleTest method testSuggestions.

@Test
public void testSuggestions() throws IOException {
    Language language = new AmericanEnglish();
    Rule rule = new MorfologikAmericanSpellerRule(TestTools.getMessages("en"), language);
    super.testNonVariantSpecificSuggestions(rule, language);
}
Also used : Language(org.languagetool.Language) AmericanEnglish(org.languagetool.language.AmericanEnglish) Rule(org.languagetool.rules.Rule) Test(org.junit.Test)

Example 33 with Language

use of org.languagetool.Language in project languagetool by languagetool-org.

the class MorfologikAustralianSpellerRuleTest method testSuggestions.

@Test
public void testSuggestions() throws IOException {
    Language language = new AustralianEnglish();
    Rule rule = new MorfologikAustralianSpellerRule(TestTools.getMessages("en"), language);
    super.testNonVariantSpecificSuggestions(rule, language);
}
Also used : Language(org.languagetool.Language) Rule(org.languagetool.rules.Rule) AustralianEnglish(org.languagetool.language.AustralianEnglish) Test(org.junit.Test)

Example 34 with Language

use of org.languagetool.Language in project languagetool by languagetool-org.

the class MorfologikNewZealandSpellerRuleTest method testSuggestions.

@Test
public void testSuggestions() throws IOException {
    Language language = new NewZealandEnglish();
    Rule rule = new MorfologikNewZealandSpellerRule(TestTools.getMessages("en"), language);
    super.testNonVariantSpecificSuggestions(rule, language);
}
Also used : Language(org.languagetool.Language) NewZealandEnglish(org.languagetool.language.NewZealandEnglish) Rule(org.languagetool.rules.Rule) Test(org.junit.Test)

Example 35 with Language

use of org.languagetool.Language in project languagetool by languagetool-org.

the class AtomFeedCheckerCmd method main.

public static void main(String[] args) throws IOException, InterruptedException {
    if (args.length < 2 || args.length > 4) {
        System.out.println("Usage: " + AtomFeedCheckerCmd.class.getSimpleName() + " <atomFeedUrl> <sleepTime> [database.properties] [languageModelDir]");
        System.out.println("  <atomFeedUrl> is a Wikipedia URL to the latest changes, for example:");
        System.out.println("    https://de.wikipedia.org/w/index.php?title=Spezial:Letzte_%C3%84nderungen&feed=atom&namespace=0");
        System.out.println("  <sleepTime> -1: don't loop at all (run once), 0: run in loop, other number: run in loop and");
        System.out.println("    wait this many milliseconds between runs");
        System.out.println("  [database.properties] (optional) is a file that defines dbUrl, dbUser, and dbPassword,");
        System.out.println("    used to write the results to a database via JDBC");
        System.out.println("  [languageModelDir] (optional, use only together with database.properties) a directory with ngram");
        System.out.println("    sub directories, activates the confusion rule if supported");
        System.out.println("");
        System.out.println("  When the database.properties file is specified, this command will store all feed changes that");
        System.out.println("  cause LanguageTool rule matches to the database. If an error is then fixed later, this will");
        System.out.println("  usually also be detected and the rule match in the database will be marked as fixed. One case");
        System.out.println("  where this does not work is if the context of the error gets modified before the error is fixed.");
        System.out.println("");
        System.out.println("  Run this command regularly so that you don't miss any changes from the feed.");
        System.out.println("  As the feed may contain only the latest 50 changes, running it more often than");
        System.out.println("  once per minute may be needed for active Wikipedias.");
        System.exit(1);
    }
    String url = args[0];
    String langCode = url.substring(url.indexOf("//") + 2, url.indexOf("."));
    System.out.println("Using URL: " + url);
    System.out.println("Language code: " + langCode);
    int sleepTimeMillis = Integer.parseInt(args[1]);
    System.out.println("Sleep time: " + sleepTimeMillis + "ms (-1 = don't loop)");
    System.out.println("LanguageTool version: " + JLanguageTool.VERSION + " (" + JLanguageTool.BUILD_DATE + ")");
    DatabaseConfig databaseConfig = null;
    if (args.length >= 3) {
        String propFile = args[2];
        databaseConfig = new DatabaseConfig(propFile);
        System.out.println("Writing results to database at: " + databaseConfig.getUrl());
    }
    AtomFeedChecker atomFeedChecker;
    Language language = Languages.getLanguageForShortCode(langCode);
    if (args.length == 4) {
        String languageModelDir = args[3];
        atomFeedChecker = new AtomFeedChecker(language, databaseConfig, new File(languageModelDir));
    } else {
        atomFeedChecker = new AtomFeedChecker(language, databaseConfig);
    }
    while (true) {
        long startTime = System.currentTimeMillis();
        try {
            atomFeedChecker.runCheck(url);
            System.out.println("Run time: " + (System.currentTimeMillis() - startTime) + "ms");
            if (sleepTimeMillis == -1) {
                // don't loop at all
                break;
            } else {
                System.out.println("Sleeping " + sleepTimeMillis + "ms...");
                Thread.sleep(sleepTimeMillis);
            }
        } catch (Exception e) {
            // e.g. 50x HTTP errors, network problems
            e.printStackTrace();
            System.out.println("Sleeping " + sleepTimeMillis + "ms...");
            Thread.sleep(sleepTimeMillis);
        }
    }
}
Also used : Language(org.languagetool.Language) File(java.io.File) IOException(java.io.IOException)

Aggregations

Language (org.languagetool.Language)84 Test (org.junit.Test)23 File (java.io.File)15 ArrayList (java.util.ArrayList)12 JLanguageTool (org.languagetool.JLanguageTool)11 Rule (org.languagetool.rules.Rule)11 RuleMatch (org.languagetool.rules.RuleMatch)10 IOException (java.io.IOException)7 Ignore (org.junit.Ignore)6 StringTools.readerToString (org.languagetool.tools.StringTools.readerToString)5 InputStream (java.io.InputStream)4 English (org.languagetool.language.English)4 BitextRule (org.languagetool.rules.bitext.BitextRule)4 URL (java.net.URL)3 HashSet (java.util.HashSet)3 MultiThreadedJLanguageTool (org.languagetool.MultiThreadedJLanguageTool)3 AmericanEnglish (org.languagetool.language.AmericanEnglish)3 LanguageModel (org.languagetool.languagemodel.LanguageModel)3 LuceneLanguageModel (org.languagetool.languagemodel.LuceneLanguageModel)3 BufferedReader (java.io.BufferedReader)2