コード例 #1
0
 public String getSuffixString() {
   StringBuilder sb = new StringBuilder();
   for (int i = offset; i <= string.length(); i++) {
     sb.append(string.getChar(i));
   }
   return sb.toString();
 }
コード例 #2
0
    public UkkonenState(TreeString str) {
      string = str;

      lastE = 0;
      edgesWithE = new LinkedList<TreeEdge>();
      nextPhaseStart = 0;
      nextExtStart = 0;
      matcher = null;
      nextNode = root;
      gammaLength = 0;
      rule2Node = null;

      if (string.getIndex() > 0) {
        matcher = findEdge(root, string, 0, string.length(), false);
        nextPhaseStart = matcher.matchedTo;
        nextExtStart = 0;
        lastE = matcher.matchedTo;

        logger.log(
            Level.FINEST,
            String.format(
                "String %s can start at phase %d (E:%d)",
                string.toString(), nextPhaseStart, lastE));
      } else {
        matcher = new EdgeMatch(string, 0, string.length());
      }

      currentSuffix = new StringSuffix(string, 0);
    }
コード例 #3
0
  private void naiveExtendSuffixTree(int arrayIdx) {
    TreeString string = strings.get(arrayIdx);

    // the array.length-1 constraint, instead of array.length, is because
    // we assume that the terminal character has already been added to the
    // string, and we don't want to *just* add the suffix that is that
    // character.
    for (int i = 0; i <= string.length(); i++) {
      logger.log(
          Level.FINEST,
          String.format("Naive Extension: \"%s\"", string.substring(i, string.length() + 1)));

      naiveExtendSuffix(string, i);
    }
  }
コード例 #4
0
 public String currentMatchString() {
   if (array != null) {
     return new String(array, matchingFrom, end - matchingFrom);
   } else {
     return string.substring(matchingFrom, end);
   }
 }
コード例 #5
0
 public String matchedString() {
   if (array != null) {
     return new String(array, start, matchedTo - start);
   } else {
     return string.substring(start, matchedTo);
   }
 }
コード例 #6
0
 public String matchingString() {
   if (array != null) {
     return new String(array, start, end - start);
   } else {
     return string.substring(start, end);
   }
 }
コード例 #7
0
 public int hashCode() {
   int code = 17;
   code += string.hashCode();
   code *= 37;
   code += offset;
   code *= 37;
   return code;
 }
コード例 #8
0
    public int countMatches(TreeString str, int startMatch, int endMatch) {
      int ei = start;
      int mi = startMatch;
      int eend = end();

      for (; ei < eend && mi < endMatch; ei++, mi++) {
        if (!string.matches(ei, str, mi)) {
          return ei - start;
        }
      }
      return ei - start;
    }
コード例 #9
0
  private void naiveExtendSuffix(TreeString string, int start) {
    EdgeMatch em = findEdge(root, string, start, string.length(), false);
    StringSuffix stringSuffix = new StringSuffix(string, start);

    TreeEdge leafEdge = null;
    if (em.completedMatch()) {
      leafEdge = em.lastEdge;
    } else {
      if (em.lastEdge == null) {
        leafEdge = new TreeEdge(string, start, string.length(), root);
        root.addEdge(leafEdge);
      } else {
        leafEdge = new TreeEdge(string, em.matchedTo, string.length(), em.lastEdge.tailNode);
        if (em.inEdgeMiddle()) {
          int offset = em.lastMatchLength();
          em.lastEdge.split(offset);
        }
        em.lastEdge.tailNode.addEdge(leafEdge);
      }
    }

    leafEdge.tailNode.suffixes.add(stringSuffix);
  }
コード例 #10
0
    public int countMatches(char[] array, int startMatch, int endMatch) {
      int ei = start;
      int mi = startMatch;
      int eend = end();

      for (; ei < eend && mi < endMatch; ei++, mi++) {
        assert mi >= 0;
        assert mi < array.length;

        if (array[mi] != string.getChar(ei)) {
          return ei - start;
        }
      }
      return ei - start;
    }
コード例 #11
0
 public char getChar(int i) {
   return array != null ? array[i] : string.getChar(i);
 }
コード例 #12
0
 public int getStringIndex() {
   return string.getIndex();
 }
コード例 #13
0
 public String getSubstring() {
   return string.substring(start(), end());
 }
コード例 #14
0
 public boolean isTerminal() {
   return start == string.length();
 }
コード例 #15
0
 public char getChar(int offset) {
   return string.getChar(start + offset);
 }