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


Java RuleMatch.setSuggestedReplacements方法代码示例

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


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

示例1: getRuleMatches

import org.languagetool.rules.RuleMatch; //导入方法依赖的package包/类
protected List<RuleMatch> getRuleMatches(String word, int startPos, AnalyzedSentence sentence) throws IOException {
  List<RuleMatch> ruleMatches = new ArrayList<>();
  if (isMisspelled(speller1, word) || isProhibited(word)) {
    RuleMatch ruleMatch = new RuleMatch(this, sentence, startPos, startPos
        + word.length(), messages.getString("spelling"),
        messages.getString("desc_spelling_short"));
    List<String> suggestions = speller1.getSuggestions(word);
    if (suggestions.isEmpty() && word.length() >= 5) {
      // speller1 uses a maximum edit distance of 1, it won't find suggestion for "garentee", "greatful" etc.
      suggestions.addAll(speller2.getSuggestions(word));
      if (suggestions.isEmpty()) {
        suggestions.addAll(speller3.getSuggestions(word));
      }
    }
    suggestions.addAll(0, getAdditionalTopSuggestions(suggestions, word));
    suggestions.addAll(getAdditionalSuggestions(suggestions, word));
    if (!suggestions.isEmpty()) {
      filterSuggestions(suggestions);
      ruleMatch.setSuggestedReplacements(orderSuggestions(suggestions, word));
    }
    ruleMatches.add(ruleMatch);
  }
  return ruleMatches;
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:25,代码来源:MorfologikSpellerRule.java

示例2: getRuleMatches

import org.languagetool.rules.RuleMatch; //导入方法依赖的package包/类
@Override
protected List<RuleMatch> getRuleMatches(String word, int startPos, AnalyzedSentence sentence) throws IOException {
  List<RuleMatch> ruleMatches = super.getRuleMatches(word, startPos, sentence);
  if (ruleMatches.size() > 0) {
    // so 'word' is misspelled: 
    IrregularForms forms = getIrregularFormsOrNull(word);
    if (forms != null) {
      RuleMatch oldMatch = ruleMatches.get(0);
      RuleMatch newMatch = new RuleMatch(this, sentence, oldMatch.getFromPos(), oldMatch.getToPos(), 
              "Possible spelling mistake. Did you mean <suggestion>" + forms.forms.get(0) +
              "</suggestion>, the " + forms.formName + " form of the " + forms.posName +
              " '" + forms.baseform + "'?");
      List<String> allSuggestions = new ArrayList<>();
      allSuggestions.addAll(forms.forms);
      for (String repl : oldMatch.getSuggestedReplacements()) {
        if (!allSuggestions.contains(repl)) {
          allSuggestions.add(repl);
        }
      }
      newMatch.setSuggestedReplacements(allSuggestions);
      ruleMatches.set(0, newMatch);
    }
  }
  return ruleMatches;
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:26,代码来源:AbstractEnglishSpellerRule.java

示例3: createRuleMatch

import org.languagetool.rules.RuleMatch; //导入方法依赖的package包/类
@Override
protected RuleMatch createRuleMatch(String prevToken, String token, int prevPos, int pos, String msg, AnalyzedSentence sentence) {
  boolean doubleI = prevToken.equals("І") && token.equals("і");
  if( doubleI ) {
    msg += " або, можливо, перша І має бути латинською.";
  }
  
  RuleMatch ruleMatch = super.createRuleMatch(prevToken, token, prevPos, pos, msg, sentence);

  if( doubleI ) {
    List<String> replacements = new ArrayList<>(ruleMatch.getSuggestedReplacements());
    replacements.add("I і");
    ruleMatch.setSuggestedReplacements(replacements);
  }
  return ruleMatch;
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:17,代码来源:UkrainianWordRepeatRule.java

示例4: match

import org.languagetool.rules.RuleMatch; //导入方法依赖的package包/类
@Override
public RuleMatch[] match(AnalyzedSentence sentenceObj) throws IOException {
  String sentence = sentenceObj.getText();
  Matcher matcher = pattern.matcher(sentence);
  int startPos = 0;
  List<RuleMatch> matches = new ArrayList<>();
  while (matcher.find(startPos)) {
    String msg = replaceBackRefs(matcher, message);
    boolean sentenceStart = matcher.start(0) == 0;
    List<String> suggestions = extractSuggestions(matcher, msg);
    List<String> matchSuggestions = getMatchSuggestions(sentence, matcher);
    msg = replaceMatchElements(msg, matchSuggestions);
    int markStart = matcher.start(markGroup);
    int markEnd = matcher.end(markGroup);
    RuleMatch ruleMatch = new RuleMatch(this, sentenceObj, markStart, markEnd, msg, null, sentenceStart, null);
    List<String> allSuggestions = new ArrayList<>();
    if (matchSuggestions.size() > 0) {
      allSuggestions.addAll(matchSuggestions);
    } else {
      allSuggestions.addAll(suggestions);
      List<String> extendedSuggestions = extractSuggestions(matcher, getSuggestionsOutMsg());
      allSuggestions.addAll(extendedSuggestions);
    }
    ruleMatch.setSuggestedReplacements(allSuggestions);
    matches.add(ruleMatch);
    startPos = matcher.end();
  }
  return matches.toArray(new RuleMatch[matches.size()]);
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:30,代码来源:RegexPatternRule.java

示例5: match

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

  String prevToken = "";
  // we start from token 1, token 0 is SENT_START 
  for (int i = 1; i < tokens.length; i++) {
    String token = tokens[i].getToken();
    if (isWord(token) && prevToken.equalsIgnoreCase(token) && !ignore(sentence, tokensWithWS, i)) {
      int prevPos = tokens[i - 1].getStartPos();
      int pos = tokens[i].getStartPos();
      RuleMatch ruleMatch = new RuleMatch(this, sentence, prevPos, pos+prevToken.length(),
              messages.getString("repetition"),
              messages.getString("desc_repetition_short"));
      List<String> replacements = new ArrayList<>();
      replacements.add(prevToken + " " + token); // case 1: replace zero-width space w/ real space 
      replacements.add(prevToken);               // case 2: remove repeated word - same as original suggestion 
      replacements.add(prevToken + "ៗ");        // case 3: same as case 2, just add "repetition character"
      ruleMatch.setSuggestedReplacements(replacements);
      ruleMatches.add(ruleMatch);
    }
    prevToken = token;
  }

  return toRuleMatchArray(ruleMatches);
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:29,代码来源:KhmerWordRepeatRule.java

示例6: createRuleMatch

import org.languagetool.rules.RuleMatch; //导入方法依赖的package包/类
private RuleMatch createRuleMatch(AnalyzedTokenReadings readings, AnalyzedSentence sentence) {
  String tokenString = readings.getToken();
  String replacement = tokenString.replace(HIDDEN_CHAR.toString(), "");
  String msg = tokenString + getSuggestion(tokenString) + replacement;

  RuleMatch potentialRuleMatch = new RuleMatch(this, sentence, readings.getStartPos(), readings.getEndPos(), msg, getShort());
  potentialRuleMatch.setSuggestedReplacements(Arrays.asList(replacement));

  return potentialRuleMatch;
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:11,代码来源:HiddenCharacterRule.java

示例7: match

import org.languagetool.rules.RuleMatch; //导入方法依赖的package包/类
@Override
public RuleMatch[] match(AnalyzedSentence sentence) throws IOException {
  List<RuleMatch> ruleMatches = new ArrayList<>();
  if (needsInit) {
    init();
  }
  if (hunspellDict == null) {
    // some languages might not have a dictionary, be silent about it
    return toRuleMatchArray(ruleMatches);
  }
  String[] tokens = tokenizeText(getSentenceTextWithoutUrlsAndImmunizedTokens(sentence));

  // starting with the first token to skip the zero-length START_SENT
  int len = sentence.getTokens()[1].getStartPos();
  for (int i = 0; i < tokens.length; i++) {
    String word = tokens[i];
    if (ignoreWord(Arrays.asList(tokens), i) || ignoreWord(word)) {
      len += word.length() + 1;
      continue;
    }
    if (isMisspelled(word)) {
      RuleMatch ruleMatch = new RuleMatch(this, sentence,
          len, len + word.length(),
          messages.getString("spelling"),
          messages.getString("desc_spelling_short"));
      List<String> suggestions = getSuggestions(word);
      List<String> additionalTopSuggestions = getAdditionalTopSuggestions(suggestions, word);
      Collections.reverse(additionalTopSuggestions);
      for (String additionalTopSuggestion : additionalTopSuggestions) {
        if (!word.equals(additionalTopSuggestion)) {
          suggestions.add(0, additionalTopSuggestion);
        }
      }
      List<String> additionalSuggestions = getAdditionalSuggestions(suggestions, word);
      for (String additionalSuggestion : additionalSuggestions) {
        if (!word.equals(additionalSuggestion)) {
          suggestions.addAll(additionalSuggestions);
        }
      }
      if (!suggestions.isEmpty()) {
        filterSuggestions(suggestions);
        filterDupes(suggestions);
        ruleMatch.setSuggestedReplacements(suggestions);
      }
      ruleMatches.add(ruleMatch);
    }
    len += word.length() + 1;
  }
  return toRuleMatchArray(ruleMatches);
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:51,代码来源:HunspellRule.java

示例8: createRuleMatch

import org.languagetool.rules.RuleMatch; //导入方法依赖的package包/类
private RuleMatch createRuleMatch(AnalyzedTokenReadings readings, List<String> replacements, String msg, AnalyzedSentence sentence) {
  RuleMatch potentialRuleMatch = new RuleMatch(this, sentence, readings.getStartPos(), readings.getEndPos(), msg, "Перейменована назва");
  potentialRuleMatch.setSuggestedReplacements(replacements);

  return potentialRuleMatch;
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:7,代码来源:SimpleReplaceRenamedRule.java

示例9: createRuleMatch

import org.languagetool.rules.RuleMatch; //导入方法依赖的package包/类
private RuleMatch createRuleMatch(AnalyzedTokenReadings readings, List<String> replacements, String msg, AnalyzedSentence sentence) {
  RuleMatch potentialRuleMatch = new RuleMatch(this, sentence, readings.getStartPos(), readings.getEndPos(), msg, getShort());
  potentialRuleMatch.setSuggestedReplacements(replacements);

  return potentialRuleMatch;
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:7,代码来源:MixedAlphabetsRule.java


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