import java.util.List; import org.junit.Test; import com.hankcs.hanlp.HanLP; import com.hankcs.hanlp.dictionary.CustomDictionary; import com.hankcs.hanlp.seg.Segment; import com.hankcs.hanlp.seg.common.Term; public class test{ @Test public void TestA(){ String lineStr = "明天虽然会下雨,但是我还是会看周杰伦的演唱会。"; try{ Segment segment = HanLP.newSegment(); segment.enableCustomDictionary(true); /** * 自定义分词+词性 */ CustomDictionary.add("虽然会","ng 0"); List seg = segment.seg(lineStr); for (Term term : seg) { System.out.println(term.toString()); } }catch(Exception ex){ System.out.println(ex.getClass()+","+ex.getMessage()); } } }