/** * [keyword 获取关键词] * @param [type] $text [文本] * @param string $filter [过滤条件] * @return [type] [description] */ public function keyword($text, $filter = '') { $filter = $this->makeFilter($filter); vendor('pscws4.class#pscws4'); $pscws = new PSCWS4(); $pscws->set_charset('utf-8'); $pscws->send_text($text); $some = $pscws->get_tops(10, $filter); $_result = $this->makeAttr($some); $filter_reg = explode(',', str_replace('~', '', $filter)); if (!empty($filter)) { if ($filter != "~") { foreach ($_result as $k => $v) { if (in_array($v['attr'], $filter_reg)) { $_res[] = $v; } } } else { $_res = $_result; } } else { $_res = $_result; } return $_res; }
function get_tags_arr($title) { $pscws = new PSCWS4(); $pscws->set_dict(APP_ROOT . '/scws/dict.utf8.xdb'); $pscws->set_rule(APP_ROOT . '/scws/rules.utf8.ini'); $pscws->set_ignore(true); $pscws->send_text($title); $words = $pscws->get_tops(10); $tags = array(); foreach ($words as $val) { $tags[] = $val['word']; } $pscws->close(); return $tags; }
/** * @param $str 要解析的字符串 * @param $num 获取的词的数量 * @func 实现分词功能 */ public function run($str, $num) { $pscws = new \PSCWS4(); $pscws->set_dict(APP_ROOT . '/dict.utf8.xdb'); $pscws->set_rule(APP_ROOT . '/rules.utf8.ini'); $pscws->set_ignore(true); $pscws->send_text($str); $words = $pscws->get_tops($num); $tags = array(); foreach ($words as $val) { $tags[] = $val['word']; } $pscws->close(); return $tags; }
public function get_tags_by_title($title, $num = 10) { vendor('pscws4.pscws4', '', '.class.php'); $pscws = new PSCWS4(); $pscws->set_dict(PIN_DATA_PATH . 'scws/dict.utf8.xdb'); $pscws->set_rule(PIN_DATA_PATH . 'scws/rules.utf8.ini'); $pscws->set_ignore(true); $pscws->send_text($title); $words = $pscws->get_tops($num); $pscws->close(); $tags = array(); foreach ($words as $val) { $tags[] = $val['word']; } return $tags; }
public function ajax_getKeywords($title, $num = 5) { import('ORG.Pscws.Pscws4'); $pscws = new PSCWS4(); $pscws->set_dict(LIBRARY_PATH . 'ORG/Pscws/dict.utf8.xdb'); $pscws->set_rule(LIBRARY_PATH . 'ORG/Pscws/rules.utf8.ini'); $pscws->set_ignore(true); $pscws->send_text($title); $words = $pscws->get_tops($num); $pscws->close(); $list = array(); foreach ($words as $value) { $list[] = $value['word']; } echo json_encode(array('num' => count($list), 'list' => $list)); }
function getKeyword($title) { require './pscws.class.php'; $pscws = new PSCWS4(); $pscws->set_dict('./scws/dict.utf8.xdb'); $pscws->set_rule('./scws/rules.utf8.ini'); $pscws->set_ignore(true); $pscws->send_text($title); $words = $pscws->get_tops(); $res = ''; foreach ($words as $val) { $res .= '|' . $val['word']; } $pscws->close(); return substr($res, 1); }
public static function segments($arr, $num = 10) { $list = array(); if (empty($text)) { return $list; } $words = array(); //检测是否已安装php_scws扩展 if (function_exists("scws_open")) { $sh = scws_open(); scws_set_charset($sh, 'utf8'); scws_set_dict($sh, APP_ROOT_PATH . 'system/scws/dict.utf8.xdb'); scws_set_rule($sh, APP_ROOT_PATH . 'system/scws/rules.utf8.ini'); scws_set_ignore($sh, true); foreach ($arr as $key => $text) { scws_send_text($sh, $text); $words[] = scws_get_tops($sh, $num); } scws_close($sh); } else { require_once APP_ROOT_PATH . 'system/scws/pscws4.class.php'; $pscws = new PSCWS4(); $pscws->set_dict(APP_ROOT_PATH . 'system/scws/dict.utf8.xdb'); $pscws->set_rule(APP_ROOT_PATH . 'system/scws/rules.utf8.ini'); $pscws->set_ignore(true); foreach ($arr as $key => $text) { $pscws->send_text($text); $words[] = $pscws->get_tops($num); } $pscws->close(); } for ($i = 0; $i < $num; $i++) { foreach ($words as $item) { if (isset($item[$i])) { $word = $item[$i]['word']; if (isset($list[$word])) { $list[$word]++; } else { $list[$word] = 1; } } } } $list = array_slice($list, 0, $num); return array_keys($list); }
function getkeyword($title, $contents = '') { // 加入头文件 require_once 'pscws4.class.php'; // 建立分词类对像, 参数为字符集, 默认为 gbk, 可在后面调用 set_charset 改变 $pscws = new PSCWS4('utf8'); $pscws->set_dict('../function/etc/dict.xdb'); $pscws->set_rule('../function/etc/rules.ini'); $pscws->set_duality(true); $text = $title; $pscws->send_text($text); $tops = $pscws->get_tops(10, ''); foreach ($tops as $k) { $keywords = $keywords . $k[word] . ' '; } return ' ' . trim($keywords); }
public function get_tags_by_title($title, $num = 10) { //vendor('pscws4.pscws4', '', '.class.php'); import("Extend.pscws4.pscws4", APP_PATH . 'Lib/'); ///分组后 /// 分组前 import("@.Extend.pscws4.pscws4"); // dump(APP_PATH . 'Extend/pscws4/scws/dict.utf8.xdb'); $pscws = new \PSCWS4(); $pscws->set_dict(APP_PATH . 'Lib/' . 'Extend/pscws4/scws/dict.utf8.xdb'); $pscws->set_rule(APP_PATH . 'Lib/' . 'Extend/pscws4/scws/rules.utf8.ini'); $pscws->set_ignore(true); $pscws->send_text($title); $words = $pscws->get_tops($num); $pscws->close(); $tags = array(); foreach ($words as $val) { $tags[] = $val['word']; } return $tags; }
public function get_tags($title, $num = 10) { vendor('Pscws.Pscws4', '', '.class.php'); $pscws = new PSCWS4(); $pscws->set_dict(CONF_PATH . 'etc/dict.utf8.xdb'); $pscws->set_rule(CONF_PATH . 'etc/rules.utf8.ini'); $pscws->set_ignore(true); $pscws->send_text($title); $words = $pscws->get_tops($num); $pscws->close(); $tags = array(); foreach ($words as $val) { $tags[] = $val['word']; } return implode(',', $tags); }
function get_keywords($title) { require './Common/scws/pscws4.class.php'; $pscws = new PSCWS4(); $pscws->set_dict('./Common/scws/scws/dict.utf8.xdb'); $pscws->set_rule('./Common/scws/scws/rules.utf8.ini'); $pscws->set_ignore(true); $pscws->send_text($title); $words = $pscws->get_tops(5); $tags = array(); foreach ($words as $val) { $tags[] = $val['word']; } $pscws->close(); return $tags; }
//$cws->set_duality(true); $cws->send_text($text); if (php_sapi_name() != 'cli') { header('Content-Type: text/plain'); } echo "pscws version: ", $cws->version(), "\n"; echo "Segment result:\n\n"; while ($tmp = $cws->get_result()) { $line = ''; foreach ($tmp as $w) { if ($w['word'] == "\r") { continue; } if ($w['word'] == "\n") { $line = rtrim($line, ' ') . "\n"; } else { $line .= $w['word'] . " "; } } echo $line; } // top: echo "Top words stats:\n\n"; $ret = array(); $ret = $cws->get_tops(10, 'r,v,p'); echo "No.\tWord\t\t\tAttr\tTimes\tRank\n------------------------------------------------------\n"; $i = 1; foreach ($ret as $tmp) { printf("%02d.\t%-16s\t%s\t%d\t%.2f\n", $i++, $tmp['word'], $tmp['attr'], $tmp['times'], $tmp['weight']); } $cws->close();
function get_keywords3($title, $num = 10) { $title = urldecode_utf8($title); $title = trim_html($title, 1); if (strlen($title) > 2400) { $title = cutstr($title, 800, ''); } include_once ROOT_PATH . 'web/lib/pscws4/pscws4.class.php'; $cws = new PSCWS4('utf8'); $cws->set_dict(ROOT_PATH . 'web/lib/pscws4/dict.utf8.xdb'); //$cws->set_dict(ROOT_PATH.'web/lib/pscws4/a.xdb'); $cws->set_rule(ROOT_PATH . 'web/lib/pscws4/rules.ini'); //$cws->set_multi(3); $cws->set_ignore(true); //$cws->set_debug(true); //$cws->set_duality(true); $cws->send_text($title); $words = $cws->get_tops(10, 'r,v,p'); $cws->close(); $tags = array(); foreach ($words as $val) { $tags[] = $val['word']; } $tags = implode(',', $tags); return $tags; }
private function get_tags($title, $num = 10) { vendor("Pscws.Pscws4", "", ".class.php"); $pscws = new PSCWS4(); $pscws->set_dict(CONF_PATH . "etc/dict.utf8.xdb"); $pscws->set_rule(CONF_PATH . "etc/rules.utf8.ini"); $pscws->set_ignore(true); $pscws->send_text($title); $words = $pscws->get_tops($num); $pscws->close(); $tags = array(); foreach ($words as $val) { $tags[] = $val["word"]; } return implode(",", $tags); }