這是網上已有的分詞函式,先轉過來了解了解。
基礎的分字程式
下面是 carrie (感謝 carrie!:d )寫的乙個基礎的分字程式,在很大程度上可以滿足相當多應用的需要:
---- a basic chinese word segment function
-- author: carrie
--create or replace function carriecharseg( input text ) returns text as $$
declare
retval text;
i int;
j int;
begin
i:= char_length(input);
j:= 0;
retval:= '';
loop
retval:= retval || substring(input from j for 1) || ' ';
j:= j+1;
exit when j=i+1;
end loop;
return retval;
end;
$$language plpgsql;
下面是乙個過載的分詞程式,區分了單詞和漢字,對單詞單獨進行分詞:
---- a basic chinese word segment function
-- author: carrie
--create or replace function carriecharseg(input text,int) returns text as $q$
declare
query text:= '';
retval text:= '';
thisval text:= '';
lastval text:= '';
i integer:= 0;
j integer:= 0;
begin
query:= lower(regexp_replace(input,'[[:punct:]]',' ','g'));
--raise notice '123: %',query;
i:= char_length(query);
loop
thisval:= substring(query from j for 1);
if ((thisval <> ' ')and(thisval <> ' ')) then
if (((lastval >= 'a') and (lastval <= 'z'))
or((lastval >= 'a')and(lastval <= 'z'))) and
(((thisval >= 'a') and (thisval <= 'z')) or
((thisval >= 'a')and(thisval <= 'z'))) then
retval:= retval || thisval;
else
retval:= retval || ' ' || thisval;
end if;
end if;
lastval:= thisval;
j:= j+1;
exit when j > i;
end loop;
return trim(retval);
end$q$language plpgsql;
使用感受:
最近用過了這兩個自定義的分詞函式,簡單的說就是將漢字分割開來,例如:
「我來自地球",通過上面的分詞函式後就變成「我 來 自 地 球」,會在每個字之間加入空格,這種方式比較適合標題式的檢索,因為標題本身的內容不多,這樣輸入乙個字,也是能查詢出來相關的標題資訊的。
如果應用的場景需要很精確的查詢,那麼可以使用這種方式,在呼叫之前做一次轉換。
Python 結巴分詞(1)分詞
利用結巴分詞來進行詞頻的統計,並輸出到檔案中。結巴分詞的特點 支援繁體分詞 支援自定義詞典 mit 授權協議 演算法 分詞引數 使用者詞典 載入詞典 使用者詞典 userdict.dict 雲計算 5 李小福 2 nr 創新辦 3 i easy install 3 eng 好用 300 韓玉賞鑑 3...
mysql 三分分詞 MySQL 中文分詞原理
一,首先我們來了解一下其他幾個知識點 1.mysql的索引意義?索引是加快訪問表內容的基本手段,尤其是在涉及多個表的關聯查詢裡。當然,索引可以加快檢索速度,但是它也同時降低了索引列的插入,刪除和更新值的速度。換通俗的話來講 mysql中的索引就是乙個特殊的平衡二叉樹,當在平衡二叉樹中搜尋某一條值的時...
ICTCLAS2010分詞工具
計算所漢語詞法分析系統 ictclas 中國科學院計算技術研究所在多年研究基礎上,耗時一年研製出了基於多層隱馬模型的漢語詞法分析系統 ictclas institute of computing technology,chinese lexical analysis system 該系統的功能有 中...