hanlp中文智能分詞自動識別文字提取實例

 

需求:客戶給銷售員本身的我的信息,銷售幫助客戶下單,此過程須要銷售人員手動複製粘貼收穫地址,電話,姓名等等,一個智能的分詞系統可讓銷售人員一鍵識別以上各類信息spa

通過調研,找到了一下開源項目it

一、word 分詞器List

二、ansj 分詞器下載

三、mmseg4j 分詞器im

四、ik-analyzer 分詞器qq

五、jcseg 分詞器項目

六、fudannlp 分詞器word

七、smartcn 分詞器co

八、jieba 分詞器數字

九、stanford 分詞器

十、hanlp 分詞器

 

最後選擇了hanlp,步驟官網都有,下面演示智能匹配地址

1   List<Term> list = HanLP.newSegment().seg("湯姆江西省南昌市紅谷灘新區111號電話12023232323");

2    System.out.println(list);

 

輸出

 

1   [湯姆/nrf, 江西省/ns, 南昌市/ns, 紅谷灘/nz, 新區/n, 111/m, 號/q, 電話/n, 12023232323/m]

 

大公告成,不過前提必須下載那個600多M的data包並導入,才能夠識別地址,不然只是作了初步的識別

附上完整代碼

 

   1     String str = "湯姆   江西省南昌市紅谷灘新區111號     12023232323";

   2     String address = "";

   3     String phone = "";

   4     String name = "";

   5     List<Term> terms = NLPTokenizer.segment(str);

   6     System.out.println(terms);

   7     for (Term term : terms) {

   8         if (term.nature.startsWith("nr")){

   9             //nr表明人名

   10             name = term.word;

   11             System.out.println("name: " + term.word);

   12         }else if (term.nature.startsWith("m") && term.word.length() == 11){

   13             //m表明數字

    14            phone = term.word;

    15            System.out.println("電話: " + term.word);

    16        }

    17    }

 

    18    //因爲地址包含了數字,解析的時候數字成爲單獨的個體,與實際不符,因此經過差集求出地址

    19    address = str.replace(phone, "").replace(name, "").trim();

    20    System.out.println("address: " + address);

 

運行結果

 

1    name: 湯姆

2    電話: 12023232323

3    address: 江西省南昌市紅谷灘新區111號

---------------------

做者:qq37755661

相關文章
相關標籤/搜索