Package org.languagetool.tools

Examples of org.languagetool.tools.ContextTools


      } catch (SQLException e) {
        throw new RuntimeException(e);
      } finally {
        inStream.close();
      }
      contextTools = new ContextTools();
      contextTools.setContextSize(CONTEXT_SIZE);
      contextTools.setErrorMarkerStart(MARKER_START);
      contextTools.setErrorMarkerEnd(MARKER_END);
      contextTools.setEscapeHtml(false);
    }
View Full Code Here


    final String urlString = args[0];
    final URL url = new URL(urlString);
    final String mediaWikiContent = check.getMediaWikiContent(url);
    final String plainText = check.getPlainText(mediaWikiContent);
    final WikipediaQuickCheckResult checkResult = check.checkPage(plainText, new German());
    final ContextTools contextTools = new ContextTools();
    contextTools.setContextSize(CONTEXT_SIZE);
    for (RuleMatch ruleMatch : checkResult.getRuleMatches()) {
      System.out.println(ruleMatch.getMessage());
      final String context = contextTools.getPlainTextContext(ruleMatch.getFromPos(), ruleMatch.getToPos(), checkResult.getText());
      System.out.println(context);
    }
  }
View Full Code Here

    addHyperlinkListener(new MyHyperlinkListener());
    setTransferHandler(new RetainLineBreakTransferHandler());
  }

  String getRuleMatchHtml(List<RuleMatch> ruleMatches, String text, String startCheckText) {
    final ContextTools contextTools = new ContextTools();
    final StringBuilder sb = new StringBuilder();
    sb.append(startCheckText);
    sb.append("<br>\n");
    int i = 0;
    for (final RuleMatch match : ruleMatches) {
      final String output = Tools.makeTexti18n(messages, "result1", i + 1, match.getLine() + 1, match.getColumn());
      sb.append(output);
      final String msg = match.getMessage()
          .replaceAll("<suggestion>", "<b>").replaceAll("</suggestion>", "</b>")
          .replaceAll("<old>", "<b>").replaceAll("</old>", "</b>");
      sb.append("<b>").append(messages.getString("errorMessage")).append("</b> ");
      sb.append(msg);
      final RuleLink ruleLink = RuleLink.buildDeactivationLink(match.getRule());
      sb.append(" <a href=\"").append(ruleLink).append("\">").append(messages.getString("deactivateRule")).append("</a><br>\n");
      if (match.getSuggestedReplacements().size() > 0) {
        final String replacement = StringTools.listToString(match.getSuggestedReplacements(), "; ");
        sb.append("<b>").append(messages.getString("correctionMessage")).append("</b> ").append(replacement).append("<br>\n");
      }
      if (match.getRule() instanceof SpellingCheckRule) {
        contextTools.setErrorMarkerStart(SPELL_ERROR_MARKER_START);
      } else {
        contextTools.setErrorMarkerStart(LT_ERROR_MARKER_START);
      }
      final String context = contextTools.getContext(match.getFromPos(), match.getToPos(), text);
      sb.append("<b>").append(messages.getString("errorContext")).append("</b> ").append(context);
      sb.append("<br>\n");
      if (match.getRule().getUrl() != null && Desktop.isDesktopSupported()) {
        sb.append("<b>").append(messages.getString("moreInfo")).append("</b> <a href=\"");
        final String url = match.getRule().getUrl().toString();
View Full Code Here

   * @deprecated use {@link ContextTools}
   */
  public static String getContext(final int fromPos, final int toPos,
      String text, final int contextSize, final String markerStart,
      final String markerEnd, final boolean escapeHTML) {
    final ContextTools contextTools = new ContextTools();
    contextTools.setContextSize(contextSize);
    contextTools.setEscapeHtml(escapeHTML);
    contextTools.setErrorMarkerStart(markerStart);
    contextTools.setErrorMarkerEnd(markerEnd);
    return contextTools.getContext(fromPos, toPos, text);
  }
View Full Code Here

      }
    });
  }

  private String getRuleMatchHtml(List<RuleMatch> ruleMatches, String text, String startCheckText) {
    final ContextTools contextTools = new ContextTools();
    final StringBuilder sb = new StringBuilder(200);
    sb.append(startCheckText);
    sb.append("<br>\n");
    int i = 0;
    for (final RuleMatch match : ruleMatches) {
      final String output = Tools.makeTexti18n(messages, "result1", i + 1, match.getLine() + 1, match.getColumn());
      sb.append(output);
      final String msg = match.getMessage()
          .replaceAll("<suggestion>", "<b>").replaceAll("</suggestion>", "</b>")
          .replaceAll("<old>", "<b>").replaceAll("</old>", "</b>");
      sb.append("<b>").append(messages.getString("errorMessage")).append("</b> ");
      sb.append(msg);
      final RuleLink ruleLink = RuleLink.buildDeactivationLink(match.getRule());
      sb.append(" <a href=\"").append(ruleLink).append("\">").append(messages.getString("deactivateRule")).append("</a><br>\n");
      if (match.getSuggestedReplacements().size() > 0) {
        final String replacement = StringTools.listToString(match.getSuggestedReplacements(), "; ");
        sb.append("<b>").append(messages.getString("correctionMessage")).append("</b> ").append(replacement).append("<br>\n");
      }
      if (ITSIssueType.Misspelling.equals(match.getRule().getLocQualityIssueType())) {
        contextTools.setErrorMarkerStart(SPELL_ERROR_MARKER_START);
      } else {
        contextTools.setErrorMarkerStart(LT_ERROR_MARKER_START);
      }
      final String context = contextTools.getContext(match.getFromPos(), match.getToPos(), text);
      sb.append("<b>").append(messages.getString("errorContext")).append("</b> ").append(context);
      sb.append("<br>\n");
      if (match.getRule().getUrl() != null && Desktop.isDesktopSupported()) {
        sb.append("<b>").append(messages.getString("moreInfo")).append("</b> <a href=\"");
        final String url = match.getRule().getUrl().toString();
View Full Code Here

   * @since 1.0.1
   */
  private static void printMatches(final List<RuleMatch> ruleMatches,
                                   final int prevMatches, final String contents, final int contextSize) {
    int i = 1;
    final ContextTools contextTools = new ContextTools();
    contextTools.setContextSize(contextSize);
    for (final RuleMatch match : ruleMatches) {
      String output = i + prevMatches + ".) Line " + (match.getLine() + 1) + ", column "
              + match.getColumn() + ", Rule ID: " + match.getRule().getId();
      if (match.getRule() instanceof PatternRule) {
        final PatternRule pRule = (PatternRule) 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);
      final List<String> replacements = match.getSuggestedReplacements();
      if (!replacements.isEmpty()) {
        System.out.println("Suggestion: "
                + StringTools.listToString(replacements, "; "));
      }
      System.out.println(contextTools.getPlainTextContext(match.getFromPos(), match.getToPos(), contents));
      if (match.getRule().getUrl() != null) {
        System.out.println("More info: " +
                match.getRule().getUrl().toString());
      }
      if (i < ruleMatches.size()) {
View Full Code Here

      return matchingSentences;
    }
  }

  private static ContextTools getContextTools(int contextSize) {
    final ContextTools contextTools = new ContextTools();
    contextTools.setEscapeHtml(false);
    contextTools.setContextSize(contextSize);
    contextTools.setErrorMarkerStart("**");
    contextTools.setErrorMarkerEnd("**");
    return contextTools;
  }
View Full Code Here

    final Searcher searcher = new Searcher(new SimpleFSDirectory(indexDir));
    if (!limitSearch) {
      searcher.setMaxHits(100_000);
    }
    searcher.limitSearch = limitSearch;
    final ContextTools contextTools = getContextTools(140);
    int totalMatches = 0;
    for (String ruleId : ruleIds) {
      final long ruleStartTime = System.currentTimeMillis();
      for (PatternRule rule : searcher.getRuleById(ruleId, language)) {
        System.out.println("===== " + ruleId + "[" + rule.getSubId() + "] =========================================================");
        final SearcherResult searcherResult = searcher.findRuleMatchesOnIndex(rule, language);
        int i = 1;
        if (searcherResult.getMatchingSentences().size() == 0) {
          System.out.println("[no matches]");
        }
        for (MatchingSentence ruleMatch : searcherResult.getMatchingSentences()) {
          for (RuleMatch match : ruleMatch.getRuleMatches()) {
            String context = contextTools.getContext(match.getFromPos(), match.getToPos(), ruleMatch.getSentence());
            if (WIKITEXT_OUTPUT) {
              ContextTools contextTools2 = getContextTools(0);
              String coveredText = contextTools2.getContext(match.getFromPos(), match.getToPos(), ruleMatch.getSentence());
              coveredText = coveredText.replaceFirst("^\\.\\.\\.", "").replaceFirst("\\.\\.\\.$", "");
              coveredText = coveredText.replaceFirst("^\\*\\*", "").replaceFirst("\\*\\*$", "");
              String encodedTextWithQuotes = URLEncoder.encode("\"" + coveredText + "\"", "UTF-8");
              String searchLink = "https://de.wikipedia.org/w/index.php?search=" + encodedTextWithQuotes + "&title=Spezial%3ASuche&go=Artikel";
              context = context.replaceAll("\\*\\*.*?\\*\\*", "[" + searchLink + " " + coveredText + "]");
View Full Code Here

      lookupSt = conn.prepareStatement(lookupSql);
      insertSt = conn.prepareStatement(insertSql);
    } catch (SQLException | IOException e) {
      throw new RuntimeException(e);
    }
    contextTools = new ContextTools();
    contextTools.setContextSize(MAX_CONTEXT_LENGTH);
    contextTools.setErrorMarkerStart(MARKER_START);
    contextTools.setErrorMarkerEnd(MARKER_END);
    contextTools.setEscapeHtml(false);
    smallContextTools = new ContextTools();
    smallContextTools.setContextSize(SMALL_CONTEXT_LENGTH);
    smallContextTools.setErrorMarkerStart(MARKER_START);
    smallContextTools.setErrorMarkerEnd(MARKER_END);
    smallContextTools.setEscapeHtml(false);
  }
View Full Code Here

TOP

Related Classes of org.languagetool.tools.ContextTools

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.