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();
}
Aggregations