Author: Fukuball Lin (fukuball@gmail.com)
Esempio n. 1
0
 public function getPartofspeech($string)
 {
     Jieba::init();
     Finalseg::init();
     Posseg::init();
     $seg_list = Posseg::cut($string);
     $this->cixing = $seg_list;
     return $seg_list;
 }
Esempio n. 2
0
 public function testFinalsegCut()
 {
     $case_array = array("怜香惜", "玉", "也", "得", "要", "看", "对象", "啊");
     $seg_list = Finalseg::cut("怜香惜玉也得要看对象啊!");
     $this->assertEquals($case_array, $seg_list);
 }
Esempio n. 3
0
 /**
  * Static method __cutDAG
  *
  * @param string $sentence # input sentence
  * @param array  $options  # other options
  *
  * @return array $words
  */
 public static function __cutDAG($sentence, $options = array())
 {
     $defaults = array('mode' => 'default');
     $options = array_merge($defaults, $options);
     $words = array();
     $N = mb_strlen($sentence, 'UTF-8');
     $DAG = self::getDAG($sentence);
     self::calc($sentence, $DAG);
     $x = 0;
     $buf = '';
     while ($x < $N) {
         $current_route_keys = array_keys(self::$route[$x]);
         $y = $current_route_keys[0] + 1;
         $l_word = mb_substr($sentence, $x, $y - $x, 'UTF-8');
         if ($y - $x == 1) {
             $buf = $buf . $l_word;
         } else {
             if (mb_strlen($buf, 'UTF-8') > 0) {
                 if (mb_strlen($buf, 'UTF-8') == 1) {
                     array_push($words, $buf);
                     $buf = '';
                 } else {
                     $regognized = Finalseg::__cut($buf);
                     foreach ($regognized as $key => $word) {
                         array_push($words, $word);
                     }
                     $buf = '';
                 }
             }
             array_push($words, $l_word);
         }
         $x = $y;
     }
     if (mb_strlen($buf, 'UTF-8') > 0) {
         if (mb_strlen($buf, 'UTF-8') == 1) {
             array_push($words, $buf);
         } else {
             $regognized = Finalseg::__cut($buf);
             foreach ($regognized as $key => $word) {
                 array_push($words, $word);
             }
         }
     }
     return $words;
 }
Esempio n. 4
0
#!/usr/bin/php
<?php 
/**
 * demo_posseg.php
 *
 * PHP version 5
 *
 * @category PHP
 * @package  /src/cmd/
 * @author   Fukuball Lin <*****@*****.**>
 * @license  MIT Licence
 * @version  GIT: <fukuball/jieba-php>
 * @link     https://github.com/fukuball/jieba-php
 */
ini_set('memory_limit', '600M');
require_once dirname(dirname(__FILE__)) . "/vendor/multi-array/MultiArray.php";
require_once dirname(dirname(__FILE__)) . "/vendor/multi-array/Factory/MultiArrayFactory.php";
require_once dirname(dirname(__FILE__)) . "/class/Jieba.php";
require_once dirname(dirname(__FILE__)) . "/class/Finalseg.php";
require_once dirname(dirname(__FILE__)) . "/class/Posseg.php";
use Fukuball\Jieba\Jieba;
use Fukuball\Jieba\Finalseg;
use Fukuball\Jieba\Posseg;
Jieba::init();
Finalseg::init();
Posseg::init();
$seg_list = Posseg::cut("这是一个伸手不见五指的黑夜。我叫孙悟空,我爱北京,我爱Python和C++。");
var_dump($seg_list);
$seg_list = Posseg::posTagReadable($seg_list);
var_dump($seg_list);