Search in sources :

Example 1 with SmartGetWord

use of org.nlpcn.commons.lang.tire.SmartGetWord in project ansj_seg by NLPchina.

the class TagContent method tagContent.

public String tagContent(List<Keyword> keyWords, String content) {
    SmartForest<Double> sf = new SmartForest<Double>();
    for (Keyword keyWord : keyWords) {
        sf.add(keyWord.getName().toLowerCase(), keyWord.getScore());
    }
    SmartGetWord<Double> sgw = new SmartGetWord<Double>(sf, content.toLowerCase());
    int beginOffe = 0;
    String temp = null;
    StringBuilder sb = new StringBuilder();
    while ((temp = sgw.getFrontWords()) != null) {
        sb.append(content.substring(beginOffe, sgw.offe));
        sb.append(beginTag);
        sb.append(content.substring(sgw.offe, sgw.offe + temp.length()));
        sb.append(endTag);
        beginOffe = sgw.offe + temp.length();
    }
    if (beginOffe <= content.length() - 1) {
        sb.append(content.substring(beginOffe, content.length()));
    }
    return sb.toString();
}
Also used : SmartForest(org.nlpcn.commons.lang.tire.domain.SmartForest) Keyword(org.ansj.app.keyword.Keyword) SmartGetWord(org.nlpcn.commons.lang.tire.SmartGetWord)

Aggregations

Keyword (org.ansj.app.keyword.Keyword)1 SmartGetWord (org.nlpcn.commons.lang.tire.SmartGetWord)1 SmartForest (org.nlpcn.commons.lang.tire.domain.SmartForest)1