蒙狼科技logo
          設(shè)為首頁| 聯(lián)系我們
          咨詢熱線: 13917498722
            您的位置: 首頁 > 網(wǎng)站資訊 > 一個(gè)用PHP寫的中文分詞函數(shù)

          一個(gè)用PHP寫的中文分詞函數(shù)

          發(fā)布日期:2017/9/1

           

          <?php

          class Segmentation {
          var $options = array('lowercase' => TRUE,
          'segment_english' => FALSE);
          var $dict_name = 'Unknown';
          var $dict_words = array();
          function setLowercase($value) {
          if ($value) {
          $this->options['lowercase'] = TRUE;
          } else {
          $this->options['lowercase'] = FALSE;
          }
          return TRUE;
          }
          function setSegmentEnglish($value) {
          if ($value) {
          $this->options['segment_english'] = TRUE;
          } else {
          $this->options['segment_english'] = FALSE;
          }
          return TRUE;
          }
          function load($dict_file) {
          if (!file_exists($dict_file)) {
          return FALSE;
          }
          $fp = fopen($dict_file, 'r');
          $temp = fgets($fp, 1024);
          if ($temp === FALSE) {
          return FALSE;
          } else {
          if (strpos($temp, "t") !== FALSE) {
          list ($dict_type, $dict_name) = explode("t", trim($temp));
          } else {
          $dict_type = trim($temp);
          $dict_name = 'Unknown';
          }
          $this->dict_name = $dict_name;
          if ($dict_type !== 'DICT_WORD_W') {
          return FALSE;
          }
          }
          while (!feof($fp)) {
          $this->dict_words[rtrim(fgets($fp, 32))] = 1;
          }
          fclose($fp);
          return TRUE;
          }
          function getDictName() {
          return $this->dict_name;
          }
          function segmentString($str) {
          if (count($this->dict_words) === 0) {
          return FALSE;
          }
          $lines = explode("n", $str);
          return $this->_segmentLines($lines);
          }
          function segmentFile($filename) {
          if (count($this->dict_words) === 0) {
          return FALSE;
          }
          $lines = file($filename);
          return $this->_segmentLines($lines);
          }
          function _segmentLines($lines) {
          $contents_segmented = '';
          foreach ($lines as $line) {
          $contents_segmented .= $this->_segmentLine(rtrim($line)) . " n";
          }
          do {
          $contents_segmented = str_replace(' ', ' ', $contents_segmented);
          } while (strpos($contents_segmented, ' ') !== FALSE);
          return $contents_segmented;?>





          其他相關(guān)文章
        1. 企業(yè)公司進(jìn)行網(wǎng)站建設(shè)前提預(yù)備資料
        2. BAOCMS未來O2O系統(tǒng)生態(tài)鏈規(guī)劃藍(lán)圖
        3. 從21日DNS解析故障談及網(wǎng)站安全穩(wěn)定的主要性
        4. 淺析Discuz出現(xiàn)“內(nèi)部錯(cuò)誤,無法顯示此內(nèi)容”的
        5. 網(wǎng)絡(luò)營(yíng)銷有哪些細(xì)分種類
        6. 做網(wǎng)站設(shè)計(jì)要做好站內(nèi)搜索的兩個(gè)方面




        7. 企業(yè)網(wǎng)站后臺(tái)使用
          購(gòu)物網(wǎng)站后臺(tái)使用
          網(wǎng)站產(chǎn)品圖片的處理



          農(nóng)業(yè)銀行支付
          建設(shè)銀行支付
          郵政儲(chǔ)蓄銀行支付



          企業(yè)網(wǎng)站建設(shè)
          整站建設(shè)
          購(gòu)物網(wǎng)站



          企業(yè)網(wǎng)站建設(shè)建議
          注冊(cè)適合自己的域名
          什么是虛擬主機(jī)




          售前咨詢QQ: 838821345
          售后服務(wù)QQ: 464698733
          應(yīng)急手機(jī):13917498722


          微信掃一掃
          添加24小時(shí)微信客服


          郵箱:lang@MENGL.CN
          地址:上海寶山區(qū)城銀路555弄2號(hào)樓3樓
          ICP備案:滬ICP備12042844號(hào)-3
           滬公網(wǎng)安備:31011402002917號(hào)
          做網(wǎng)站 | 企業(yè)網(wǎng)站建設(shè) | 上海做網(wǎng)站 | 企業(yè)網(wǎng)站制作 | 做網(wǎng)站的公司 | 關(guān)于蒙狼 | 整站建設(shè) | 購(gòu)物網(wǎng)站 | 企業(yè)網(wǎng)絡(luò)營(yíng)銷 | 成功案例 | 加盟代理 | 在線訂單
          服務(wù)區(qū)域: 臨港新區(qū)做網(wǎng)站 徐匯做網(wǎng)站 閔行做網(wǎng)站 長(zhǎng)寧做網(wǎng)站 虹口做網(wǎng)站 黃浦做網(wǎng)站 盧灣做網(wǎng)站 靜安做網(wǎng)站 浦東做網(wǎng)站 楊浦做網(wǎng)站 普陀做網(wǎng)站 閘北做網(wǎng)站 寶山做網(wǎng)站 嘉定做網(wǎng)站 松江做網(wǎng)站 昆山做網(wǎng)站
          Copyright 2012-2025 上海蒙狼網(wǎng)絡(luò)科技有限公司 www.dayulega.com All Rights Reserved
          主站蜘蛛池模板: 峨边| 延津县| 玛纳斯县| 冀州市| 承德县| 大渡口区| 晋州市| 封丘县| 丰都县| 额敏县| 张北县| 孟州市| 蓬莱市| 浦北县| 宜章县| 慈溪市| 永泰县| 天津市| 略阳县| 静宁县| 阿克苏市| 子洲县| 镇远县| 齐河县| 枣庄市| 彩票| 涟源市| 赣榆县| 汕头市| 平阳县| 岐山县| 介休市| 无棣县| 彭阳县| 隆化县| 信丰县| 巨野县| 井研县| 香格里拉县| 淄博市| 普宁市|