ParticipleUtil.java 868 B

1234567891011121314151617181920212223242526272829
  1. package com.jd.util;
  2. import org.wltea.analyzer.core.IKSegmenter;
  3. import org.wltea.analyzer.core.Lexeme;
  4. import java.io.IOException;
  5. import java.io.StringReader;
  6. public class ParticipleUtil {
  7. public static String parse(String content, boolean useSmart) throws IOException {
  8. StringReader sr = new StringReader(content);
  9. // 参数2为是否使用智能分词
  10. // true:使用智能分词
  11. // false:使用最细粒度分词
  12. IKSegmenter ikSegmenter = new IKSegmenter(sr, useSmart);
  13. Lexeme word = null;
  14. String w = null;
  15. StringBuffer sb = new StringBuffer();
  16. while((word = ikSegmenter.next()) != null){
  17. w = word.getLexemeText();
  18. if(sb.length() > 0){
  19. sb.append("|");
  20. }
  21. sb.append(w);
  22. }
  23. return sb.toString();
  24. }
  25. }