public void fromText(String text) {
        String str;
        Occurrence occ;
        List<Term> terms = new ArrayList<Term>();
        StringBuilder sb = new StringBuilder();
        for (List<Term> sentence : seg2sentence(text)) {
            totalTerm += sentence.size();

            // 产生ngram, 总串长度不超过length
            for (int i = 0, j, len = sentence.size(); i < len; ++i) {
                for (j = i; j < len; ++j) {
                    str = sentence.get(j).getRealName();
                    if (termMap.containsKey(str)) {
                        termMap.put(str, termMap.get(str) + 1);
                    } else {
                        addTerm(str);
                    }

                    sb.append(str);
                    if (length < sb.length()) {
                        break;
                    }

                    terms.add(sentence.get(j));

                    str = sb.toString();
                    occ = occurrenceMap.containsKey(str) ? occurrenceMap.get(str) : new Occurrence(new ArrayList<Term>(terms));

                    // 添加左邻项
                    if (0 < i) {
                        occ.addLeftTerm(sentence.get(i - 1).getRealName());
                    }

                    // 添加右临项
                    if (j < len - 1) {
                        occ.addRightTerm(sentence.get(j + 1).getRealName());
                    }

                    // 递增出现频次
                    occ.increaseFrequency();

                    //
                    if (occ.getFrequency() == 1) {
                        addOccurrence(str, occ);
                    }
                }

                //
                terms.clear();
                sb.delete(0, sb.length());
            }
        }
    }
public void fromText ( String text ) { String str ; Occurrence occ ; List < Term > terms = new ArrayList < Term > ( ) ; StringBuilder sb = new StringBuilder ( ) ; for ( List < Term > sentence : seg2sentence ( text ) ) { totalTerm += sentence . size ( ) ; for ( int i = 0 , j , len = sentence . size ( ) ; i < len ; ++ i ) { for ( j = i ; j < len ; ++ j ) { str = sentence . get ( j ) . getRealName ( ) ; if ( termMap . containsKey ( str ) ) { termMap . put ( str , termMap . get ( str ) + 1 ) ; } else { addTerm ( str ) ; } sb . append ( str ) ; if ( length < sb . length ( ) ) { break ; } terms . add ( sentence . get ( j ) ) ; str = sb . toString ( ) ; occ = occurrenceMap . containsKey ( str ) ? occurrenceMap . get ( str ) : new Occurrence ( new ArrayList < Term > ( terms ) ) ; if ( 0 < i ) { occ . addLeftTerm ( sentence . get ( i - 1 ) . getRealName ( ) ) ; } if ( j < len - 1 ) { occ . addRightTerm ( sentence . get ( j + 1 ) . getRealName ( ) ) ; } occ . increaseFrequency ( ) ; if ( occ . getFrequency ( ) == 1 ) { addOccurrence ( str , occ ) ; } } terms . clear ( ) ; sb . delete ( 0 , sb . length ( ) ) ; } } }
从文本中提取子串

@param text