Exemple #1
0
  protected boolean isPrefixClosed(SequenceDatabase<T> sdb, SortedMap<T, Integer> frequencies) {
    List<T> prefix = sdb.getPrefix();
    if (prefix == null) {
      return false;
    }

    int support = sdb.getSupportOfPrefix();
    if (logger.isDebugEnabled()) {
      logger.debug("Testing: {}:{}", prefix, support);
    }

    for (Map.Entry<T, Integer> entry : frequencies.entrySet()) {
      if (entry.getValue() == support) {
        if (logger.isTraceEnabled()) {
          logger.trace(
              "Open: The prefix can be extended by a forward extension item {}.", entry.getKey());
        }
        return false; /* Found a forward extension item */
      }
    }

    if (!hasBackwardExtensionItem(sdb)) {
      if (logger.isDebugEnabled()) {
        logger.debug("Closed: {}:{}", prefix, support);
      }
      return true;
    }
    return false;
  }
Exemple #2
0
  protected List<List<T>> bide(SequenceDatabase<T> sdb, int minSup, ResultHandler<T> handler) {
    List<T> prefix = sdb.getPrefix();

    if (prefix != null && backScan(sdb)) {
      return Collections.emptyList();
    }

    SortedMap<T, Integer> frequencies = sdb.getItemFrequencies(minSup);
    if (isPrefixClosed(sdb, frequencies)) {
      synchronized (handler) {
        handler.handle(prefix, sdb.getSupportOfPrefix(), sdb);
      }
    }

    List<List<T>> prefixes = new ArrayList<List<T>>();
    for (Map.Entry<T, Integer> entry : frequencies.entrySet()) {
      List<T> extendedPrefix = new ArrayList<T>();
      if (prefix != null) {
        extendedPrefix.addAll(prefix);
      }
      extendedPrefix.add(entry.getKey());
      prefixes.add(extendedPrefix);
    }
    return prefixes;
  }