@@ -0,0 +1,1446 @@
+package me.xiaosheng.util;%0A%0Aimport java.util.LinkedList;%0Aimport java.util.List;%0A%0Aimport com.hankcs.hanlp.*;%0Aimport com.hankcs.hanlp.dictionary.stopword.CoreStopWordDictionary;%0Aimport com.hankcs.hanlp.seg.common.Term;%0A%0Apublic class Segment %7B%0A%0A%09private List%3CTerm%3E termList;%0A%09/**%0A%09 * %E5%88%86%E8%AF%8D%E5%99%A8%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%0A%09 * @param sentence %E8%A6%81%E5%88%86%E8%AF%8D%E7%9A%84%E5%8F%A5%E5%AD%90%0A%09 * @param enableStopWordFilter %E6%98%AF%E5%90%A6%E8%BF%87%E6%BB%A4%E5%81%9C%E7%94%A8%E8%AF%8D%0A%09 */%0A%09public Segment(String sentence, boolean enableStopWordFilter) %7B%0A%09%09termList = HanLP.segment(sentence);%0A%09%09if (enableStopWordFilter) %7B%0A%09%09%09CoreStopWordDictionary.apply(termList);%0A%09%09%7D%0A%09%7D%0A%09/**%0A%09 * %E8%8E%B7%E5%8F%96%E8%AF%8D%E8%AF%AD%E5%88%97%E8%A1%A8%0A%09 * @return%0A%09 */%0A%09public List%3CString%3E getWords() %7B%0A%09%09List%3CString%3E wordList = new LinkedList%3CString%3E();%0A%09%09for (Term wordTerm : termList) %7B%0A%09%09%09wordList.add(wordTerm.word);%0A%09%09%7D%0A%09%09return wordList;%0A%09%7D%0A%09/**%0A%09 * %E8%8E%B7%E5%8F%96%E8%AF%8D%E6%80%A7%E5%88%97%E8%A1%A8%0A%09 * @return%0A%09 */%0A%09public List%3CString%3E getPOS() %7B%0A%09%09List%3CString%3E POSList = new LinkedList%3CString%3E();%0A%09%09for (Term wordTerm : termList) %7B%0A%09%09%09POSList.add(wordTerm.nature.toString());%0A%09%09%7D%0A%09%09return POSList;%0A%09%7D%0A%09%0A%09public float%5B%5D getPOSWeightVector() %7B%0A%09%09float%5B%5D weightVector = new float%5BtermList.size()%5D;%0A%09%09for (int i = 0; i %3C weightVector.length; i++) %7B%0A%09%09%09String POS = termList.get(i).nature.toString();%0A%09%09%09if (POS.charAt(0) == 'n') %7B%0A%09%09%09%09weightVector%5Bi%5D = 1;%0A%09%09%09%7D else if (POS.charAt(0) == 'v') %7B%0A%09%09%09%09weightVector%5Bi%5D = 1;%0A%09%09%09%7D else %7B%0A%09%09%09%09weightVector%5Bi%5D = (float) 0.8;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return weightVector;%0A%09%7D%0A%09@Override%0A%09public String toString() %7B%0A%09%09return termList.toString();%0A%09%7D%0A%7D%0A

add segment util class