本文整理汇总了Java中org.languagetool.JLanguageTool.check方法的典型用法代码示例。如果您正苦于以下问题:Java JLanguageTool.check方法的具体用法?Java JLanguageTool.check怎么用?Java JLanguageTool.check使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.languagetool.JLanguageTool
的用法示例。
在下文中一共展示了JLanguageTool.check方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.languagetool.JLanguageTool; //导入方法依赖的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.");
}
示例2: checkFile
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void checkFile(File file, JLanguageTool lt) throws IOException {
try (
FileInputStream fis = new FileInputStream(file);
InputStreamReader reader = new InputStreamReader(fis, "utf-8");
BufferedReader br = new BufferedReader(reader)
) {
String line;
while ((line = br.readLine()) != null) {
List<RuleMatch> matches = lt.check(line);
for (RuleMatch match : matches) {
String covered = line.substring(match.getFromPos(), match.getToPos());
List<String> suggestions = match.getSuggestedReplacements();
List<String> limitedSuggestions = suggestions.subList(0, Math.min(MAX_SUGGESTIONS, suggestions.size()));
System.out.println(covered + ": " + limitedSuggestions);
}
}
}
}
示例3: warmUp
import org.languagetool.JLanguageTool; //导入方法依赖的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");
}
示例4: main
import org.languagetool.JLanguageTool; //导入方法依赖的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);
}
}
}
示例5: testIgnoreSuggestionsWithMorfologik
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
@Test
public void testIgnoreSuggestionsWithMorfologik() throws IOException {
JLanguageTool lt = new JLanguageTool(new AmericanEnglish());
assertThat(lt.check("This is anArtificialTestWordForLanguageTool.").size(), is(0)); // no error, as this word is in ignore.txt
assertThat(lt.check("How an ab initio calculation works.").size(), is(0)); // As a multi-word entry in spelling.txt "ab initio" must be accepted
assertThat(lt.check("Test adjoint").size(), is(0)); // in spelling.txt
assertThat(lt.check("Test Adjoint").size(), is(0)); // in spelling.txt (lowercase)
List<RuleMatch> matches2 = lt.check("This is a real typoh.");
assertThat(matches2.size(), is(1));
assertThat(matches2.get(0).getRule().getId(), is("MORFOLOGIK_RULE_EN_US"));
List<RuleMatch> matches3 = lt.check("This is anotherArtificialTestWordForLanguageTol."); // note the typo
assertThat(matches3.size(), is(1));
assertThat(matches3.get(0).getSuggestedReplacements().toString(), is("[anotherArtificialTestWordForLanguageTool]"));
}
示例6: checkCorrections
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void checkCorrections(Rule rule, IncorrectExample incorrectExample, List<String> xmlLines, JLanguageTool tool) throws IOException {
List<String> corrections = incorrectExample.getCorrections();
if (corrections.isEmpty()) {
for (Rule r : tool.getAllActiveRules()) {
tool.disableRule(r.getId());
}
tool.enableRule(rule.getId());
String incorrectSentence = incorrectExample.getExample().replaceAll("</?marker>", "");
List<RuleMatch> matches = tool.check(incorrectSentence);
System.err.println("no corrections: " + rule.getId() + ", " + matches.size() + " matches");
if (matches.size() == 0) {
throw new RuntimeException("Got no rule match: " + incorrectSentence);
}
List<String> suggestedReplacements = matches.get(0).getSuggestedReplacements();
String newAttribute = "correction=\"" + String.join("|", suggestedReplacements) + "\"";
addAttribute(rule, newAttribute, xmlLines);
}
}
示例7: run
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void run(Language language, File file) throws IOException {
JLanguageTool lt = new JLanguageTool(language);
try (Scanner scanner = new Scanner(file)) {
int count = 0;
long startTime = System.currentTimeMillis();
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
lt.check(line);
if (++count % BATCH_SIZE == 0) {
long time = System.currentTimeMillis() - startTime;
System.out.println(count + ". " + time + "ms per " + BATCH_SIZE + " sentences");
startTime = System.currentTimeMillis();
}
}
}
}
示例8: checkNodeSpelling
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void checkNodeSpelling(SensorContext sensorContext,
InputFile inputFile,
JLanguageTool langTool,
Node node,
String nodeText) throws IOException {
List<RuleMatch> matches = langTool.check(nodeText);
for (RuleMatch match : matches) {
createSpellCheckIssueObject(sensorContext, inputFile, node, match);
}
}
示例9: check
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
@Override
public void check(IDocument document, IRegion[] regions, SpellingContext context,
ISpellingProblemCollector collector, IProgressMonitor monitor) {
JLanguageTool.setDataBroker(new EclipseRessourceDataBroker());
JLanguageTool langTool = new JLanguageTool(new AmericanEnglish());
if (langTool.getLanguage() == null) {
return;
}
for (IRegion region : regions) {
AnnotatedTextBuilder textBuilder = new AnnotatedTextBuilder();
List<RuleMatch> matches;
try {
MarkupUtil.populateBuilder(textBuilder, document.get(region.getOffset(), region.getLength()));
matches = langTool.check(textBuilder.build());
processMatches(collector, matches);
} catch (IOException | BadLocationException e) {
e.printStackTrace();
}
}
}
示例10: checkText
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private int checkText(final JLanguageTool langTool, final String text,
final StringBuilder sb) throws IOException {
final long startTime = System.currentTimeMillis();
final List<RuleMatch> ruleMatches = langTool.check(text);
final long startTimeMatching = System.currentTimeMillis();
int i = 0;
for (final RuleMatch match : ruleMatches) {
final String output = Tools.makeTexti18n(
messages,
"result1",
new Object[] { i + 1, match.getLine() + 1,
match.getColumn() });
sb.append(output);
String msg = match.getMessage();
msg = msg.replaceAll("<suggestion>", "<b>");
msg = msg.replaceAll("</suggestion>", "</b>");
msg = msg.replaceAll("<old>", "<b>");
msg = msg.replaceAll("</old>", "</b>");
sb.append("<b>" + messages.getString("errorMessage") + "</b> "
+ msg + "<br>\n");
if (match.getSuggestedReplacements().size() > 0) {
final String repl = StringTools.listToString(
match.getSuggestedReplacements(), "; ");
sb.append("<b>" + messages.getString("correctionMessage")
+ "</b> " + repl + "<br>\n");
}
final String context = Tools.getContext(match.getFromPos(),
match.getToPos(), text);
sb.append("<b>" + messages.getString("errorContext") + "</b> "
+ context);
sb.append("<br>\n");
i++;
}
final long endTime = System.currentTimeMillis();
sb.append(HTML_GREY_FONT_START);
sb.append(Tools.makeTexti18n(messages, "resultTime", new Object[] {
endTime - startTime, endTime - startTimeMatching }));
sb.append(HTML_FONT_END);
return ruleMatches.size();
}
示例11: initExpectedResults
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void initExpectedResults(List<Language> languages) throws IOException {
for (Language lang : languages) {
JLanguageTool lt = new JLanguageTool(lang);
String input = examples.get(lang.getShortCodeWithCountryAndVariant());
if (input != null) {
List<RuleMatch> matches = lt.check(input);
expectedResults.put(lang.getShortCodeWithCountryAndVariant(), toString(matches));
}
}
}
示例12: initExpectedResults
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void initExpectedResults() throws IOException {
JLanguageTool lt = new JLanguageTool(LANG);
for (String sentence : sentences) {
List<RuleMatch> matches = lt.check(sentence);
expectedResults.put(sentence, matches.toString());
}
}
示例13: run
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
@Override
public void run() {
try {
JLanguageTool lt = new JLanguageTool(lang);
List<RuleMatch> matches = lt.check(sentence);
//System.out.println("=>" + matches);
String expected = expectedResults.get(sentence);
String real = matches.toString();
if (!expectedResults.get(sentence).equals(real)) {
fail("Got '" + real + "', expected '" + expected + "' for input: " + sentence);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例14: getBaselineTime
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private static long getBaselineTime(JLanguageTool langTool, String text) throws IOException {
deactivateAllRules(langTool);
long baselineStartTime = System.currentTimeMillis();
langTool.check(text);
long baselineTime = System.currentTimeMillis() - baselineStartTime;
if (langTool.getAllActiveRules().size() > 0) {
throw new RuntimeException("Did not expect to get any pattern rules: " + langTool.getAllActiveRules().size());
}
for (Rule rule : langTool.getAllRules()) {
langTool.enableRule(rule.getId());
}
return baselineTime;
}
示例15: assertSuggestions
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void assertSuggestions(int suggestionCount, String text, JLanguageTool langTool) throws IOException {
List<RuleMatch> matches = langTool.check(text);
int suggestionsFound = 0;
for (RuleMatch match : matches) {
int pos = 0;
while (pos != -1) {
pos = match.getMessage().indexOf("<suggestion>", pos + 1);
suggestionsFound ++;
}
}
if (suggestionsFound > 0) {
suggestionsFound--;
}
assertEquals(suggestionCount, suggestionsFound);
}