示例#1
0
 protected function loadDict($mss, $key)
 {
     $rs = $this->di['confilter']->sMembers($key);
     foreach ($rs as $value) {
         if (!empty($value)) {
             mss_add($mss, $value);
         }
     }
 }
示例#2
0
文件: Mss.php 项目: tianyunchong/php
 protected function loadDict($mss, $key)
 {
     $redis = \Phalcon\DI::getDefault()->get("redis");
     $rs = $redis->sMembers($key);
     foreach ($rs as $value) {
         if (!empty($value)) {
             //词语转换成大写
             $value = strtolower($value);
             mss_add($mss, $value);
         }
     }
 }
示例#3
0
function load_dict($mss, $filename)
{
    $fp = fopen($filename, "r");
    while (!feof($fp)) {
        $line = trim(fgets($fp));
        $pos = strpos($line, "#");
        if ($pos !== false) {
            $line = strstr($line, 0, $pos);
        }
        if (!$line) {
            continue;
        }
        $line = explode(":", $line, 2);
        if (count($line) == 2) {
            mss_add($mss, trim($line[0]), trim($line[1]));
        } else {
            mss_add($mss, trim($line[0]));
        }
    }
}
示例#4
0
文件: sample.php 项目: noikiy/php-mss
<?php

// header("content-type: text/plain; charset=utf-8");
$mss = mss_create();
mss_add($mss, "安居客", "公司名称");
mss_add($mss, "二手房", "通用名词");
$text = "安居客,是安居客集团旗下国内最大的专业二手房网站。自2007年上线至今的短短4年时间里,安居客凭借其“专业二手房搜索引擎”的核心竞争力在业内独树一帜。通过对用户需求的精准把握、海量的二手房房源、精准的搜索功能、强大的产品研发能力,为用户提供最佳找房体验。目前,安居客的足迹已经遍布全国超过29个城市,注册用户超过1000万。";
echo "Round: 1\n";
$matches = mss_search($mss, $text);
echo "[\n";
foreach ($matches as $match) {
    echo "  ({$match[0]}, {$match[2]}, {$match[1]})\n";
}
echo "]\n";
echo "\n";
echo "Round: 2\n";
echo "[\n";
mss_search($mss, $text, function ($kw, $idx, $type) {
    echo "  ({$kw}, {$idx}, {$type})\n";
});
echo "]\n";
echo "\n";
$matched = mss_match($mss, $text);
echo $matched ? "matched" : "not matched", "\n";