Package org.wikipediacleaner.api.data

Examples of org.wikipediacleaner.api.data.Suggestion


    List<ContentsChunk> chunks = computeContentsChunks(analysis, true);
    String contents = analysis.getContents();
    Iterator<Suggestion> itSuggestion = suggestions.iterator();
    List<Replacement> tmpReplacements = new ArrayList<CheckErrorAlgorithm501.Replacement>();
    while (itSuggestion.hasNext()) {
      Suggestion suggestion = itSuggestion.next();
      if (!suggestion.isOtherPattern()) {
        Performance perf = new Performance("Slow regular expression");
        perf.setThreshold(slowRegexp);
        itSuggestion.remove();
        Matcher matcher = suggestion.initMatcher(contents);
        for (ContentsChunk chunk : chunks) {
          matcher.region(chunk.getBegin(), chunk.getEnd());
          int authorizedBegin = chunk.getBegin();
          while (matcher.find()) {
            int begin = matcher.start();
            int end = matcher.end();
            boolean shouldKeep = true;
            if (shouldKeep && (begin > 0) &&
                (Character.isLetterOrDigit(contents.charAt(begin))) &&
                (Character.isLetterOrDigit(contents.charAt(begin - 1)))) {
              shouldKeep = false;
            }
            if (shouldKeep && (end < contents.length()) &&
                (Character.isLetterOrDigit(contents.charAt(end))) &&
                (Character.isLetterOrDigit(contents.charAt(end - 1)))) {
              shouldKeep = false;
            }
            if (shouldKeep) {
              tmpReplacements.clear();
              shouldKeep = addReplacements(
                  begin, end, contents, authorizedBegin, chunk.getEnd(),
                  suggestion, tmpReplacements);
            }
            if (shouldKeep && (analysis.getAreas().getEndArea(begin) > begin)) {
              shouldKeep = false;
            }
            if (shouldKeep && (analysis.isInTemplate(begin) != null)) {
              shouldKeep = false;
            }
            if (shouldKeep) {
              shouldKeep = shouldKeep(contents, begin, end);
            }
            if (shouldKeep) {
              result = true;
              replacements.addAll(tmpReplacements);
            }
            authorizedBegin = end;
          }
        }
        perf.printEnd(suggestion.getPatternText());
      }
    }

    return result;
  }
View Full Code Here


    List<ContentsChunk> chunks = computeContentsChunks(analysis, false);
    String contents = analysis.getContents();
    Iterator<Suggestion> itSuggestion = suggestions.iterator();
    List<Replacement> tmpReplacements = new ArrayList<CheckErrorAlgorithm501.Replacement>();
    while (itSuggestion.hasNext()) {
      Suggestion suggestion = itSuggestion.next();
      if (suggestion.isOtherPattern()) {
        Performance perf = new Performance("Slow regular expression");
        perf.setThreshold(slowRegexp);
        itSuggestion.remove();
        Matcher matcher = suggestion.initMatcher(contents);
        for (ContentsChunk chunk : chunks) {
          matcher.region(chunk.getBegin(), chunk.getEnd());
          int authorizedBegin = chunk.getBegin();
          while (matcher.find()) {
            int begin = matcher.start();
            int end = matcher.end();
            tmpReplacements.clear();
            boolean shouldKeep = addReplacements(
                begin, end, contents, authorizedBegin, chunk.getEnd(),
                suggestion, tmpReplacements);
            if (shouldKeep) {
              shouldKeep = shouldKeep(contents, begin, end);
            }
            if (shouldKeep) {
              result = true;
              replacements.addAll(tmpReplacements);
            }
            authorizedBegin = end;
          }
        }
        perf.printEnd(suggestion.getComment(), suggestion.getPatternText());
      }
    }

    return result;
  }
View Full Code Here

    List<PageElementFunction> functions = analysis.getFunctions();
    String contents = analysis.getContents();
    int contentsLength = contents.length();
    Iterator<Suggestion> itSuggestion = suggestions.iterator();
    while (itSuggestion.hasNext()) {
      Suggestion suggestion = itSuggestion.next();
      if (suggestion.getPatternText().startsWith("\\{\\{")) {
        itSuggestion.remove();
        Matcher matcher = suggestion.initMatcher(contents);

        // Check suggestion on every template
        for (PageElementTemplate template : templates) {
          int begin = template.getBeginIndex();
          if (matcher.region(begin, contentsLength).lookingAt()) {
View Full Code Here

    List<PageElementInternalLink> links = analysis.getInternalLinks();
    String contents = analysis.getContents();
    int contentsLength = contents.length();
    Iterator<Suggestion> itSuggestion = suggestions.iterator();
    while (itSuggestion.hasNext()) {
      Suggestion suggestion = itSuggestion.next();
      if (suggestion.getPatternText().startsWith("\\[\\[")) {
        itSuggestion.remove();
        Matcher matcher = suggestion.initMatcher(contents);

        // Check suggestion on every internal links
        for (PageElementInternalLink link : links) {
          int begin = link.getBeginIndex();
          if (matcher.region(begin, contentsLength).lookingAt()) {
View Full Code Here

                Collection<PageElementTemplate> templates = analysis.getTemplates(elements[1]);
                for (PageElementTemplate template : templates) {
                  String chapterId = PageAnalysisUtils.getCurrentChapterId(analysis, template.getBeginIndex());
                  if ((suggestionIgnore == null) || (!suggestionIgnore.contains(chapterId))) {
                    String patternText = template.getParameterValue(elements[2]);
                    Suggestion suggestion = tmpMap.get(patternText);
                    if (suggestion == null) {
                      String chapter = PageAnalysisUtils.getCurrentChapterId(analysis, template.getBeginIndex());
                      suggestion = Suggestion.createSuggestion(patternText, false, chapter);
                      if (suggestion != null) {
                        tmpMap.put(patternText, suggestion);
                      }
                    }
                    if (suggestion != null) {
                      boolean automatic = false;
                      if (elements.length > 4) {
                        suggestion.setComment(template.getParameterValue(elements[4]));
                        if (elements.length > 6) {
                          if (elements[6].equalsIgnoreCase(template.getParameterValue(elements[5]))) {
                            automatic = true;
                          }
                        }
                      }
                      for (String elementReplacement : elementsReplacement) {
                        String replacementText = template.getParameterValue(elementReplacement);
                        if ((replacementText != null) &&
                            (replacementText.length() > 0)) {
                          suggestion.addReplacement(replacementText, automatic);
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }

        // Construct suggestions from AWB format
        if (suggestionTypoPages != null) {
          List<String> suggestionIgnore = getStringList(WPCConfigurationStringList.SUGGESTION_IGNORE);
          for (String suggestionPage : suggestionTypoPages) {
            Page page = pages.get(suggestionPage);
            if ((page != null) && (page.getContents() != null)) {
              String contents = page.getContents();
              PageAnalysis analysis = page.getAnalysis(contents, true);
              Collection<PageElementTag> tags = analysis.getTags(PageElementTag.TAG_OTHER_TYPO);
              for (PageElementTag tag : tags) {
                String chapterId = PageAnalysisUtils.getCurrentChapterId(analysis, tag.getBeginIndex());
                if ((suggestionIgnore == null) || (!suggestionIgnore.contains(chapterId))) {
                  Parameter word = tag.getParameter("word");
                  Parameter find = tag.getParameter("find");
                  Parameter replace = tag.getParameter("replace");
                  Parameter disabled = tag.getParameter("disabled");
                  if ((word != null) && (find != null) && (replace != null) && (disabled == null)) {
                    String wordValue = word.getValue();
                    String findValue = find.getValue();
                    String replaceValue = replace.getValue();
                    if ((wordValue != null) && (findValue != null) && (replaceValue != null)) {
                      String cleanFindValue = Suggestion.cleanPattern(findValue);
                      if (cleanFindValue == null) {
                        System.err.println("Rejecting " + wordValue + " : " + findValue);
                      } else {
                        Suggestion suggestion = tmpMap.get(cleanFindValue);
                        if (suggestion == null) {
                          String chapter = PageAnalysisUtils.getCurrentChapterId(analysis, tag.getBeginIndex());
                          suggestion = Suggestion.createSuggestion(cleanFindValue, true, chapter);
                          if (suggestion != null) {
                            tmpMap.put(cleanFindValue, suggestion);
                          }
                        }
                        if (suggestion != null) {
                          suggestion.setComment("Typo AWB " + wordValue);
                          suggestion.addReplacement(replaceValue, false);
                        }
                      }
                    }
                  }
                }
View Full Code Here

TOP

Related Classes of org.wikipediacleaner.api.data.Suggestion

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.