Пример #1
0
  protected boolean hasBackwardExtensionItem(SequenceDatabase<T> sdb) {
    List<T> prefix = sdb.getPrefix();
    prefix_loop:
    for (int i = 0; i < prefix.size(); i++) {
      Set<T> intersection = null;

      for (Sequence<T> sequence : sdb.getSequences()) {
        List<T> mp_i = sequence.getMaximumPeriodOf(prefix, i);
        if (mp_i == null || mp_i.isEmpty()) {
          continue prefix_loop;
        }

        if (intersection == null) {
          intersection = new HashSet<T>(mp_i);
        } else {
          intersection.retainAll(mp_i);
          if (intersection.isEmpty()) {
            continue prefix_loop;
          }
        }
      }

      if (logger.isTraceEnabled()) {
        logger.trace(
            "Open: The prefix can be extended by backward extension items {}, found in each of the {} maximum period.",
            intersection,
            toOrdinal(i));
      }
      return true;
    }
    return false;
  }
Пример #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;
  }
Пример #3
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;
  }
Пример #4
0
  protected boolean backScan(SequenceDatabase<T> sdb) {
    List<T> prefix = sdb.getPrefix();
    prefix_loop:
    for (int i = 0; i < prefix.size(); i++) {
      Set<T> intersection = null;

      for (Sequence<T> sequence : sdb.getSequences()) {
        List<T> smp_i = sequence.getSemiMaximumPeriodOf(prefix, i);
        if (smp_i == null || smp_i.isEmpty()) {
          continue prefix_loop;
        }

        if (intersection == null) {
          intersection = new HashSet<T>(smp_i);
        } else {
          intersection.retainAll(smp_i);
          if (intersection.isEmpty()) {
            continue prefix_loop;
          }
        }
      }

      if (logger.isTraceEnabled()) {
        logger.trace(
            "Pruned: Search space was pruned by the BackScan method. Items {} exists in each of the {} semi-maximum period.",
            intersection,
            toOrdinal(i));
      }
      return true;
    }
    return false;
  }