// 3: Add <f_i, i, i+1, p_eps> to queue
queue.add(new Tuple(epsilon, i, i, root));
}
if (this.maxNonterminals > 0) { Pattern xpattern = new Pattern(vocab,X);
int start = START_OF_SENTENCE;
if (!sentenceInitialX) start += 1;
// 4: for i from 1 to I
for (int i=start; i<=END_OF_SENTENCE; i++) {
//if (logger.isLoggable(Level.FINEST)) logger.finest("Adding tuple (" + (i-1) + ","+(i)+","+root+",{"+X+","+intToString(sentence[i])+"})");
if (logger.isLoggable(Level.FINEST)) logger.finest("Adding tuple (X," + (i-1) + ","+ i +","+xnode.toShortString(vocab) +")");
// 5: Add <X f_i, i-1, i+1, p_x> to queue
if (edgeXMayViolatePhraseSpan) {
queue.add(new Tuple(xpattern, i, i, xnode));
} else {
queue.add(new Tuple(xpattern, i-1, i, xnode));
}
}
}
// 6: While queue is not empty do
while (! queue.isEmpty()) {
if (logger.isLoggable(Level.FINER)) {
logger.finer("\n");
if (logger.isLoggable(Level.FINEST)) logger.finest("CURRENT TREE: " + root);
}
// 7: Pop <alpha, i, j, p_alphaBeta> from queue
Tuple tuple = queue.remove();
int i = tuple.spanStart;
int j = tuple.spanEnd;
Node prefixNode = tuple.prefixNode;
Pattern prefixPattern = tuple.pattern;
// if (prefixNode.objectID==329 //) {
// || (prefixNode.objectID==28 && i==13 && j==17)) {
// int x = -1;
// x++;
// }
if (logger.isLoggable(Level.FINER)) logger.finer("Have tuple (" +prefixPattern+","+ i + ","+j+","+prefixNode.toShortString(vocab)+")");
if (j <= END_OF_SENTENCE) {
// 8: If p_alphaBetaF_i elementOf children(p_alphaBeta) then
if (prefixNode.hasChild(sentence[j])) {
if (logger.isLoggable(Level.FINER)) logger.finer("EXISTING node for \"" + sentence[j] + "\" from " + prefixNode.toShortString(vocab) + " to node " + prefixNode.getChild(sentence[j]).toShortString(vocab) + " with pattern " + prefixPattern);
// child is p_alphaBetaF_j
Node child = prefixNode.getChild(sentence[j]);
// 9: If p_alphaBetaF_j is inactive then
if (! child.active) {
// 10: Continue to next item in queue
continue;
// 11: Else
} else {
// 12: EXTEND_QUEUE(alpha beta f_j, i, j, f_1^I)
if (logger.isLoggable(Level.FINER)) {
logger.finer("Calling EXTEND_QUEUE("+i+","+j+","+prefixPattern+","+prefixNode.toShortString(vocab));
if (logger.isLoggable(Level.FINEST)) logger.finest("TREE BEFOR EXTEND: " + root);
}
extendQueue(queue, i, j, sentence, new Pattern(prefixPattern,sentence[j]), child);
if (logger.isLoggable(Level.FINEST)) logger.finest("TREE AFTER EXTEND: " + root);
}
} else { // 13: Else
// 14: children(alphaBeta) <-- children(alphaBeta) U p_alphaBetaF_j
// (Add new child node)
if (logger.isLoggable(Level.FINER)) logger.finer("Adding new node to node " + prefixNode.toShortString(vocab));
Node newNode = prefixNode.addChild(sentence[j]);
if (logger.isLoggable(Level.FINER)) {
String word = (suffixArray==null) ? ""+sentence[j] : suffixArray.getVocabulary().getWord(sentence[j]);
logger.finer("Created new node " + newNode.toShortString(vocab) +" for \"" + word + "\" and \n added it to " + prefixNode.toShortString(vocab));
}
// 15: p_beta <-- suffix_link(p_alpha_beta)
// suffixNode in this code is p_beta_f_j, not p_beta
Node suffixNode = prefixNode.calculateSuffixLink(sentence[j]);
if (logger.isLoggable(Level.FINEST)) {
String oldSuffixLink = (newNode.suffixLink==null) ? "null" : "id"+newNode.suffixLink.objectID;
String newSuffixLink = (suffixNode==null) ? "null" : "id"+suffixNode.objectID;
logger.finest("Changing suffix link from " + oldSuffixLink + " to " + newSuffixLink + " for node " + newNode.toShortString(vocab) + " (prefix node " + prefixNode.toShortString(vocab) + " ) with token " + sentence[j]);
}
newNode.linkToSuffix( suffixNode );
// 16: if p_beta_f_j is inactive then
if (! suffixNode.active) {
// 17: Mark p_alpha_beta_f_j inactive
newNode.active = false; //Node.INACTIVE;
// 18: else
} else {
Pattern extendedPattern = new Pattern(prefixPattern,sentence[j]);
MatchedHierarchicalPhrases result = null;
if (suffixArray != null) {