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


Java RuleMatch.getRule方法代码示例

本文整理汇总了Java中org.languagetool.rules.RuleMatch.getRule方法的典型用法代码示例。如果您正苦于以下问题:Java RuleMatch.getRule方法的具体用法?Java RuleMatch.getRule怎么用?Java RuleMatch.getRule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.languagetool.rules.RuleMatch的用法示例。


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

示例1: writeRule

import org.languagetool.rules.RuleMatch; //导入方法依赖的package包/类
private void writeRule(JsonGenerator g, RuleMatch match) throws IOException {
  g.writeObjectFieldStart("rule");
  g.writeStringField("id", match.getRule().getId());
  if (match.getRule() instanceof AbstractPatternRule) {
    AbstractPatternRule pRule = (AbstractPatternRule) match.getRule();
    if (pRule.getSubId() != null) {
      g.writeStringField("subId", pRule.getSubId());
    }
  }
  g.writeStringField("description", match.getRule().getDescription());
  g.writeStringField("issueType", match.getRule().getLocQualityIssueType().toString());
  if (match.getUrl() != null || match.getRule().getUrl() != null) {
    g.writeArrayFieldStart("urls");  // currently only one, but keep it extensible
    g.writeStartObject();
    if (match.getUrl() != null) {
      g.writeStringField("value", match.getUrl().toString());
    } else {
      g.writeStringField("value", match.getRule().getUrl().toString());
    }
    g.writeEndObject();
    g.writeEndArray();
  }
  writeCategory(g, match.getRule().getCategory());
  g.writeEndObject();
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:26,代码来源:RuleMatchesAsJsonSerializer.java

示例2: acceptRuleMatch

import org.languagetool.rules.RuleMatch; //导入方法依赖的package包/类
@Nullable
@Override
public RuleMatch acceptRuleMatch(RuleMatch match, Map<String, String> arguments, AnalyzedTokenReadings[] patternTokens) {
  try {
    String decade = arguments.get("lata").substring(2);
    String century = arguments.get("lata").substring(0, 2);
    int cent = Integer.parseInt(century);
    String message = match.getMessage()
        .replace("{dekada}", decade)
        .replace("{wiek}", getRomanNumber(cent + 1));
    return new RuleMatch(match.getRule(), match.getSentence(), match.getFromPos(), match.getToPos(), message, match.getShortMessage(),
        match.getFromPos() == 0, null);
  } catch (IllegalArgumentException ignore) {
    // ignore it silently
    return null;
  }

}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:19,代码来源:DecadeSpellingFilter.java

示例3: printMatches

import org.languagetool.rules.RuleMatch; //导入方法依赖的package包/类
/**
 * Displays matches in a simple text format.
 * @param ruleMatches Matches from rules.
 * @param prevMatches Number of previously found matches.
 * @param contents  The text that was checked.
 * @param contextSize The size of contents displayed.
 * @since 1.0.1
 */
private static void printMatches(List<RuleMatch> ruleMatches,
                                 int prevMatches, String contents, int contextSize) {
  int i = 1;
  ContextTools contextTools = new ContextTools();
  contextTools.setContextSize(contextSize);
  for (RuleMatch match : ruleMatches) {
    Rule rule = match.getRule();
    String output = i + prevMatches + ".) Line " + (match.getLine() + 1) + ", column "
            + match.getColumn() + ", Rule ID: " + rule.getId();
    if (rule instanceof AbstractPatternRule) {
      AbstractPatternRule pRule = (AbstractPatternRule) rule;
      if (pRule.getSubId() != null) {
        output += "[" + pRule.getSubId() + "]";
      }
    }
    System.out.println(output);
    String msg = match.getMessage();
    msg = msg.replaceAll("</?suggestion>", "'");
    System.out.println("Message: " + msg);
    List<String> replacements = match.getSuggestedReplacements();
    if (!replacements.isEmpty()) {
      System.out.println("Suggestion: " + String.join("; ", replacements));
    }
    System.out.println(contextTools.getPlainTextContext(match.getFromPos(), match.getToPos(), contents));
    if (rule.getUrl() != null) {
      System.out.println("More info: " + rule.getUrl());
    }
    if (i < ruleMatches.size()) {
      System.out.println();
    }
    i++;
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:42,代码来源:CommandLineTools.java

示例4: handleResult

import org.languagetool.rules.RuleMatch; //导入方法依赖的package包/类
@Override
protected void handleResult(Sentence sentence, List<RuleMatch> ruleMatches, Language language) {
  if (ruleMatches.size() > 0) {
    int i = 1;
    System.out.println("\nTitle: " + sentence.getTitle());
    for (RuleMatch match : ruleMatches) {
      String output = i + ".) Line " + (match.getLine() + 1) + ", column "
              + match.getColumn() + ", Rule ID: " + match.getRule().getId();
      if (match.getRule() instanceof AbstractPatternRule) {
        AbstractPatternRule pRule = (AbstractPatternRule) match.getRule();
        output += "[" + pRule.getSubId() + "]";
      }
      System.out.println(output);
      String msg = match.getMessage();
      msg = msg.replaceAll("<suggestion>", "'");
      msg = msg.replaceAll("</suggestion>", "'");
      System.out.println("Message: " + msg);
      List<String> replacements = match.getSuggestedReplacements();
      if (!replacements.isEmpty()) {
        System.out.println("Suggestion: " + String.join("; ", replacements));
      }
      System.out.println(contextTools.getPlainTextContext(match.getFromPos(), match.getToPos(), sentence.getText()));
      i++;
      checkMaxErrors(++errorCount);
    }
  }
  checkMaxSentences(++sentenceCount);
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:29,代码来源:StdoutHandler.java

示例5: handleResult

import org.languagetool.rules.RuleMatch; //导入方法依赖的package包/类
@Override
protected void handleResult(Sentence sentence, List<RuleMatch> ruleMatches, Language language) {
  if (ruleMatches.size() > 0) {
    for (RuleMatch match : ruleMatches) {
      String ruleId = match.getRule().getId();
      if (match.getRule() instanceof AbstractPatternRule) {
        AbstractPatternRule pRule = (AbstractPatternRule) match.getRule();
        ruleId = pRule.getFullId();
      }
      System.out.println(ruleId + ": " + contextTools.getContext(match.getFromPos(), match.getToPos(), sentence.getText()));
      checkMaxErrors(++errorCount);
    }
  }
  checkMaxSentences(++sentenceCount);
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:16,代码来源:CompactStdoutHandler.java

示例6: WikipediaRuleMatch

import org.languagetool.rules.RuleMatch; //导入方法依赖的package包/类
WikipediaRuleMatch(Language language, RuleMatch match, String errorContext, AtomFeedItem feedItem) {
  super(match.getRule(), match.getSentence(), match.getFromPos(), match.getToPos(), match.getMessage());
  this.language = Objects.requireNonNull(language);
  this.errorContext = Objects.requireNonNull(errorContext);
  this.title = Objects.requireNonNull(feedItem.getTitle());
  this.editDate = Objects.requireNonNull(feedItem.getDate());
  this.diffId = feedItem.getDiffId();
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:9,代码来源:WikipediaRuleMatch.java

示例7: main

import org.languagetool.rules.RuleMatch; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, PageNotFoundException {
  if (args.length != 1) {
    System.out.println("Usage: " + WikipediaQuickCheck.class.getName() + " <url>");
    System.exit(1);
  }
  WikipediaQuickCheck check = new WikipediaQuickCheck();
  // URL examples:
  //String urlString = "http://de.wikipedia.org/wiki/Angela_Merkel";
  //String urlString = "https://de.wikipedia.org/wiki/Benutzer_Diskussion:Dnaber";
  //String urlString = "https://secure.wikimedia.org/wikipedia/de/wiki/Gütersloh";
  String urlString = args[0];
  MarkupAwareWikipediaResult result = check.checkPage(new URL(urlString), new ErrorMarker("***", "***"));
  int errorCount = 0;
  for (AppliedRuleMatch match : result.getAppliedRuleMatches()) {
    RuleMatchApplication matchApplication = match.getRuleMatchApplications().get(0);
    RuleMatch ruleMatch = match.getRuleMatch();
    Rule rule = ruleMatch.getRule();
    System.out.println("");
    String message = ruleMatch.getMessage().replace("<suggestion>", "'").replace("</suggestion>", "'");
    errorCount++;
    System.out.print(errorCount + ". " + message);
    if (rule instanceof AbstractPatternRule) {
      System.out.println(" (" + ((AbstractPatternRule) rule).getFullId() + ")");
    } else {
      System.out.println(" (" + rule.getId() + ")");
    }
    System.out.println("    ..." + matchApplication.getOriginalErrorContext(50).replace("\n", "\\n") + "...");
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:30,代码来源:WikipediaQuickCheck.java

示例8: getRuleMatchIds

import org.languagetool.rules.RuleMatch; //导入方法依赖的package包/类
private List<String> getRuleMatchIds(List<RuleMatch> ruleMatches) {
  List<String> ids = new ArrayList<>();
  for (RuleMatch ruleMatch : ruleMatches) {
    if (ruleMatch.getRule() instanceof PatternRule) {
      PatternRule patternRule = (PatternRule) ruleMatch.getRule();
      ids.add(patternRule.getFullId());
    }
  }
  return ids;
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:11,代码来源:IndexerSearcherTest.java

示例9: ruleMatchesToXmlSnippet

import org.languagetool.rules.RuleMatch; //导入方法依赖的package包/类
/**
 * Get the XML snippet (i.e. not a complete XML document) for the given rules.
 * @see #getXmlStart
 * @see #getXmlEnd()
 */
public String ruleMatchesToXmlSnippet(List<RuleMatch> ruleMatches, String text, int contextSize) {
  StringBuilder xml = new StringBuilder(CAPACITY);
  //
  // IMPORTANT: people rely on this format, don't change it!
  //
  ContextTools contextTools = new ContextTools();
  contextTools.setEscapeHtml(false);
  contextTools.setContextSize(contextSize);
  String startMarker = "__languagetool_start_marker";
  contextTools.setErrorMarkerStart(startMarker);
  contextTools.setErrorMarkerEnd("");

  for (RuleMatch match : ruleMatches) {
    String subId = "";
    if (match.getRule() instanceof AbstractPatternRule) {
      AbstractPatternRule pRule = (AbstractPatternRule) match.getRule();
      if (pRule.getSubId() != null) {
        subId = " subId=\"" + escapeXMLForAPIOutput(pRule.getSubId()) + "\" ";
      }
    }
    xml.append("<error fromy=\"").append(match.getLine()).append('"')
            .append(" fromx=\"").append(match.getColumn() - 1).append('"')
            .append(" toy=\"").append(match.getEndLine()).append('"')
            .append(" tox=\"").append(match.getEndColumn() - 1).append('"')
            .append(" ruleId=\"").append(match.getRule().getId()).append('"');
    xml.append(subId);
    String msg = match.getMessage().replaceAll("</?suggestion>", "'");
    xml.append(" msg=\"").append(escapeXMLForAPIOutput(msg)).append('"');
    if (!match.getShortMessage().isEmpty()) {
      xml.append(" shortmsg=\"").append(escapeXMLForAPIOutput(match.getShortMessage())).append('"');
    }
    xml.append(" replacements=\"").append(escapeXMLForAPIOutput(
            String.join("#", match.getSuggestedReplacements()))).append('"');
    String context = contextTools.getContext(match.getFromPos(), match.getToPos(), text);
    // get position of error in context and remove artificial marker again:
    int contextOffset = context.indexOf(startMarker);
    context = context.replaceFirst(startMarker, "");
    context = context.replaceAll("[\n\r]", " ");
    xml.append(" context=\"").append(escapeForXmlAttribute(context)).append('"')
            .append(" contextoffset=\"").append(contextOffset).append('"')
            .append(" offset=\"").append(match.getFromPos()).append('"')
            .append(" errorlength=\"").append(match.getToPos() - match.getFromPos()).append('"');
    if (match.getRule().getUrl() != null) {
      xml.append(" url=\"").append(escapeXMLForAPIOutput(match.getRule().getUrl().toString())).append('"');
    }
    Category category = match.getRule().getCategory();
    if (category != null) {
      xml.append(" category=\"").append(escapeXMLForAPIOutput(category.getName())).append('"');
      CategoryId id = category.getId();
      if (id != null) {
        xml.append(" categoryid=\"").append(escapeXMLForAPIOutput(id.toString())).append('"');
      }
    }
    ITSIssueType type = match.getRule().getLocQualityIssueType();
    if (type != null) {
      xml.append(" locqualityissuetype=\"").append(escapeXMLForAPIOutput(type.toString())).append('"');
    }
    xml.append("/>\n");
  }
  return xml.toString();
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:67,代码来源:RuleMatchAsXmlSerializer.java


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