本文整理汇总了Java中org.languagetool.Languages.getLanguageForShortCode方法的典型用法代码示例。如果您正苦于以下问题:Java Languages.getLanguageForShortCode方法的具体用法?Java Languages.getLanguageForShortCode怎么用?Java Languages.getLanguageForShortCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.languagetool.Languages
的用法示例。
在下文中一共展示了Languages.getLanguageForShortCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例2: 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);
}
示例3: 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);
}
}
示例4: 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!");
}
示例5: setLanguage
import org.languagetool.Languages; //导入方法依赖的package包/类
private void setLanguage(String shortCode) {
if (Languages.isLanguageSupported(shortCode)) {
language = Languages.getLanguageForShortCode(shortCode);
} else {
System.out.println("ERROR: " + shortCode + " is not a recognized language. Checking disabled.");
language = null;
}
documents.values().forEach(this::publishIssues);
}
示例6: detectLanguage
import org.languagetool.Languages; //导入方法依赖的package包/类
/**
* @return language or {@code null} if language could not be identified
*/
@Nullable
public Language detectLanguage(String text) {
String languageCode = detectLanguageCode(text);
if (languageCode != null) {
return Languages.getLanguageForShortCode(languageCode);
} else {
return null;
}
}
示例7: testEquals
import org.languagetool.Languages; //导入方法依赖的package包/类
@Test
public void testEquals() throws Exception {
PatternRule patternRule1 = new PatternRule("id1", Languages.getLanguageForShortCode("xx"),
Collections.<PatternToken>emptyList(), "desc1", "msg1", "short1");
RuleMatch ruleMatch1 = new RuleMatch(patternRule1, null, 0, 1, "message");
RuleMatch ruleMatch2 = new RuleMatch(patternRule1, null, 0, 1, "message");
assertTrue(ruleMatch1.equals(ruleMatch2));
RuleMatch ruleMatch3 = new RuleMatch(patternRule1, null, 0, 9, "message");
assertFalse(ruleMatch1.equals(ruleMatch3));
assertFalse(ruleMatch2.equals(ruleMatch3));
}
示例8: testRule
import org.languagetool.Languages; //导入方法依赖的package包/类
@Test
@Ignore("only works when OpenNMT server is running")
public void testRule() throws IOException {
OpenNMTRule rule = new OpenNMTRule();
JLanguageTool lt = new JLanguageTool(Languages.getLanguageForShortCode("xx"));
String input = "This were an example.";
RuleMatch[] matches = rule.match(lt.getAnalyzedSentence(input));
// TODO: check result - depends on model...
System.out.println("-->" + Arrays.toString(matches));
}
示例9: main
import org.languagetool.Languages; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
if (args.length < 5 || args.length > 6) {
System.err.println("Usage: " + ConfusionRuleEvaluator.class.getSimpleName()
+ " <token> <homophoneToken> <langCode> <languageModelTopDir> <wikipediaXml|tatoebaFile|plainTextFile|dir>...");
System.err.println(" <languageModelTopDir> is a directory with sub-directories like 'en' which then again contain '1grams',");
System.err.println(" '2grams', and '3grams' sub directories with Lucene indexes");
System.err.println(" See http://wiki.languagetool.org/finding-errors-using-n-gram-data");
System.err.println(" <wikipediaXml|tatoebaFile|plainTextFile|dir> either a Wikipedia XML dump, or a Tatoeba file, or");
System.err.println(" a plain text file with one sentence per line, or a directory with");
System.err.println(" example sentences (where <word>.txt contains only the sentences for <word>).");
System.err.println(" You can specify both a Wikipedia file and a Tatoeba file.");
System.exit(1);
}
long startTime = System.currentTimeMillis();
String token = args[0];
String homophoneToken = args[1];
String langCode = args[2];
Language lang;
if ("en".equals(langCode)) {
lang = new EnglishLight();
} else {
lang = Languages.getLanguageForShortCode(langCode);
}
LanguageModel languageModel = new LuceneLanguageModel(new File(args[3], lang.getShortCode()));
//LanguageModel languageModel = new BerkeleyRawLanguageModel(new File("/media/Data/berkeleylm/google_books_binaries/ger.blm.gz"));
//LanguageModel languageModel = new BerkeleyLanguageModel(new File("/media/Data/berkeleylm/google_books_binaries/ger.blm.gz"));
List<String> inputsFiles = new ArrayList<>();
inputsFiles.add(args[4]);
if (args.length >= 6) {
inputsFiles.add(args[5]);
}
ConfusionRuleEvaluator generator = new ConfusionRuleEvaluator(lang, languageModel, CASE_SENSITIVE);
generator.run(inputsFiles, token, homophoneToken, MAX_SENTENCES, EVAL_FACTORS);
long endTime = System.currentTimeMillis();
System.out.println("\nTime: " + (endTime-startTime)+"ms");
}
示例10: getLanguage
import org.languagetool.Languages; //导入方法依赖的package包/类
private Language getLanguage(Locale locale) {
try {
if (locale.Language.equalsIgnoreCase(LIBREOFFICE_SPECIAL_LANGUAGE_TAG)) {
return Languages.getLanguageForShortCode(locale.Variant);
} else {
return Languages.getLanguageForShortCode(locale.Language + "-" + locale.Country);
}
} catch (java.lang.IllegalArgumentException e) {
return Languages.getLanguageForShortCode(locale.Language);
}
}
示例11: testRule
import org.languagetool.Languages; //导入方法依赖的package包/类
@Test
public void testRule() throws IOException {
Language german = Languages.getLanguageForShortCode("de");
GermanWordRepeatRule rule = new GermanWordRepeatRule(TestTools.getEnglishMessages(), german);
JLanguageTool lt = new JLanguageTool(german);
assertThat(rule.match(lt.getAnalyzedSentence("Das ist gut so.")).length, is(0));
assertThat(rule.match(lt.getAnalyzedSentence("Das ist ist gut so.")).length, is(1));
assertThat(rule.match(lt.getAnalyzedSentence("Der der Mann")).length, is(1));
assertThat(rule.match(lt.getAnalyzedSentence("Warum fragen Sie sie nicht selbst?")).length, is(0));
assertThat(rule.match(lt.getAnalyzedSentence("Er will nur sein Leben leben.")).length, is(0));
assertThat(rule.match(lt.getAnalyzedSentence("Wie bei Honda, die die Bezahlung erhöht haben.")).length, is(0));
assertThat(rule.match(lt.getAnalyzedSentence("Dann warfen sie sie weg.")).length, is(0));
assertThat(rule.match(lt.getAnalyzedSentence("Dann konnte sie sie sehen.")).length, is(0));
}
示例12: test
import org.languagetool.Languages; //导入方法依赖的package包/类
@Test
public void test() throws IOException {
Language german = Languages.getLanguageForShortCode("de");
OldSpellingRule rule = new OldSpellingRule(JLanguageTool.getMessageBundle());
JLanguageTool lt = new JLanguageTool(german);
AnalyzedSentence sentence1 = lt.getAnalyzedSentence("Ein Kuß");
assertThat(rule.match(sentence1).length, is(1));
assertThat(rule.match(sentence1)[0].getSuggestedReplacements().toString(), is("[Kuss]"));
AnalyzedSentence sentence2 = lt.getAnalyzedSentence("Das Corpus delicti");
assertThat(rule.match(sentence2).length, is(1));
assertThat(rule.match(sentence2)[0].getSuggestedReplacements().toString(), is("[Corpus Delicti]"));
// inflected forms should work, too (as long as the inflection database still contains the old variants):
AnalyzedSentence sentence3 = lt.getAnalyzedSentence("In Rußlands Weiten");
assertThat(rule.match(sentence3).length, is(1));
assertThat(rule.match(sentence3)[0].getSuggestedReplacements().toString(), is("[Russlands]"));
AnalyzedSentence sentence4 = lt.getAnalyzedSentence("Hot pants");
assertThat(rule.match(sentence4).length, is(1));
assertThat(rule.match(sentence4)[0].getSuggestedReplacements().toString(), is("[Hotpants]"));
AnalyzedSentence sentence5 = lt.getAnalyzedSentence("Ich muß los");
assertThat(rule.match(sentence5).length, is(1));
assertThat(rule.match(sentence5)[0].getSuggestedReplacements().toString(), is("[muss]"));
assertThat(rule.match(lt.getAnalyzedSentence("In Russland")).length, is(0));
assertThat(rule.match(lt.getAnalyzedSentence("In Russlands Weiten")).length, is(0));
assertThat(rule.match(lt.getAnalyzedSentence("Schlüsse")).length, is(0));
assertThat(rule.match(lt.getAnalyzedSentence("in Schloß Holte")).length, is(0));
assertThat(rule.match(lt.getAnalyzedSentence("Asse")).length, is(0));
}
示例13: run
import org.languagetool.Languages; //导入方法依赖的package包/类
private void run(List<String> lines, File indexDir) throws IOException {
Language language = Languages.getLanguageForShortCode(LANGUAGE);
LanguageModel lm = new LuceneLanguageModel(indexDir);
ConfusionRuleEvaluator evaluator = new ConfusionRuleEvaluator(language, lm, CASE_SENSITIVE);
int lineCount = 0;
for (String line : lines) {
lineCount++;
if (line.contains("#")) {
System.out.println("Ignoring: " + line);
continue;
}
String[] parts = line.split(";\\s*");
if (parts.length != 2) {
throw new IOException("Expected semicolon-separated input: " + line);
}
try {
int i = 1;
for (String part : parts) {
// compare pair-wise - maybe we should compare every item with every other item?
if (i < parts.length) {
runOnPair(evaluator, line, lineCount, lines.size(), removeComment(part), removeComment(parts[i]));
}
i++;
}
} catch (RuntimeException e) {
e.printStackTrace();
}
}
System.out.println("Done. Ignored items because they are already known: " + ignored);
}
示例14: test
import org.languagetool.Languages; //导入方法依赖的package包/类
@Test
public void test() throws SQLException, ClassNotFoundException {
Language language = Languages.getLanguageForShortCode("de");
MatchDatabase database = new MatchDatabase("jdbc:derby:atomFeedChecksDB;create=true", "user", "pass");
database.dropTables();
database.createTables();
assertThat(database.getLatestDate(language), is(new Date(0)));
assertThat(database.list().size(), is(0));
assertThat(database.getCheckDates().size(), is(0));
FakeRule rule1 = new FakeRule(1);
rule1.setCategory(new Category(new CategoryId("TEST_ID"), "My Category"));
RuleMatch ruleMatch = new RuleMatch(rule1, null, 5, 10, "my message");
AtomFeedItem feedItem1 = new AtomFeedItem("//id1?diff=123", "title", "summary1", new Date(10000));
WikipediaRuleMatch wikiRuleMatch1 = new WikipediaRuleMatch(language, ruleMatch, "my context", feedItem1);
database.add(wikiRuleMatch1);
assertThat(database.list().size(), is(1));
assertThat(database.list().get(0).getRuleId(), is("ID_1"));
assertThat(database.list().get(0).getRuleDescription(), is("A fake rule"));
assertThat(database.list().get(0).getRuleMessage(), is("my message"));
assertThat(database.list().get(0).getTitle(), is("title"));
assertThat(database.list().get(0).getErrorContext(), is("my context"));
assertThat(database.list().get(0).getDiffId(), is(123L));
assertThat(database.list().get(0).getFixDiffId(), is(0L));
assertThat(database.list().get(0).getEditDate(), is(new Date(10000)));
assertThat(database.getLatestDate(language), is(new Date(0)));
assertNull(database.list().get(0).getRuleSubId());
assertNull(database.list().get(0).getFixDate());
assertThat(database.getCheckDates().size(), is(0));
RuleMatch ruleMatch2 = new RuleMatch(new FakeRule(1), null, 9, 11, "my message"); // same ID, different character positions
AtomFeedItem feedItem2 = new AtomFeedItem("//id2?diff=124", "title", "summary2", new Date(9000000000L));
WikipediaRuleMatch wikiRuleMatch2 = new WikipediaRuleMatch(language, ruleMatch2, "my context", feedItem2);
int affected = database.markedFixed(wikiRuleMatch2);
assertThat(affected, is(1));
assertThat(database.list().get(0).getFixDate(), is(new Date(9000000000L)));
assertThat(database.list().get(0).getDiffId(), is(123L));
assertThat(database.list().get(0).getFixDiffId(), is(124L));
assertThat(database.getLatestDate(language), is(new Date(0)));
assertThat(database.getCheckDates().size(), is(0));
}
示例15: main
import org.languagetool.Languages; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
if (args.length != 4) {
System.out.println("Usage: " + CommonCrawlToNgram.class + " <langCode> <input.xz> <ngramIndexDir> <simpleEvalFile>");
System.out.println(" <simpleEvalFile> a plain text file with simple error markup");
System.exit(1);
}
Language language = Languages.getLanguageForShortCode(args[0]);
File input = new File(args[1]);
File outputDir = new File(args[2]);
File evalFile = new File(args[3]);
try (CommonCrawlToNgram prg = new CommonCrawlToNgram(language, input, outputDir, evalFile)) {
prg.indexInputFile();
}
}