Search in sources :

Example 71 with Language

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

the class Server method warmUp.

/**
   * Check a tiny text with all languages and all variants, so that e.g. static caches
   * get initialized. This helps getting a slightly better performance when real
   * texts get checked.
   */
protected void warmUp() {
    List<Language> languages = Languages.get();
    System.out.println("Running warm up with all " + languages.size() + " languages/variants:");
    for (int i = 1; i <= 2; i++) {
        long startTime = System.currentTimeMillis();
        for (Language language : languages) {
            System.out.print(language.getLocaleWithCountryAndVariant() + " ");
            JLanguageTool lt = new JLanguageTool(language);
            try {
                lt.check("test");
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        long endTime = System.currentTimeMillis();
        float runTime = (endTime - startTime) / 1000.0f;
        System.out.printf(Locale.ENGLISH, "\nRun #" + i + " took %.2fs\n", runTime);
    }
    System.out.println("Warm up finished");
}
Also used : Language(org.languagetool.Language) JLanguageTool(org.languagetool.JLanguageTool) IOException(java.io.IOException)

Example 72 with Language

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

the class HTTPServerOverheadTest method runLoop.

private void runLoop(HashMap<Language, Float> results, List<Language> languages) throws IOException {
    for (Language lang : languages) {
        System.out.println(lang + "...");
        int runs = 30;
        long times = 0;
        for (int i = 0; i < runs; i++) {
            long startTime = System.currentTimeMillis();
            checkTextOnServer(lang, "");
            times += System.currentTimeMillis() - startTime;
        }
        float averageTime = (float) times / (float) runs;
        results.put(lang, averageTime);
    }
}
Also used : Language(org.languagetool.Language)

Example 73 with Language

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

the class XmlUsageCounter method main.

public static void main(String[] args) throws XMLStreamException {
    XmlUsageCounter counter = new XmlUsageCounter();
    Set<String> countedFiles = new HashSet<>();
    for (Language language : Languages.get()) {
        List<String> ruleFileNames = language.getRuleFileNames();
        //        language.getShortCode() + "/" + "disambiguation.xml");
        for (String ruleFileName : ruleFileNames) {
            if (countedFiles.contains(ruleFileName)) {
                continue;
            }
            System.err.println("Counting elements for " + ruleFileName);
            InputStream ruleStream = XmlUsageCounter.class.getResourceAsStream(ruleFileName);
            if (ruleStream == null) {
                System.err.println("Not found, ignoring: " + ruleFileName);
                continue;
            }
            counter.countElementsAndAttributes(ruleStream);
            countedFiles.add(ruleFileName);
        }
    }
    counter.printResult();
}
Also used : Language(org.languagetool.Language) InputStream(java.io.InputStream)

Example 74 with Language

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

the class CommonCrawlToNgram3 method main.

public static void main(String[] args) throws Exception {
    if (args.length != 3) {
        System.out.println("Usage: " + CommonCrawlToNgram3.class + " <langCode> <input.xz/bz2> <outputDir>");
        System.exit(1);
    }
    Language language = Languages.getLanguageForShortCode(args[0]);
    File input = new File(args[1]);
    File outputDir = new File(args[2]);
    try (CommonCrawlToNgram3 prg = new CommonCrawlToNgram3(language, input, outputDir)) {
        prg.indexInputFile();
    }
}
Also used : Language(org.languagetool.Language)

Example 75 with Language

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

the class RuleActivityOverview method run.

private void run() {
    System.out.println("Commits per language in the last " + PAST_DAYS + " days");
    System.out.println("Date: " + new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
    List<String> sortedLanguages = new ArrayList<>();
    for (Language element : Languages.get()) {
        sortedLanguages.add(element.getName());
    }
    Collections.sort(sortedLanguages);
    for (String langName : sortedLanguages) {
        Language lang = Languages.getLanguageForName(langName);
        int commits = getActivityFor(lang, PAST_DAYS);
        System.out.println(commits + "\t" + lang.getName() + (lang.isVariant() ? " (including the parent language)" : ""));
    }
}
Also used : Language(org.languagetool.Language) ArrayList(java.util.ArrayList) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

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