WordSpliter.cs 786 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace Ant.Service.Utilities
  6. {
  7. /// <summary>
  8. /// 分词类
  9. /// </summary>
  10. public static class WordSpliter
  11. {
  12. /// <summary>
  13. /// 得到分词关键字
  14. /// </summary>
  15. /// <param name="key"></param>
  16. /// <returns></returns>
  17. public static string GetKeyword(string key, string splitchar)
  18. {
  19. Segment seg = new Segment();
  20. seg.InitWordDics();
  21. seg.EnablePrefix = true;
  22. seg.Separator = splitchar;
  23. return seg.SegmentText(key, false).Trim();
  24. }
  25. public static string GetKeyword(string key)
  26. {
  27. return GetKeyword(key, " ");
  28. }
  29. }
  30. }