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


Java RuleMatch.setSuggestedReplacement方法代码示例

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


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

示例1: getRuleMatches

import org.languagetool.rules.RuleMatch; //导入方法依赖的package包/类
private List<RuleMatch> getRuleMatches(String resultXml, AnnotatedText text) throws XPathExpressionException {
  List<RuleMatch> matches = new ArrayList<>();
  Document document = getDocument(resultXml);
  XPath xPath = XPathFactory.newInstance().newXPath();
  NodeList errors = (NodeList)xPath.evaluate("//error", document, XPathConstants.NODESET);
  for (int i = 0; i < errors.getLength(); i++) {
    Node error = errors.item(i);
    String string = xPath.evaluate("string", error);
    String description = xPath.evaluate("description", error);
    String preContext = xPath.evaluate("precontext", error);
    String errorText = preContext + " " + string;
    int fromPos = text.getPlainText().indexOf(errorText) + preContext.length() + 1;
    int toPos = fromPos + string.length();
    NodeList suggestions = (NodeList)xPath.evaluate("suggestions", error, XPathConstants.NODESET);
    RuleMatch ruleMatch = new RuleMatch(new AtdRule(), null, 
            text.getOriginalTextPositionFor(fromPos), text.getOriginalTextPositionFor(toPos), description);
    for (int j = 0; j < suggestions.getLength(); j++) {
      Node option = suggestions.item(j);
      String optionStr = xPath.evaluate("option", option);
      ruleMatch.setSuggestedReplacement(optionStr);
    }
    matches.add(ruleMatch);
  }
  return matches;
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:26,代码来源:AtDEvaluator.java

示例2: createRuleMatch

import org.languagetool.rules.RuleMatch; //导入方法依赖的package包/类
@NotNull
private RuleMatch createRuleMatch(AnalyzedTokenReadings token, Suggestion suggestion, float[] y) {
  String msg = getMessage(suggestion, y);
  int pos = token.getStartPos();
  RuleMatch ruleMatch = new RuleMatch(this, pos, pos + token.getToken().length(), msg);
  ruleMatch.setSuggestedReplacement(suggestion.toString());
  return ruleMatch;
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:9,代码来源:NeuralNetworkRule.java

示例3: testCorrectTextFromMatches

import org.languagetool.rules.RuleMatch; //导入方法依赖的package包/类
@Test
public void testCorrectTextFromMatches() {
  RuleMatch match1 = new RuleMatch(new FakeRule(), null, 0, 9, "msg1");
  match1.setSuggestedReplacement("I've had");
  RuleMatch match2 = new RuleMatch(new FakeRule(), null, 0, 9, "msg2");
  match2.setSuggestedReplacement("I have");
  List<RuleMatch> matches = Arrays.asList(match1, match2);
  assertThat(Tools.correctTextFromMatches("I've have", matches), is("I've had"));
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:10,代码来源:ToolsTest.java

示例4: match

import org.languagetool.rules.RuleMatch; //导入方法依赖的package包/类
@Override
  public RuleMatch[] match(AnalyzedSentence sentence) throws IOException {
    List<RuleMatch> ruleMatches = new ArrayList<>();
    AnalyzedTokenReadings[] tokens = sentence.getTokensWithoutWhitespace();    

    for (int i = 1; i < tokens.length-1; i++) {
      AnalyzedTokenReadings tokenReadings = tokens[i];
      AnalyzedTokenReadings nextTokenReadings = tokens[i + 1];
      
      boolean isCapitalized = Character.isUpperCase(tokenReadings.getToken().charAt(0));
      
      if (isInPrefixes(tokenReadings, isCapitalized)
          && PosTagHelper.hasPosTagPart(nextTokenReadings, "noun")
//          && ! PosTagHelper.hasPosTag(nextTokenReadings, Pattern.compile("^(?!noun).*"))
          && ALL_LOWER.matcher(nextTokenReadings.getToken()).matches() ) {
    
        String hyphenedWord = tokenReadings.getToken() + "-" + nextTokenReadings.getToken();
        String tokenToCheck = isCapitalized ? StringUtils.uncapitalize(hyphenedWord) : hyphenedWord;
        
        if ( wordTagger.tag(tokenToCheck).size() > 0 ) {
          RuleMatch potentialRuleMatch = new RuleMatch(this, sentence, tokenReadings.getStartPos(), nextTokenReadings.getEndPos(), "Можливо, пропущено дефіс?", getDescription());
          potentialRuleMatch.setSuggestedReplacement(hyphenedWord);

          ruleMatches.add(potentialRuleMatch);
        }
      }
      
    }
    
    return ruleMatches.toArray(new RuleMatch[0]);
  }
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:32,代码来源:MissingHyphenRule.java

示例5: match

import org.languagetool.rules.RuleMatch; //导入方法依赖的package包/类
@Override
public RuleMatch[] match(List<AnalyzedSentence> sentences) throws IOException {
  String firstUse = null;
  List<RuleMatch> ruleMatches = new ArrayList<>();
  int pos = 0;
  for (AnalyzedSentence sentence : sentences) {
    AnalyzedTokenReadings[] tokens = sentence.getTokensWithoutWhitespace();
    for (int i = 0; i < tokens.length; i++) {
      if (i > 0 && (tokens[i-1].isSentenceStart() || tokens[i-1].getToken().matches("[\"„:]"))) {
        continue;
      }
      AnalyzedTokenReadings token = tokens[i];
      String word = token.getToken();
      String lcWord = word.toLowerCase();
      if (lowerWords.contains(lcWord) || ambiguousWords.contains(lcWord)) {
        if (firstUse == null) {
          if (!ambiguousWords.contains(word)) {
            firstUse = word;
          }
        } else {
          boolean firstUseIsUpper = StringTools.startsWithUppercase(firstUse);
          String msg = null;
          String replacement = null;
          if (firstUseIsUpper && !StringTools.startsWithUppercase(word)) {
            replacement =  StringTools.uppercaseFirstChar(word);
            if (ambiguousWords.contains(word)) {
              msg = "Vorher wurde bereits '" + firstUse + "' großgeschrieben. " +
                      "Nur falls es sich hier auch um eine Anrede handelt: Aus Gründen der Einheitlichkeit '" + replacement + "' hier auch großschreiben?";
            } else {
              msg = "Vorher wurde bereits '" + firstUse + "' großgeschrieben. " +
                      "Aus Gründen der Einheitlichkeit '" + replacement + "' hier auch großschreiben?";
            }
          } else if (!firstUseIsUpper && StringTools.startsWithUppercase(word)) {
            replacement = StringTools.lowercaseFirstChar(word);
            msg = "Vorher wurde bereits '" + firstUse + "' kleingeschrieben. " +
                    "Aus Gründen der Einheitlichkeit '" + replacement + "' hier auch kleinschreiben?";
          }
          if (replacement != null) {
            RuleMatch ruleMatch = new RuleMatch(this, sentence, pos + token.getStartPos(), pos + token.getEndPos(), msg);
            ruleMatch.setSuggestedReplacement(replacement);
            ruleMatches.add(ruleMatch);
          }
        }
      }
    }
    pos += sentence.getText().length();
  }
  return toRuleMatchArray(ruleMatches);
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:50,代码来源:DuUpperLowerCaseRule.java


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