public boolean matches(@NotNull final String name, @NotNull final String pattern) {
   final AnAction anAction = myActionManager.getAction(name);
   if (!(anAction instanceof ActionGroup)) {
     final Presentation presentation = anAction.getTemplatePresentation();
     final String text = presentation.getText();
     final String description = presentation.getDescription();
     final Pattern compiledPattern = getPattern(pattern);
     if ((text != null && myMatcher.matches(text, compiledPattern))
         || (description != null && myMatcher.matches(description, compiledPattern))) {
       return true;
     }
   }
   return false;
 }
Beispiel #2
0
  public static List<LinkedHashMap<String, Object>> getPhrases(
      GraphDatabaseService db, String text, GraphManager graphManager) {
    // This method trains a model on a supplied label and text content
    Map<Long, Integer> patternMatchers =
        PatternMatcher.match(GraphManager.ROOT_TEMPLATE, text, db, graphManager);

    // Translate map to phrases
    List<LinkedHashMap<String, Object>> results =
        patternMatchers
            .keySet()
            .stream()
            .map(
                a -> {
                  LinkedHashMap<String, Object> linkHashMap = new LinkedHashMap<>();
                  linkHashMap.put("feature", NodeManager.getNodeFromGlobalCache(a).get("phrase"));
                  linkHashMap.put("frequency", patternMatchers.get(a));
                  return linkHashMap;
                })
            .collect(Collectors.toList());

    results.sort(
        (a, b) -> {
          Integer diff = ((Integer) a.get("frequency")) - ((Integer) b.get("frequency"));
          return diff > 0 ? -1 : diff.equals(0) ? 0 : 1;
        });

    return results;
  }
  /**
   * Filters a collection according to the include and exclude parameters.
   *
   * @param c The collection to filter.
   * @return A filtered collection.
   */
  protected Collection filterCollection(Collection c) {
    ArrayList<Object> result = new ArrayList<Object>();

    PatternMatcher pm = new Perl5Matcher();

    for (Iterator i = c.iterator(); i.hasNext(); ) {
      String pageName = null;
      Object objectje = i.next();
      if (objectje instanceof WikiPage) {
        pageName = ((WikiPage) objectje).getName();
      } else {
        pageName = (String) objectje;
      }

      //
      //  If include parameter exists, then by default we include only those
      //  pages in it (excluding the ones in the exclude pattern list).
      //
      //  include='*' means the same as no include.
      //
      boolean includeThis = m_include == null;

      if (m_include != null) {
        for (int j = 0; j < m_include.length; j++) {
          if (pm.matches(pageName, m_include[j])) {
            includeThis = true;
            break;
          }
        }
      }

      if (m_exclude != null) {
        for (int j = 0; j < m_exclude.length; j++) {
          if (pm.matches(pageName, m_exclude[j])) {
            includeThis = false;
            break; // The inner loop, continue on the next item
          }
        }
      }

      if (includeThis) {
        if (objectje instanceof WikiPage) {
          result.add(objectje);
        } else {
          result.add(pageName);
        }
        //
        //  if we want to show the last modified date of the most recently change page, we keep a
        // "high watermark" here:
        WikiPage page = null;
        if (m_lastModified) {
          page = m_engine.getPage(pageName);
          if (page != null) {
            Date lastModPage = page.getLastModified();
            if (log.isDebugEnabled()) {
              log.debug("lastModified Date of page " + pageName + " : " + m_dateLastModified);
            }
            if (lastModPage.after(m_dateLastModified)) {
              m_dateLastModified = lastModPage;
            }
          }
        }
      }
    }

    return result;
  }