demo.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: tanszhe
  5. * Date: 2017/12/25
  6. * Time: 下午7:46
  7. */
  8. //定义词典文件路径
  9. require __DIR__.'/Lib/VicWord.php';
  10. use Lizhichao\Word\VicWord;
  11. //type: 词典格式
  12. $fc = new VicWord();
  13. //长度优先分词
  14. $ar = $fc->getWord('聚知台是一个及时沟通工具');
  15. //细切分
  16. $ar = $fc->getShortWord('聚知台是一个及时沟通工具');
  17. //自动 这种方法最耗时
  18. $ar = $fc->getAutoWord('聚知台是一个及时沟通工具');
  19. print_r($ar);
  20. /*
  21. Array
  22. (
  23. [0] => Array
  24. (
  25. [0] => 聚知台 //词语
  26. [1] => 8 //词语的位置 utf-8编码
  27. [2] => //词性 tip:词库里面没有词性 欢迎大家添加
  28. [3] => 1 // 1 词典含有该词语 0没有该词语
  29. )
  30. [1] => Array
  31. (
  32. [0] => 是
  33. [1] => 10
  34. [2] =>
  35. [3] => 1
  36. )
  37. [2] => Array
  38. (
  39. [0] => 一个
  40. [1] => 16
  41. [2] =>
  42. [3] => 1
  43. )
  44. [3] => Array
  45. (
  46. [0] => 及时
  47. [1] => 23
  48. [2] =>
  49. [3] => 1
  50. )
  51. [4] => Array
  52. (
  53. [0] => 沟通
  54. [1] => 29
  55. [2] =>
  56. [3] => 1
  57. )
  58. [5] => Array
  59. (
  60. [0] => 工具
  61. [1] => 36
  62. [2] =>
  63. [3] => 1
  64. )
  65. )
  66. */