本文整理汇总了Java中org.languagetool.Languages类的典型用法代码示例。如果您正苦于以下问题:Java Languages类的具体用法?Java Languages怎么用?Java Languages使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Languages类属于org.languagetool包,在下文中一共展示了Languages类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: startElement
import org.languagetool.Languages; //导入依赖的package包/类
@Override
public void startElement(String namespaceURI, String lName,
String qName, Attributes attrs) throws SAXException {
switch (qName) {
case RULES:
String languageStr = attrs.getValue("targetLang");
language = Languages.getLanguageForShortCode(languageStr);
break;
case RULE:
super.startElement(namespaceURI, lName, qName, attrs);
correctExamples = new ArrayList<>();
incorrectExamples = new ArrayList<>();
break;
case TARGET:
startPattern(attrs);
break;
case SOURCE:
srcLang = Languages.getLanguageForShortCode(attrs.getValue("lang"));
break;
default:
super.startElement(namespaceURI, lName, qName, attrs);
break;
}
}
开发者ID:languagetool-org,项目名称:languagetool,代码行数:25,代码来源:BitextPatternRuleHandler.java
示例2: 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
示例3: getGrammarFileNames
import org.languagetool.Languages; //导入依赖的package包/类
private List<String> getGrammarFileNames(Language lang) {
String shortNameWithVariant = lang.getShortCodeWithCountryAndVariant();
List<String> fileNames = new ArrayList<>();
for (String ruleFile : lang.getRuleFileNames()) {
String nameOnly = new File(ruleFile).getName();
String fileName;
if (shortNameWithVariant.contains("-x-")) {
fileName = lang.getShortCode() + "/" + nameOnly;
} else if (shortNameWithVariant.contains("-") && !shortNameWithVariant.equals("xx-XX")
&& !shortNameWithVariant.endsWith("-ANY") && Languages.get().size() > 1) {
fileName = lang.getShortCode() + "/" + shortNameWithVariant + "/" + nameOnly;
} else {
fileName = lang.getShortCode() + "/" + nameOnly;
}
if (!fileNames.contains(fileName)) {
fileNames.add(fileName);
}
}
return fileNames;
}
开发者ID:languagetool-org,项目名称:languagetool,代码行数:21,代码来源:PatternRuleTest.java
示例4: testJson
import org.languagetool.Languages; //导入依赖的package包/类
@Test
public void testJson() {
String json = serializer.ruleMatchesToJson(matches, "This is an text.", 5, Languages.getLanguageForShortCode("xx-XX"));
// Software:
assertContains("\"LanguageTool\"", json);
assertContains(JLanguageTool.VERSION, json);
// Language:
assertContains("\"Testlanguage\"", json);
assertContains("\"xx-XX\"", json);
// Matches:
assertContains("\"My Message, use \\\"foo\\\" instead\"", json);
assertContains("\"My rule description\"", json);
assertContains("\"FAKE_ID\"", json);
assertContains("\"This is ...\"", json);
assertContains("\"http://foobar.org/blah\"", json);
assertContains("\"addition\"", json);
assertContains("\"short message\"", json);
assertContains("\"sentence\":\"This is an test sentence.\"", json);
}
开发者ID:languagetool-org,项目名称:languagetool,代码行数:20,代码来源:RuleMatchesAsJsonSerializerTest.java
示例5: hasLocale
import org.languagetool.Languages; //导入依赖的package包/类
/**
* @return true if LT supports the language of a given locale
* @param locale The Locale to check
*/
@Override
public final boolean hasLocale(Locale locale) {
try {
for (Language element : Languages.get()) {
if (locale.Language.equalsIgnoreCase(LIBREOFFICE_SPECIAL_LANGUAGE_TAG)
&& element.getShortCodeWithCountryAndVariant().equals(locale.Variant)) {
return true;
}
if (element.getShortCode().equals(locale.Language)) {
return true;
}
}
} catch (Throwable t) {
showError(t);
}
return false;
}
开发者ID:languagetool-org,项目名称:languagetool,代码行数:22,代码来源:Main.java
示例6: 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
示例7: 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
示例8: 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
示例9: testJavaRules
import org.languagetool.Languages; //导入依赖的package包/类
@Test
public void testJavaRules() throws IOException {
Map<String,String> idsToClassName = new HashMap<>();
Set<Class> ruleClasses = new HashSet<>();
if (Languages.getWithDemoLanguage().size() <= 1) {
System.err.println("***************************************************************************");
System.err.println("WARNING: found only these languages - the tests might not be complete:");
System.err.println(Languages.getWithDemoLanguage());
System.err.println("***************************************************************************");
}
for (Language language : Languages.getWithDemoLanguage()) {
JLanguageTool lt = new JLanguageTool(language);
List<Rule> allRules = lt.getAllRules();
for (Rule rule : allRules) {
if (!(rule instanceof AbstractPatternRule)) {
assertIdUniqueness(idsToClassName, ruleClasses, language, rule);
assertIdValidity(language, rule);
assertTrue(rule.supportsLanguage(language));
testExamples(rule, lt);
}
}
}
}
开发者ID:languagetool-org,项目名称:languagetool,代码行数:24,代码来源:RuleTest.java
示例10: 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
示例11: OldSpellingData
import org.languagetool.Languages; //导入依赖的package包/类
OldSpellingData(String ruleDesc) {
String filePath = "/de/alt_neu.csv";
try (InputStream inputStream = JLanguageTool.getDataBroker().getFromResourceDirAsStream(filePath);
Scanner scanner = new Scanner(inputStream, "utf-8")) {
Language german = Languages.getLanguageForShortCode("de");
String message = "Diese Schreibweise war nur in der alten Rechtschreibung korrekt.";
String shortMessage = "alte Rechtschreibung";
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line.startsWith("#")) {
continue;
}
String[] parts = line.split(";");
if (parts.length != 2) {
throw new RuntimeException("Unexpected format in file " + filePath + ": " + line);
}
String oldSpelling = parts[0];
String newSpelling = parts[1];
List<PatternToken> patternTokens = getTokens(oldSpelling, german);
PatternRule rule = new PatternRule("OLD_SPELLING_INTERNAL", german, patternTokens, ruleDesc, message, shortMessage);
spellingRules.add(new OldSpellingRuleWithSuggestion(rule, oldSpelling, newSpelling));
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
开发者ID:languagetool-org,项目名称:languagetool,代码行数:27,代码来源:OldSpellingData.java
示例12: testPerformance
import org.languagetool.Languages; //导入依赖的package包/类
@Ignore("just for internal performance testing, thus ignored by default")
@Test
public void testPerformance() throws Exception {
List<Language> allLanguages = Languages.get();
for (Language language : allLanguages) {
JLanguageTool langTool = new JLanguageTool(language);
//HunspellRule rule = new HunspellRule(TestTools.getMessages("German"), language);
langTool.check("warmup"); // make sure everything is initialized when actually testing
langTool.check("anotherwarmup");
long startTime = System.currentTimeMillis();
langTool.check("fdfds fdfdsa fdfdsb fdfdsc fdfdsd fdfdse fdfdsf fdfds fdfdsa fdfdsb fdfdsc fdfdsd fdfdse fdfdsf");
//String[] w = {"foo", "warmup", "Rechtschreipreform", "Theatrekasse", "Zoobesuck", "Handselvertreter", "Mückenstick", "gewönlich", "Traprennen", "Autoverkehrr"};
//AnalyzedSentence analyzedSentence = langTool.getAnalyzedSentence("fdfds fdfdsa fdfdsb fdfdsc fdfdsd fdfdse fdfdsf");
//rule.match(analyzedSentence);
long endTime = System.currentTimeMillis();
System.out.println((endTime-startTime) + "ms for " + language);
}
}
开发者ID:languagetool-org,项目名称:languagetool,代码行数:19,代码来源:HunspellRuleTest.java
示例13: main
import org.languagetool.Languages; //导入依赖的package包/类
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();
//comment in this to count disambiguation files instead:
//List<String> ruleFileNames = Collections.singletonList(ResourceDataBroker.RESOURCE_DIR + "/" +
// 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();
}
开发者ID:languagetool-org,项目名称:languagetool,代码行数:25,代码来源:XmlUsageCounter.java
示例14: main
import org.languagetool.Languages; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
if (args.length < 4) {
System.err.println("Usage: " + NeuralNetworkRuleEvaluator.class.getSimpleName()
+ " <langCode> <word2vecDir> <ruleId> <wikipediaXml|tatoebaFile|plainTextFile|dir>...");
System.err.println(" <word2vecDir> is a directory with sub-directories 'en' etc. with dictionary.txt and final_embeddings.txt");
System.err.println(" <ruleId> id of a NeuralNetworkRule or ALL for evaluating all NeuralNetworkRules");
System.err.println(" <wikipediaXml|tatoebaFile|plainTextFile> either a Wikipedia XML dump, or a Tatoeba file, or");
System.err.println(" a plain text file with one sentence per line, a Wikipedia or Tatoeba file");
System.exit(1);
}
long startTime = System.currentTimeMillis();
String langCode = args[0];
File word2vecDir = new File(args[1]);
String ruleId = args[2];
Language lang;
lang = Languages.getLanguageForShortCode(langCode);
List<String> inputsFiles = Arrays.stream(args).skip(3).collect(toList());
NeuralNetworkRuleEvaluator generator = new NeuralNetworkRuleEvaluator(lang, word2vecDir, ruleId);
List<Map<Double, EvalResult>> evaluationResults = generator.runAll(inputsFiles, MAX_SENTENCES, EVAL_MIN_SCORES);
long endTime = System.currentTimeMillis();
System.out.println("\nTime: " + (endTime - startTime) + "ms");
System.out.println("Recommended configuration:");
System.out.println(ConfusionFileIndenter.indent(confusionSetConfig(evaluationResults, RECOMMENDED_MIN_PRECISION)));
}
开发者ID:languagetool-org,项目名称:languagetool,代码行数:26,代码来源:NeuralNetworkRuleEvaluator.java
示例15: main
import org.languagetool.Languages; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
if (args.length < 4) {
System.out.println("Usage: " + AfterTheDeadlineChecker.class.getSimpleName() + " <langCode> <atdUrlPrefix> <file...>");
System.out.println(" <langCode> a language code like 'en' for English");
System.out.println(" <atdUrlPrefix> URL prefix of After the Deadline server, like 'http://localhost:1059/checkDocument?data='");
System.out.println(" <sentenceLimit> Maximum number of sentences to check, or 0 for no limit");
System.out.println(" <file...> Wikipedia and/or Tatoeba file(s)");
System.exit(1);
}
Language language = Languages.getLanguageForShortCode(args[0]);
String urlPrefix = args[1];
int maxSentenceCount = Integer.parseInt(args[2]);
List<String> files = Arrays.asList(args).subList(3, args.length);
AfterTheDeadlineChecker atdChecker = new AfterTheDeadlineChecker(urlPrefix, maxSentenceCount);
atdChecker.run(language, files);
}
开发者ID:languagetool-org,项目名称:languagetool,代码行数:17,代码来源:AfterTheDeadlineChecker.java
示例16: run
import org.languagetool.Languages; //导入依赖的package包/类
private static void run(String textFile, String indexDir, String languageCode) throws IOException {
File file = new File(textFile);
if (!file.exists() || !file.canRead()) {
System.out.println("Text file '" + file.getAbsolutePath()
+ "' does not exist or is not readable, please check the path");
System.exit(1);
}
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
System.out.println("Indexing to directory '" + indexDir + "'...");
try (FSDirectory directory = FSDirectory.open(new File(indexDir).toPath())) {
Language language = Languages.getLanguageForShortCode(languageCode);
try (Indexer indexer = new Indexer(directory, language)) {
indexer.indexText(reader);
}
}
}
System.out.println("Index complete!");
}
开发者ID:languagetool-org,项目名称:languagetool,代码行数:19,代码来源:Indexer.java
示例17: 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
示例18: 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
示例19: testHTTPServer
import org.languagetool.Languages; //导入依赖的package包/类
@Test
@Override
public void testHTTPServer() throws Exception {
File dir = new File(DATA_PATH);
List<Language> languages = new ArrayList<>();
//languages.add(new German());
languages.addAll(Languages.get());
for (Language language : languages) {
File file = new File(dir, "tatoeba-" + language.getShortCode() + ".txt");
if (!file.exists()) {
System.err.println("No data found for " + language + ", language will not be tested");
} else {
String content = StringTools.readerToString(new FileReader(file));
langCodeToText.put(language, content);
System.err.println("Using " + content.length() + " bytes of data for " + language);
}
}
if (langCodeToText.size() == 0) {
throw new RuntimeException("No input data found in " + dir);
}
System.out.println("Testing " + langCodeToText.keySet().size() + " languages and variants");
//super.testHTTPServer(); // start server in this JVM
super.doTest(); // assume server has been started manually in its own JVM
}
开发者ID:languagetool-org,项目名称:languagetool,代码行数:25,代码来源:HTTPServerMultiLangLoadTest.java
示例20: 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
注:本文中的org.languagetool.Languages类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论