function expandSeqTree()

in src/models/SentenTreeModel.js [85:154]


function expandSeqTree(rootSeq, graphs, expandCnt, minSupport, maxSupport, terms, itemset) {
  if (rootSeq.words && rootSeq.words.length > 0) {
    rootSeq.graph.nodes = rootSeq.graph.nodes.concat(rootSeq.words);
    expandCnt -= rootSeq.words.length;
  }

  /* Create a max heap */
  const seqs = new Heap((a, b) => b.size - a.size);
  seqs.push(rootSeq);
  const leafSeqs = [];

  while (!seqs.empty() && expandCnt > 0) {
    /* find the candidate sequence with largest support DB */
    const s = seqs.pop();
    let graph = s.graph;
    let s0 = s.r;
    let s1 = s.l;

    if (!s0 && !s1) {
      /* find the next frequent sequence */
      const result = growSeq(s, terms, minSupport, maxSupport, itemset);
      s0 = result.s0;
      s1 = result.s1;
      const { word, pos, count } = result;

      if (count < minSupport) {
        leafSeqs.push(s);
      } else {
        /* create new sequences and add new word */
        if (!graph) {
          graph = new RawGraph(minSupport, maxSupport);
          graphs.push(graph);
        }
        const newWord = {
          id: graph.totalNodeCnt++,
          entity: itemset[word],
          freq: count,
          topEntries: s1.DBs.slice(0, 5),
          seq: s1,
        };
        const newWords = s.words.slice();
        newWords.splice(pos, 0, newWord);
        s0.words = s.words;
        s1.words = newWords;
        s1.newWord = newWord;
        s0.graph = s.graph;
        s1.graph = graph;
      }
    }

    if (s1) {
      s1.graph.nodes.push(s1.newWord);
      expandCnt--;
    }

    /* add new sequences to seqTree */
    s.l = s1;
    s.r = s0;

    /* add new sequences to candidates */
    if (s1) {
      seqs.push(s1);
    }
    if (s0 && s0.size >= minSupport) {
      seqs.push(s0);
    }
  }

  return leafSeqs.concat(seqs.toArray());
}