在 Xunsearch 使用 SCWS

创建分词对象

$xs = new XS('my');  // 必须先创建一个 xs 实例,否则会抛出异常
$tokenizer = new XSTokenizerScws;   // 直接创建实例

获取分词结果

$xs = new XS('my');  // 必须先创建一个 xs 实例,否则会抛出异常
$tokenizer = new XSTokenizerScws();   // 直接创建实例
$text = '上海人民公园';
$words = $tokenizer->getResult($text);
print_r($words);
Array
(
    [0] => Array
        (
            [off] => 0
            [attr] => ns  
            [word] => 上海
        )

    [1] => Array
        (
            [off] => 6
            [attr] => n   
            [word] => 人民
        )

    [2] => Array
        (
            [off] => 12
            [attr] => n   
            [word] => 公园
        )

)

提取重要词汇

$xs = new XS('my');  // 必须先创建一个 xs 实例,否则会抛出异常
$tokenizer = new XSTokenizerScws();   // 直接创建实例
$text = '上海人民公园';
$tops = $tokenizer->getTops($text, 5, 'n,v,vn');
print_r($tops);