本文整理汇总了Java中org.languagetool.Language.getShortCode方法的典型用法代码示例。如果您正苦于以下问题:Java Language.getShortCode方法的具体用法?Java Language.getShortCode怎么用?Java Language.getShortCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.languagetool.Language
的用法示例。
在下文中一共展示了Language.getShortCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getXmlStart
import org.languagetool.Language; //导入方法依赖的package包/类
/**
* Get the string to begin the XML. After this, use {@link #ruleMatchesToXmlSnippet} and then {@link #getXmlEnd()}
* or better, simply use {@link #ruleMatchesToXml}.
*/
public String getXmlStart(Language lang, Language motherTongue) {
StringBuilder xml = new StringBuilder(CAPACITY);
xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
.append("<!-- THIS OUTPUT IS DEPRECATED, PLEASE SEE http://wiki.languagetool.org/http-server FOR A BETTER APPROACH -->\n")
.append("<matches software=\"LanguageTool\" version=\"" + JLanguageTool.VERSION + "\"" + " buildDate=\"")
.append(JLanguageTool.BUILD_DATE).append("\">\n");
if (lang != null || motherTongue != null) {
String languageXml = "<language ";
String warning = "";
if (lang != null) {
languageXml += "shortname=\"" + lang.getShortCodeWithCountryAndVariant() + "\" name=\"" + lang.getName() + "\"";
String longCode = lang.getShortCodeWithCountryAndVariant();
if ("en".equals(longCode) || "de".equals(longCode)) {
xml.append("<!-- NOTE: The language code you selected ('").append(longCode).append("') doesn't support spell checking. Consider using a code with a variant like 'en-US'. -->\n");
}
}
if (motherTongue != null && (lang == null || !motherTongue.getShortCode().equals(lang.getShortCodeWithCountryAndVariant()))) {
languageXml += " mothertongueshortname=\"" + motherTongue.getShortCode() + "\" mothertonguename=\"" + motherTongue.getName() + "\"";
}
languageXml += "/>\n";
xml.append(languageXml);
xml.append(warning);
}
return xml.toString();
}
示例2: getLanguageCodes
import org.languagetool.Language; //导入方法依赖的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;
}
示例3: getGrammarFileNames
import org.languagetool.Language; //导入方法依赖的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;
}
示例4: activateLanguageModelRules
import org.languagetool.Language; //导入方法依赖的package包/类
private void activateLanguageModelRules(Language language) {
if (config.getNgramDirectory() != null) {
File ngramLangDir = new File(config.getNgramDirectory(), language.getShortCode());
if (ngramLangDir.exists()) {
try {
languageTool.activateLanguageModelRules(config.getNgramDirectory());
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error while loading ngram database.\n" + e.getMessage());
}
} else {
// user might have set ngram directory to use it for e.g. English, but they
// might not have the data for other languages that supports ngram, so don't
// annoy them with an error dialog:
System.err.println("Not loading ngram data, directory does not exist: " + ngramLangDir);
}
}
}
示例5: testConfusionSetLoading
import org.languagetool.Language; //导入方法依赖的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);
}
示例6: run
import org.languagetool.Language; //导入方法依赖的package包/类
private void run(Language lang) throws IOException {
File basePath = new File("/lt/git/languagetool/languagetool-language-modules");
if (!basePath.exists()) {
throw new RuntimeException("basePath does not exist: " + basePath);
}
String langCode = lang.getShortCode();
File xml = new File(basePath, "/" + langCode + "/src/main/resources/org/languagetool/rules/" + langCode + "/grammar.xml");
List<String> xmlLines = IOUtils.readLines(new FileReader(xml));
JLanguageTool tool = new JLanguageTool(lang);
for (Rule rule : tool.getAllRules()) {
if (!(rule instanceof PatternRule)) {
continue;
}
List<IncorrectExample> incorrectExamples = rule.getIncorrectExamples();
for (IncorrectExample incorrectExample : incorrectExamples) {
checkCorrections(rule, incorrectExample, xmlLines, tool);
}
}
System.err.println("Added corrections: " + addedCorrectionsCount);
for (String xmlLine : xmlLines) {
System.out.println(xmlLine);
}
}
示例7: run
import org.languagetool.Language; //导入方法依赖的package包/类
private void run(Language lang) throws IOException {
File basePath = new File("/lt/git/languagetool/languagetool-language-modules");
if (!basePath.exists()) {
throw new RuntimeException("basePath does not exist: " + basePath);
}
String langCode = lang.getShortCode();
File xml = new File(basePath, "/" + langCode + "/src/main/resources/org/languagetool/rules/" + langCode + "/grammar.xml");
List<String> xmlLines = IOUtils.readLines(new FileReader(xml));
JLanguageTool tool = new JLanguageTool(lang);
for (Rule rule : tool.getAllActiveRules()) {
if (!(rule instanceof PatternRule)) {
continue;
}
List<CorrectExample> correctExamples = rule.getCorrectExamples();
List<IncorrectExample> incorrectExamples = rule.getIncorrectExamples();
for (IncorrectExample incorrectExample : incorrectExamples) {
checkCorrections(rule, correctExamples, incorrectExample, xmlLines);
}
}
System.err.println("Useless examples: " + uselessExampleCount);
System.err.println("Removed lines: " + removedLinesCount);
for (String xmlLine : xmlLines) {
System.out.println(xmlLine);
}
}
示例8: getShortestCorrectDetection
import org.languagetool.Language; //导入方法依赖的package包/类
private int getShortestCorrectDetection(String line, Language expectedLanguage) {
totalInputs++;
String[] tokens = line.split("\\s+");
for (int i = tokens.length; i > 0; i--) {
String text = String.join(" ", Arrays.asList(tokens).subList(0, i));
Language detectedLangObj = languageIdentifier.detectLanguage(text);
String detectedLang = null;
if (detectedLangObj != null) {
detectedLang = detectedLangObj.getShortCode();
}
if (detectedLang == null && i == tokens.length) {
throw new DetectionException("Detection failed for '" + line + "', detected <null>");
} else if (detectedLang != null && !expectedLanguage.getShortCode().equals(detectedLang)) {
if (i == tokens.length) {
throw new DetectionException("Detection failed for '" + line + "', detected " + detectedLang);
} else {
int textLength = getTextLength(tokens, i + 1);
//System.out.println("TEXT : " + line);
//System.out.println("TOO SHORT: " + text + " => " + detectedLang + " (" + textLength + ")");
return textLength;
}
}
}
return tokens[0].length();
}
示例9: XmlRuleDisambiguator
import org.languagetool.Language; //导入方法依赖的package包/类
public XmlRuleDisambiguator(Language language) {
Objects.requireNonNull(language);
String disambiguationFile = language.getShortCode() + "/" + DISAMBIGUATION_FILE;
try {
disambiguationRules = loadPatternRules(disambiguationFile);
} catch (Exception e) {
throw new RuntimeException("Problems with loading disambiguation file: " + disambiguationFile, e);
}
}
示例10: ConfusionProbabilityRule
import org.languagetool.Language; //导入方法依赖的package包/类
public ConfusionProbabilityRule(ResourceBundle messages, LanguageModel languageModel, Language language, int grams) {
super(messages);
setCategory(Categories.TYPOS.getCategory(messages));
setLocQualityIssueType(ITSIssueType.NonConformance);
for (String filename : getFilenames()) {
String path = "/" + language.getShortCode() + "/" + filename;
this.wordToSets.putAll(confSetCache.getUnchecked(path));
}
this.lm = Objects.requireNonNull(languageModel);
this.language = Objects.requireNonNull(language);
if (grams < 1 || grams > 5) {
throw new IllegalArgumentException("grams must be between 1 and 5: " + grams);
}
this.grams = grams;
}
示例11: getBitextRules
import org.languagetool.Language; //导入方法依赖的package包/类
/**
* Gets default bitext rules for a given pair of languages
* @param source Source language.
* @param target Target language.
* @param externalBitextRuleFile external file with bitext rules
* @return List of Bitext rules
* @since 2.9
*/
public static List<BitextRule> getBitextRules(Language source,
Language target, File externalBitextRuleFile) throws IOException, ParserConfigurationException, SAXException {
List<BitextRule> bRules = new ArrayList<>();
//try to load the bitext pattern rules for the language...
BitextPatternRuleLoader ruleLoader = new BitextPatternRuleLoader();
String name = "/" + target.getShortCode() + "/bitext.xml";
if (JLanguageTool.getDataBroker().ruleFileExists(name)) {
InputStream is = JLanguageTool.getDataBroker().getFromRulesDirAsStream(name);
if (is != null) {
bRules.addAll(ruleLoader.getRules(is, name));
}
}
if (externalBitextRuleFile != null) {
bRules.addAll(ruleLoader.getRules(new FileInputStream(externalBitextRuleFile), externalBitextRuleFile.getAbsolutePath()));
}
//load the false friend rules in the bitext mode:
FalseFriendsAsBitextLoader fRuleLoader = new FalseFriendsAsBitextLoader();
String falseFriendsFile = "/false-friends.xml";
List<BitextPatternRule> rules = fRuleLoader.getFalseFriendsAsBitext(falseFriendsFile, source, target);
bRules.addAll(rules);
//load Java bitext rules:
bRules.addAll(getAllBuiltinBitextRules(source, null));
return bRules;
}
示例12: testHTTPServer
import org.languagetool.Language; //导入方法依赖的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));
int fromPos = random.nextInt(content.length());
int toPos = fromPos + random.nextInt(MAX_TEXT_LENGTH) + MIN_TEXT_LENGTH;
String textSubstring = content.substring(fromPos, Math.min(toPos, content.length()));
langCodeToText.put(language, textSubstring);
String response = checkByPOST(language, textSubstring);
textToResult.put(language, response);
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
}
示例13: testExportPosDictAndCreateSynth
import org.languagetool.Language; //导入方法依赖的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("");
}
}
示例14: activateWord2VecModelRules
import org.languagetool.Language; //导入方法依赖的package包/类
private void activateWord2VecModelRules(Language language) {
if (config.getWord2VecDirectory() != null) {
File word2vecDir = new File(config.getWord2VecDirectory(), language.getShortCode());
if (word2vecDir.exists()) {
try {
languageTool.activateWord2VecModelRules(config.getWord2VecDirectory());
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error while loading word2vec model.\n" + e.getMessage());
}
} else {
System.err.println("Not loading word2vec data, directory does not exist: " + word2vecDir);
}
}
}
示例15: run
import org.languagetool.Language; //导入方法依赖的package包/类
private void run(Language lang) throws IOException {
File basePath = new File("/lt/git/languagetool/languagetool-language-modules");
if (!basePath.exists()) {
throw new RuntimeException("basePath does not exist: " + basePath);
}
String langCode = lang.getShortCode();
File xml = new File(basePath, "/" + langCode + "/src/main/resources/org/languagetool/rules/" + langCode + "/grammar.xml");
List<String> xmlLines = IOUtils.readLines(new FileReader(xml));
JLanguageTool tool = new JLanguageTool(lang);
int totalRules = 0;
for (Rule rule : tool.getAllActiveRules()) {
if (!(rule instanceof PatternRule)) {
continue;
}
PatternRule patternRule = (PatternRule) rule;
String id = patternRule.getFullId();
if (isSimple((PatternRule)rule)) {
System.err.println("Simplifying: " + id);
simplify(patternRule, xmlLines);
} else {
System.err.println("Can't simplify: " + id);
}
totalRules++;
}
System.err.println("touchedRulesCount: " + touchedRulesCount + " out of " + totalRules);
for (String xmlLine : xmlLines) {
System.out.println(xmlLine);
}
}