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


Java Language类代码示例

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


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

示例1: main

import org.languagetool.Language; //导入依赖的package包/类
public static void main(String[] args) {
	System.out.println("start...");
	try {
		JLanguageTool langTool = new JLanguageTool(Language.ENGLISH);
		langTool.activateDefaultPatternRules();
		List<RuleMatch> matches = langTool.check("A sentence "
				+ "with a error in the Hitchhiker's Guide tot he Galaxy");
		for (RuleMatch match : matches) {
			System.out.println("Potential error at line "
					+ match.getEndLine() + ", column " + match.getColumn()
					+ ": " + match.getMessage());
			System.out.println("Suggested correction: "
					+ match.getSuggestedReplacements());
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	System.out.println("finished.");
}
 
开发者ID:kennanmeyer,项目名称:SE-410-Project,代码行数:20,代码来源:TestLangTool.java

示例2: getCurrentLanguage

import org.languagetool.Language; //导入依赖的package包/类
private Language getCurrentLanguage() {
	if (autoDetectBox.isSelected()) {
		final LanguageIdentifier langIdentifier = new LanguageIdentifier(
				textArea.getText());
		Language lang = Language.getLanguageForShortName(langIdentifier
				.getLanguage());
		if (lang == null) {
			lang = Language.ENGLISH;
		}
		for (int i = 0; i < languageBox.getItemCount(); i++) {
			final I18nLanguage boxLanguage = (I18nLanguage) languageBox
					.getItemAt(i);
			if (boxLanguage.toString().equals(
					lang.getTranslatedName(messages))) {
				languageBox.setSelectedIndex(i);
			}
		}
		return lang;
	} else {
		return ((I18nLanguage) languageBox.getSelectedItem()).getLanguage();
	}
}
 
开发者ID:markkohdev,项目名称:oStorybook,代码行数:23,代码来源:LangToolMain.java

示例3: getCurrentConfigDialog

import org.languagetool.Language; //导入依赖的package包/类
private ConfigurationDialog getCurrentConfigDialog() {
	final Language language = getCurrentLanguage();
	final ConfigurationDialog configDialog;
	if (configDialogs.containsKey(language)) {
		configDialog = configDialogs.get(language);
	} else {
		configDialog = new ConfigurationDialog(frame, false);
		configDialog.setMotherTongue(config.getMotherTongue());
		configDialog.setDisabledRules(config.getDisabledRuleIds());
		configDialog.setEnabledRules(config.getEnabledRuleIds());
		configDialog.setDisabledCategories(config
				.getDisabledCategoryNames());
		configDialog.setRunServer(config.getRunServer());
		configDialog.setServerPort(config.getServerPort());
		configDialogs.put(language, configDialog);
	}
	return configDialog;
}
 
开发者ID:markkohdev,项目名称:oStorybook,代码行数:19,代码来源:LangToolMain.java

示例4: getMaintainerInfo

import org.languagetool.Language; //导入依赖的package包/类
private String getMaintainerInfo(Language lang) {
  final StringBuilder maintainerInfo = new StringBuilder();
  if (lang.getMaintainers() != null) {
    for (Contributor contributor : lang.getMaintainers()) {
      if (!StringTools.isEmpty(maintainerInfo.toString())) {
        maintainerInfo.append(", ");
      }
      if (contributor.getUrl() != null) {
        maintainerInfo.append("<a href=\"");
        maintainerInfo.append(contributor.getUrl());
        maintainerInfo.append("\">");
      }
      maintainerInfo.append(contributor.getName());
      if (contributor.getUrl() != null) {
        maintainerInfo.append("</a>");
      }
    }
  }
  return maintainerInfo.toString();
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:21,代码来源:RuleOverview.java

示例5: DisambiguationPatternRule

import org.languagetool.Language; //导入依赖的package包/类
/**
 * @param id Id of the Rule
 * @param language Language of the Rule
 * @param description Description to be shown (name)
 * @param disambAction the action to be executed on found token(s)
 * @since public since 2.5
 */
public DisambiguationPatternRule(String id, String description,
                                 Language language, List<PatternToken> patternTokens,
                                 String disambiguatedPOS, Match posSelect,
                                 DisambiguatorAction disambAction) {
  super(id, description, language, patternTokens, true);
  if (disambiguatedPOS == null && posSelect == null
      && disambAction != DisambiguatorAction.UNIFY
      && disambAction != DisambiguatorAction.ADD
      && disambAction != DisambiguatorAction.REMOVE
      && disambAction != DisambiguatorAction.IMMUNIZE
      && disambAction != DisambiguatorAction.REPLACE
      && disambAction != DisambiguatorAction.FILTERALL
      && disambAction != DisambiguatorAction.IGNORE_SPELLING) {
    throw new NullPointerException("disambiguated POS cannot be null with posSelect == null and " + disambAction);
  }
  this.disambiguatedPOS = disambiguatedPOS;
  this.matchElement = posSelect;
  this.disAction = Objects.requireNonNull(disambAction);
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:27,代码来源:DisambiguationPatternRule.java

示例6: main

import org.languagetool.Language; //导入依赖的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

示例7: combineLists

import org.languagetool.Language; //导入依赖的package包/类
/**
 * Creates a Cartesian product of the arrays stored in the input array.
 * @param input Array of string arrays to combine.
 * @param output Work array of strings.
 * @param r Starting parameter (use 0 to get all combinations).
 * @param lang Text language for adding spaces in some languages.
 * @return Combined array of String.
 */
private static String[] combineLists(String[][] input,
    String[] output, int r, Language lang) {
  List<String> outputList = new ArrayList<>();
  if (r == input.length) {
    StringBuilder sb = new StringBuilder();
    for (int k = 0; k < output.length; k++) {
      sb.append(output[k]);
      if (k < output.length - 1) {
        sb.append(StringTools.addSpace(output[k + 1], lang));
      }
    }
    outputList.add(sb.toString());
  } else {
    for (int c = 0; c < input[r].length; c++) {
      output[r] = input[r][c];
      String[] sList = combineLists(input, output, r + 1, lang);
      outputList.addAll(Arrays.asList(sList));
    }
  }
  return outputList.toArray(new String[outputList.size()]);
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:30,代码来源:PatternRuleMatcher.java

示例8: getRules

import org.languagetool.Language; //导入依赖的package包/类
public final List<AbstractPatternRule> getRules(InputStream stream,
    Language textLanguage, Language motherTongue)
    throws ParserConfigurationException, SAXException, IOException {
  FalseFriendRuleHandler handler = new FalseFriendRuleHandler(
      textLanguage, motherTongue);
  SAXParserFactory factory = SAXParserFactory.newInstance();
  SAXParser saxParser = factory.newSAXParser();
  saxParser.getXMLReader().setFeature(
          "http://apache.org/xml/features/nonvalidating/load-external-dtd",
          false);
  saxParser.parse(stream, handler);
  List<AbstractPatternRule> rules = handler.getRules();
  // Add suggestions to each rule:
  ResourceBundle messages = ResourceBundle.getBundle(
          JLanguageTool.MESSAGE_BUNDLE, motherTongue.getLocale());
  MessageFormat msgFormat = new MessageFormat(messages.getString("false_friend_suggestion"));
  for (AbstractPatternRule rule : rules) {
    List<String> suggestions = handler.getSuggestionMap().get(rule.getId());
    if (suggestions != null) {
      String[] msg = { formatSuggestions(suggestions) };
      rule.setMessage(rule.getMessage() + " " + msgFormat.format(msg));
    }
  }
  return rules;
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:26,代码来源:FalseFriendRuleLoader.java

示例9: 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));
      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

示例10: checkByPOST

import org.languagetool.Language; //导入依赖的package包/类
/**
 * Same as {@link #checkV1(Language, String)} but using HTTP POST method instead of GET
 */
String checkByPOST(Language lang, String text) throws IOException {
  String postData = "language=" + lang.getShortCodeWithCountryAndVariant() + "&text=" + URLEncoder.encode(text, "UTF-8"); // latin1 is not enough for languages like Polish, Romanian, etc
  URL url = new URL(LOAD_TEST_URL.replace("<PORT>", String.valueOf(HTTPTools.getDefaultPort())));
  try {
    return HTTPTools.checkAtUrlByPost(url, postData);
  } catch (IOException e) {
    if (text.length() > MAX_LENGTH) {
      // this is expected, log it anyway:
      System.err.println("Got expected error on long text (" + text.length() + " chars): " + e.getMessage());
      return "";
    } else {
      System.err.println("Got error from " + url + " (" + lang.getShortCodeWithCountryAndVariant() + ", " +
                         text.length() + " chars): " + e.getMessage() + ", text was (" + text.length() +  " chars): '" + StringUtils.abbreviate(text, 100) + "'");
      return "";
    }
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:21,代码来源:HTTPServerTest.java

示例11: main

import org.languagetool.Language; //导入依赖的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

示例12: run

import org.languagetool.Language; //导入依赖的package包/类
private void run(Language lang) throws IOException {
  File basePath = new File("/home/dnaber/lt/git/languagetool/languagetool-language-modules");
  if (!basePath.exists()) {
    throw new RuntimeException("basePath does not exist: " + basePath);
  }
  JLanguageTool tool = new JLanguageTool(lang);
  System.out.println("<html>");
  System.out.println("<head>");
  System.out.println("  <title>LanguageTool examples sentences</title>");
  System.out.println("  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
  System.out.println("</head>");
  System.out.println("<body>");
  int i = 1;
  for (Rule rule : tool.getAllActiveRules()) {
    List<IncorrectExample> incorrectExamples = rule.getIncorrectExamples();
    if (incorrectExamples.size() > 0) {
      String example = incorrectExamples.get(0).getExample()
              .replace("<marker>", "<b>")
              .replace("</marker>", "</b>");
      System.out.println(i + ". " + example + " [" + rule.getId() + "]<br>");
      i++;
    }
  }
  System.out.println("</body>");
  System.out.println("</html>");
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:27,代码来源:ExampleSentencePrinter.java

示例13: testPerformance

import org.languagetool.Language; //导入依赖的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

示例14: create

import org.languagetool.Language; //导入依赖的package包/类
public static MixingSentenceSource create(List<String> dumpFileNames, Language language, Pattern filter) throws IOException {
  List<SentenceSource> sources = new ArrayList<>();
  for (String dumpFileName : dumpFileNames) {
    File file = new File(dumpFileName);
    if (file.getName().endsWith(".xml")) {
      sources.add(new WikipediaSentenceSource(new FileInputStream(dumpFileName), language, filter));
    } else if (file.getName().startsWith("tatoeba-")) {
      sources.add(new TatoebaSentenceSource(new FileInputStream(dumpFileName), language, filter));
    } else if (file.getName().endsWith(".txt")) {
      sources.add(new PlainTextSentenceSource(new FileInputStream(dumpFileName), language, filter));
    } else if (file.getName().endsWith(".xz")) {
      sources.add(new CommonCrawlSentenceSource(new FileInputStream(dumpFileName), language, filter));
    } else {
      throw new RuntimeException("Could not find a source handler for " + dumpFileName +
              " - Wikipedia files must be named '*.xml', Tatoeba files must be named 'tatoeba-*', CommonCrawl files '*.xz', plain text files '*.txt'");
    }
  }
  return new MixingSentenceSource(sources, language);
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:20,代码来源:MixingSentenceSource.java

示例15: disambiguateUntil

import org.languagetool.Language; //导入依赖的package包/类
private AnalyzedSentence disambiguateUntil(
    Language lang, List<DisambiguationPatternRule> rules, String ruleID,
    AnalyzedSentence sentence) throws IOException {

  AnalyzedSentence disambiguated = sentence;
  
  disambiguated = lang.getDisambiguator().preDisambiguate(disambiguated);

  for (DisambiguationPatternRule rule : rules) {
    if (ruleID.equals(rule.getId())) {
      break;
    }
    disambiguated = rule.replace(disambiguated);
  }
  return disambiguated;
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:17,代码来源:DisambiguationRuleTest.java


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