Examples of Suggestion


Examples of org.apache.stanbol.enhancer.engines.keywordextraction.impl.Suggestion

                "for selection "+linkedEntity.getSelectedText(),
                linkedEntity.getSuggestions().size(),
                expectedSuggestions.size());
            double score = linkedEntity.getScore();
            for(int i=0;i<expectedSuggestions.size();i++){
                Suggestion suggestion = linkedEntity.getSuggestions().get(i);
                assertEquals("Expecced Suggestion at Rank "+i+" expected: "+
                    expectedSuggestions.get(i)+" suggestion: "+
                    suggestion.getRepresentation().getId(),
                    expectedSuggestions.get(i),
                    suggestion.getRepresentation().getId());
                assertTrue("Score of suggestion "+i+"("+suggestion.getScore()+
                    " > as of the previous one ("+score+")",
                    score >= suggestion.getScore());
                score = suggestion.getScore();
            }
        }
    }
View Full Code Here

Examples of org.apache.stanbol.enhancer.engines.keywordextraction.linking.Suggestion

                "for selection "+linkedEntity.getSelectedText(),
                linkedEntity.getSuggestions().size(),
                expectedSuggestions.size());
            double score = linkedEntity.getScore();
            for(int i=0;i<expectedSuggestions.size();i++){
                Suggestion suggestion = linkedEntity.getSuggestions().get(i);
                assertEquals("Expecced Suggestion at Rank "+i+" expected: "+
                    expectedSuggestions.get(i)+" suggestion: "+
                    suggestion.getRepresentation().getId(),
                    expectedSuggestions.get(i),
                    suggestion.getRepresentation().getId());
                assertTrue("Score of suggestion "+i+"("+suggestion.getScore()+
                    " > as of the previous one ("+score+")",
                    score >= suggestion.getScore());
                score = suggestion.getScore();
            }
        }
    }
View Full Code Here

Examples of org.jahia.services.search.Suggestion

    public Suggestion suggest(String originalQuery, String siteKey, Locale locale) {
        if (StringUtils.isBlank(originalQuery)) {
            return null;
        }

        Suggestion suggestion = null;
        JCRSessionWrapper session;
        try {
            session = ServicesRegistry.getInstance().getJCRStoreService().getSessionFactory().getCurrentUserSession(
                    null, locale);
            QueryManager qm = session.getWorkspace().getQueryManager();
            StringBuilder xpath = new StringBuilder(64);
            xpath.append("/jcr:root[rep:spellcheck(").append(stringToJCRSearchExp(originalQuery)).append(")");
            if (locale != null) {
                xpath.append(" or @jcr:language='" + locale + "'");
            }
            xpath.append("]");
            if (siteKey != null) {
                xpath.append("/sites/").append(siteKey);
            }
            xpath.append("/(rep:spellcheck())");

            Query query = qm.createQuery(xpath.toString(), Query.XPATH);
            RowIterator rows = query.execute().getRows();
            if (rows.hasNext()) {
                Row r = rows.nextRow();
                Value v = r.getValue("rep:spellcheck()");
                if (v != null) {
                    suggestion = new Suggestion(originalQuery, v.getString());
                }
                if (logger.isDebugEnabled()) {
                    logger.debug("Making spell check suggestion for '" + originalQuery + "' site '"
                            + siteKey + "' and locale '" + locale + "' using XPath query ["
                            + xpath.toString() + "]. Result suggestion: " + suggestion);
View Full Code Here

Examples of org.switchyard.quickstarts.demos.library.types.Suggestion

    }

    public void testLibraryServices() throws Exception {
        System.out.println();
        // get 1st suggestion
        Suggestion suggestion1_Zombie = getSuggestion("Zombie");
        Book book1_WorldWarZ = suggestion1_Zombie.getBook();
        System.out.println("Received suggestion for book: " + book1_WorldWarZ.getTitle() + " (isbn: " + book1_WorldWarZ.getIsbn() + ")");
        Assert.assertEquals("World War Z", book1_WorldWarZ.getTitle());
        // take out 1st loan
        System.out.println("Attempting 1st loan for isbn: " + book1_WorldWarZ.getIsbn());
        Loan loan1_WorldWarZ = attemptLoan(book1_WorldWarZ.getIsbn());
        System.out.println("1st loan approved? " + loan1_WorldWarZ.isApproved());
        Assert.assertTrue(loan1_WorldWarZ.isApproved());
        // 2nd loan should not be approved since 1st loan hasn't been returned
        System.out.println("Attempting 2nd loan for isbn: " + book1_WorldWarZ.getIsbn());
        Loan loan2_WorldWarZ = attemptLoan(book1_WorldWarZ.getIsbn());
        System.out.println("2nd loan approved? " + loan2_WorldWarZ.isApproved());
        Assert.assertFalse(loan2_WorldWarZ.isApproved());
        // return 1st loan
        System.out.println("Returning 1st loan for isbn: " + loan1_WorldWarZ.getBook().getIsbn());
        boolean return1_ack = returnLoan(loan1_WorldWarZ);
        System.out.println("1st loan return acknowledged? " + return1_ack);
        Assert.assertTrue(return1_ack);
        // try 2nd loan again; this time it should work
        System.out.println("Re-attempting 2nd loan for isbn: " + book1_WorldWarZ.getIsbn());
        loan2_WorldWarZ = attemptLoan(book1_WorldWarZ.getIsbn());
        System.out.println("Re-attempt of 2nd loan approved? " + loan2_WorldWarZ.isApproved());
        Assert.assertTrue(loan2_WorldWarZ.isApproved());
        // get 2nd suggestion, and since 1st book not available (again), 2nd match will return
        Suggestion suggestion2_TheZombieSurvivalGuide = getSuggestion("Zombie");
        Book book2_TheZombieSurvivalGuide = suggestion2_TheZombieSurvivalGuide.getBook();
        System.out.println("Received suggestion for book: " + book2_TheZombieSurvivalGuide.getTitle() + " (isbn: " + book2_TheZombieSurvivalGuide.getIsbn() + ")");
        Assert.assertEquals("The Zombie Survival Guide", book2_TheZombieSurvivalGuide.getTitle());
        // take out 3rd loan
        System.out.println("Attempting 3rd loan for isbn: " + book2_TheZombieSurvivalGuide.getIsbn());
        Loan loan3_TheZombieSurvivalGuide = attemptLoan(book2_TheZombieSurvivalGuide.getIsbn());
View Full Code Here

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

Examples of org.wikipediacleaner.api.data.Suggestion

    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

Examples of org.wikipediacleaner.api.data.Suggestion

    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

Examples of org.wikipediacleaner.api.data.Suggestion

    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

Examples of org.wikipediacleaner.api.data.Suggestion

                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

Examples of simpleserver.config.GiveAliasList.Suggestion

      if (request[0].matches("\\d+")) {
        id = Integer.valueOf(request[0]);
      } else {
        Item item = target.getServer().giveAliasList.getItemId(request[0]);
        if (item == null) {
          Suggestion suggestion = target.getServer().giveAliasList.findWithLevenshtein(request[0]);
          if (suggestion.distance > 4 || suggestion.distance * 2 > request[0].length()) {
            tError("Can't find item %s", request[0]);
            return;
          }
          item = target.getServer().giveAliasList.getItemId(suggestion.name);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.