当前位置: 首页>>代码示例>>Java>>正文


Java Languages.get方法代码示例

本文整理汇总了Java中org.languagetool.Languages.get方法的典型用法代码示例。如果您正苦于以下问题:Java Languages.get方法的具体用法?Java Languages.get怎么用?Java Languages.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.languagetool.Languages的用法示例。


在下文中一共展示了Languages.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getLanguageCodes

import org.languagetool.Languages; //导入方法依赖的package包/类
private static List<String> getLanguageCodes() {
  List<String> langCodes = new ArrayList<>();
  for (Language lang : Languages.get()) {
    String langCode = lang.getShortCode();
    boolean ignore = lang.isVariant() || ignoreLangCodes.contains(langCode) || externalLangCodes.contains(langCode);
    if (ignore) {
      continue;
    }
    if ("zh".equals(langCode)) {
      langCodes.add("zh-CN");
      langCodes.add("zh-TW");
    } else {
      langCodes.add(langCode);
    }
  }
  return langCodes;
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:18,代码来源:LanguageIdentifier.java

示例2: test

import org.languagetool.Languages; //导入方法依赖的package包/类
@Test
@Ignore("for interactive use only")
public void test() throws Exception {
  List<Language> languages1 = new ArrayList<>(Languages.get());
  initExpectedResults(languages1);
  List<Language> languages2 = new ArrayList<>(Languages.get());
  ExecutorService executor = Executors.newFixedThreadPool(THREADS);
  for (int i = 0; i < RUNS; i++) {
    System.out.println("Run #" + i);
    Collections.shuffle(languages1, rnd);
    Collections.shuffle(languages2, rnd);
    List<Future> futures = new ArrayList<>();
    for (int j = 0; j < languages1.size(); j++) {
      Language lang1 = languages1.get(j);
      Language lang2 = languages2.get(j);
      //System.out.println("Checking " + lang1 + " and " + lang2);
      futures.add(executor.submit(new Handler(lang1)));
      futures.add(executor.submit(new Handler(lang2)));
    }
    for (Future future : futures) {
      future.get();  // wait for all results or exception
    }
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:25,代码来源:MultiThreadingTest1.java

示例3: testOfficeFootnoteTokenize

import org.languagetool.Languages; //导入方法依赖的package包/类
@Test
public void testOfficeFootnoteTokenize() {
  int count = 0;
  for (Language language : Languages.get()) {
    if (language.getSentenceTokenizer().getClass() != SRXSentenceTokenizer.class) {
      continue;
    }
    if (language.getShortCode().equals("km") || language.getShortCode().equals("ml")) {
      // TODO: I don't know about these...
      continue;
    }
    String input = "A sentence.\u0002 And another one.";
    SentenceTokenizer tokenizer = new SRXSentenceTokenizer(language);
    assertEquals("Sentence not split correctly for " + language + ": '" + input + "'",
            "[A sentence.\u0002 , And another one.]", tokenizer.tokenize(input).toString());
    count++;
  }
  if (count == 0) {
    fail("No languages found for testing");
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:22,代码来源:SRXSentenceTokenizerTest.java

示例4: testConfusionSetLoading

import org.languagetool.Languages; //导入方法依赖的package包/类
@Test
public void testConfusionSetLoading() throws IOException {
  int count = 0;
  for (Language language : Languages.get()) {
    List<Rule> rules;
    try {
      rules = language.getRelevantLanguageModelRules(JLanguageTool.getMessageBundle(), new FakeLanguageModel());
    } catch (Exception e) {
      throw new RuntimeException("Could not load confusion pairs for " + language.getName(), e);
    }
    if (rules.size() > 0) {
      String path = "/" + language.getShortCode() + "/confusion_sets.txt";
      try (InputStream confusionSetStream = JLanguageTool.getDataBroker().getFromResourceDirAsStream(path)) {
        ConfusionSetLoader confusionSetLoader = new ConfusionSetLoader();
        Map<String, List<ConfusionSet>> set = confusionSetLoader.loadConfusionSet(confusionSetStream);
        count += set.size();
      }
    }
  }
  int minCount = 1000;
  assertTrue("Only got " + count + " confusion pairs for all languages, expected > " + minCount, count > minCount);
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:23,代码来源:ConfusionSetLoaderTest.java

示例5: testWordListValidity

import org.languagetool.Languages; //导入方法依赖的package包/类
@Test
public void testWordListValidity() throws IOException {
  Set<String> checked = new HashSet<>();
  for (Language lang : Languages.get()) {
    if (lang.getShortCode().equals("ru")) {
      // skipping, Cyrillic chars not part of the validation yet
      continue;
    }
    JLanguageTool lt = new JLanguageTool(lang);
    List<Rule> rules = lt.getAllActiveRules();
    for (Rule rule : rules) {
      if (rule instanceof SpellingCheckRule) {
        SpellingCheckRule sRule = (SpellingCheckRule) rule;
        String file = sRule.getSpellingFileName();
        if (JLanguageTool.getDataBroker().resourceExists(file) && !checked.contains(file)) {
          System.out.println("Checking " + file);
          CachingWordListLoader loader = new CachingWordListLoader();
          List<String> words = loader.loadWords(file);
          validateWords(words, file);
          checked.add(file);
        }
      }
    }
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:26,代码来源:WordListValidatorTest.java

示例6: warmUp

import org.languagetool.Languages; //导入方法依赖的package包/类
/**
 * 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");
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:26,代码来源:Server.java

示例7: getLanguages

import org.languagetool.Languages; //导入方法依赖的package包/类
String getLanguages() throws IOException {
  StringWriter sw = new StringWriter();
  try (JsonGenerator g = factory.createGenerator(sw)) {
    g.writeStartArray();
    List<Language> languages = new ArrayList<>(Languages.get());
    languages.sort((o1, o2) -> o1.getName().compareTo(o2.getName()));
    for (Language lang : languages) {
      g.writeStartObject();
      g.writeStringField("name", lang.getName());
      g.writeStringField("code", lang.getShortCode());
      g.writeStringField("longCode", lang.getShortCodeWithCountryAndVariant());
      g.writeEndObject();
    }
    g.writeEndArray();
  }
  return sw.toString();
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:18,代码来源:ApiV2.java

示例8: main

import org.languagetool.Languages; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
  List<Language> realLanguages = Languages.get();
  System.out.println("This example will test a short string with all languages known to LanguageTool.");
  System.out.println("It's just a test to make sure there's at least no crash.");
  System.out.println("Using LanguageTool " + JLanguageTool.VERSION + " (" + JLanguageTool.BUILD_DATE + ")");
  System.out.println("Supported languages: " + realLanguages.size());
  for (Language language : realLanguages) {
    JLanguageTool langTool = new JLanguageTool(language);
    String input = "And the the";
    List<RuleMatch> result = langTool.check(input);
    System.out.println("Checking '" + input + "' with " + language + ":");
    for (RuleMatch ruleMatch : result) {
      System.out.println("    " + ruleMatch);
    }
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:17,代码来源:Example.java

示例9: shortMessageIsLongerThanErrorMessage

import org.languagetool.Languages; //导入方法依赖的package包/类
@Test
public void shortMessageIsLongerThanErrorMessage() throws IOException {
  for (Language lang : Languages.get()) {
    if (skipCountryVariant(lang)) {
      // Skipping because there are no specific rules for this variant
      return;
    }
    JLanguageTool languageTool = new JLanguageTool(lang);
    for (AbstractPatternRule rule : getAllPatternRules(lang, languageTool)) {
      warnIfShortMessageLongerThanErrorMessage(rule);
    }
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:14,代码来源:PatternRuleTest.java

示例10: runGrammarRulesFromXmlTest

import org.languagetool.Languages; //导入方法依赖的package包/类
/**
 * 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");
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:19,代码来源:PatternRuleTest.java

示例11: testExportAndImport

import org.languagetool.Languages; //导入方法依赖的package包/类
@Test
@Ignore("for interactive use only")
public void testExportAndImport() throws Exception {
  for (Language language : Languages.get()) {
    String langCode = language.getShortCode();
    File dir = new File("./languagetool-language-modules/" + langCode + "/src/main/resources/org/languagetool/resource/" + langCode);
    File oldBinaryFile = new File(dir, language.getName().toLowerCase() + ".dict");
    File infoFile = new File(dir, language.getName().toLowerCase() + ".info");
    File exportFile = exportDictionaryContents(oldBinaryFile);
    if (exportFile.length() == 0) {
      System.out.println("Zero-size output for " + language + ", skipping dictionary generation");
      exportFile.delete();
      continue;
    }
    POSDictionaryBuilder builder = new POSDictionaryBuilder(infoFile);
    File newBinaryFile = builder.build(exportFile);
    exportFile.delete();
    System.out.println(language + " old binary file size: " + oldBinaryFile.length() + " bytes (" + oldBinaryFile.getName() + ")");
    System.out.println(language + " new binary file size: " + newBinaryFile.length() + " bytes (" + newBinaryFile.getAbsolutePath() + ")");
    // comment in to copy the new files over the old ones:
    /*boolean b = newBinaryFile.renameTo(oldBinaryFile);
    if (!b) {
      throw new RuntimeException("Could not rename" + newBinaryFile.getAbsolutePath() + " to " + oldBinaryFile.getCanonicalPath());
    }*/
    System.out.println("");
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:28,代码来源:POSDictionaryBuilderTest.java

示例12: testExportPosDictAndCreateSynth

import org.languagetool.Languages; //导入方法依赖的package包/类
@Test
@Ignore("for interactive use only")
public void testExportPosDictAndCreateSynth() throws Exception {
  for (Language language : Languages.get()) {
    String langCode = language.getShortCode();
    File dir = new File("./languagetool-language-modules/" + langCode + "/src/main/resources/org/languagetool/resource/" + langCode);
    File oldBinarySynthFile = new File(dir, language.getName().toLowerCase() + "_synth.dict");
    if (!oldBinarySynthFile.exists()) {
      System.out.println("Ignoring " + language + ", no synth file found");
      continue;
    }
    File oldBinaryFile = new File(dir, language.getName().toLowerCase() + ".dict");
    File infoFile = new File(dir, language.getName().toLowerCase() + "_synth.info");
    File exportFile = exportDictionaryContents(oldBinaryFile);
    if (exportFile.length() == 0) {
      System.out.println("Zero-size output for " + language + ", skipping dictionary generation");
      exportFile.delete();
      continue;
    }
    SynthDictionaryBuilder builder = new SynthDictionaryBuilder(infoFile);
    File newBinarySynthFile = builder.build(exportFile, infoFile);
    exportFile.delete();
    System.out.println(language + " old binary file size: " + oldBinarySynthFile.length() + " bytes (" + oldBinarySynthFile.getName() + ")");
    System.out.println(language + " new binary file size: " + newBinarySynthFile.length() + " bytes (" + newBinarySynthFile.getAbsolutePath() + ")");
    // comment in to copy the new files over the old ones:
    /*boolean b = newBinarySynthFile.renameTo(oldBinarySynthFile);
    if (!b) {
      throw new RuntimeException("Could not rename " + newBinarySynthFile.getAbsolutePath() + " to " + oldBinarySynthFile.getCanonicalPath());
    }*/
    System.out.println("");
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:33,代码来源:SynthDictionaryBuilderTest.java

示例13: getLocales

import org.languagetool.Languages; //导入方法依赖的package包/类
/**
 * @return An array of Locales supported by LT
 */
@Override
public final Locale[] getLocales() {
  try {
    List<Locale> locales = new ArrayList<>();
    for (Language lang : Languages.get()) {
      if (lang.getCountries().length == 0) {
        // e.g. Esperanto
        if (lang.getVariant() != null) {
          locales.add(new Locale(LIBREOFFICE_SPECIAL_LANGUAGE_TAG, "", lang.getShortCodeWithCountryAndVariant()));
        } else {
          locales.add(new Locale(lang.getShortCode(), "", ""));
        }
      } else {
        for (String country : lang.getCountries()) {
          if (lang.getVariant() != null) {
            locales.add(new Locale(LIBREOFFICE_SPECIAL_LANGUAGE_TAG, country, lang.getShortCodeWithCountryAndVariant()));
          } else {
            locales.add(new Locale(lang.getShortCode(), country, ""));
          }
        }
      }
    }
    return locales.toArray(new Locale[locales.size()]);
  } catch (Throwable t) {
    showError(t);
    return new Locale[0];
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:32,代码来源:Main.java

示例14: runTests

import org.languagetool.Languages; //导入方法依赖的package包/类
private void runTests(int threadNumber) throws IOException {
  List<Language> languages = Languages.get();
  Language lang = languages.get(rnd.nextInt(languages.size()));
  List<ExampleSentence> sentences = provider.getRandomSentences(lang);
  String text = getSentencesAsText(sentences);
  String data = "language=" + lang.getShortCodeWithCountryAndVariant() + "&text=" + URLEncoder.encode(text, "utf-8");
  String resultXml = checkAtUrl(new URL(SERVER_URL), data, threadNumber);
  for (ExampleSentence sentence : sentences) {
    assertTrue("Expected " + sentence.getRuleId() + " for '" + text + "' (" + sentences.size() + " sentences)", resultXml.contains(sentence.getRuleId()));
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:12,代码来源:HTTPSServerTesting.java

示例15: loadConfigForOtherLanguages

import org.languagetool.Languages; //导入方法依赖的package包/类
private void loadConfigForOtherLanguages(Language lang, Properties prop) {
  for (Language otherLang : Languages.get()) {
    if (!otherLang.equals(lang)) {
      String languageSuffix = "." + otherLang.getShortCodeWithCountryAndVariant();
      storeConfigKeyFromProp(prop, DISABLED_RULES_KEY + languageSuffix);
      storeConfigKeyFromProp(prop, ENABLED_RULES_KEY + languageSuffix);
      storeConfigKeyFromProp(prop, DISABLED_CATEGORIES_KEY + languageSuffix);
    }
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:11,代码来源:Configuration.java


注:本文中的org.languagetool.Languages.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。