word分词器、ansj分词器、mmseg4j分词器、ik-analyzer分词器分词效果评估

word分词是一个Java实现的中文分词组件,提供了多种基于词典的分词算法,并利用ngram模型来消除歧义。 能准确识别英文、数字,以及日期、时间等数量词,能识别人名、地名、组织机构名等未登录词。 同时提供了Lucene、Solr、ElasticSearch插件。

 

word分词器分词效果评估主要评估下面7种分词算法:

 

正向最大匹配算法:MaximumMatching
逆向最大匹配算法:ReverseMaximumMatching
正向最小匹配算法:MinimumMatching
逆向最小匹配算法:ReverseMinimumMatching
双向最大匹配算法:BidirectionalMaximumMatching
双向最小匹配算法:BidirectionalMinimumMatching
双向最大最小匹配算法:BidirectionalMaximumMinimumMatching

 

所有的双向算法都使用ngram来消歧,分词效果评估分别评估bigramtrigram

 

评估采用的测试文本有253 3709行,共2837 4490个字符,标准文本和测试文本一行行对应,标准文本中的词以空格分隔,评估标准为严格一致,评估核心代码如下:

 

Java代码   收藏代码
  1. /** 
  2.  * 分词效果评估 
  3.  * @param resultText 实际分词结果文件路径 
  4.  * @param standardText 标准分词结果文件路径 
  5.  * @return 评估结果 
  6.  */  
  7. public static EvaluationResult evaluation(String resultText, String standardText) {  
  8.     int perfectLineCount=0;  
  9.     int wrongLineCount=0;  
  10.     int perfectCharCount=0;  
  11.     int wrongCharCount=0;  
  12.     try(BufferedReader resultReader = new BufferedReader(new InputStreamReader(new FileInputStream(resultText),"utf-8"));  
  13.         BufferedReader standardReader = new BufferedReader(new InputStreamReader(new FileInputStream(standardText),"utf-8"))){  
  14.         String result;  
  15.         while( (result = resultReader.readLine()) != null ){  
  16.             result = result.trim();  
  17.             String standard = standardReader.readLine().trim();  
  18.             if(result.equals("")){  
  19.                 continue;  
  20.             }  
  21.             if(result.equals(standard)){  
  22.                 //分词结果和标准一模一样  
  23.                 perfectLineCount++;  
  24.                 perfectCharCount+=standard.replaceAll("\\s+""").length();  
  25.             }else{  
  26.                 //分词结果和标准不一样  
  27.                 wrongLineCount++;  
  28.                 wrongCharCount+=standard.replaceAll("\\s+""").length();  
  29.             }  
  30.         }  
  31.     } catch (IOException ex) {  
  32.         LOGGER.error("分词效果评估失败:", ex);  
  33.     }  
  34.     int totalLineCount = perfectLineCount+wrongLineCount;  
  35.     int totalCharCount = perfectCharCount+wrongCharCount;  
  36.     EvaluationResult er = new EvaluationResult();  
  37.     er.setPerfectCharCount(perfectCharCount);  
  38.     er.setPerfectLineCount(perfectLineCount);  
  39.     er.setTotalCharCount(totalCharCount);  
  40.     er.setTotalLineCount(totalLineCount);  
  41.     er.setWrongCharCount(wrongCharCount);  
  42.     er.setWrongLineCount(wrongLineCount);       
  43.     return er;  
  44. }  

 

Java代码   收藏代码
  1. /** 
  2.  * 中文分词效果评估结果 
  3.  * @author 杨尚川 
  4.  */  
  5. public class EvaluationResult implements Comparable{  
  6.     private int totalLineCount;  
  7.     private int perfectLineCount;  
  8.     private int wrongLineCount;  
  9.     private int totalCharCount;  
  10.     private int perfectCharCount;  
  11.     private int wrongCharCount;  
  12.   
  13.       
  14.     public float getLinePerfectRate(){  
  15.         return perfectLineCount/(float)totalLineCount*100;  
  16.     }  
  17.     public float getLineWrongRate(){  
  18.         return wrongLineCount/(float)totalLineCount*100;  
  19.     }  
  20.     public float getCharPerfectRate(){  
  21.         return perfectCharCount/(float)totalCharCount*100;  
  22.     }  
  23.     public float getCharWrongRate(){  
  24.         return wrongCharCount/(float)totalCharCount*100;  
  25.     }  
  26.     public int getTotalLineCount() {  
  27.         return totalLineCount;  
  28.     }  
  29.     public void setTotalLineCount(int totalLineCount) {  
  30.         this.totalLineCount = totalLineCount;  
  31.     }  
  32.     public int getPerfectLineCount() {  
  33.         return perfectLineCount;  
  34.     }  
  35.     public void setPerfectLineCount(int perfectLineCount) {  
  36.         this.perfectLineCount = perfectLineCount;  
  37.     }  
  38.     public int getWrongLineCount() {  
  39.         return wrongLineCount;  
  40.     }  
  41.     public void setWrongLineCount(int wrongLineCount) {  
  42.         this.wrongLineCount = wrongLineCount;  
  43.     }  
  44.     public int getTotalCharCount() {  
  45.         return totalCharCount;  
  46.     }  
  47.     public void setTotalCharCount(int totalCharCount) {  
  48.         this.totalCharCount = totalCharCount;  
  49.     }  
  50.     public int getPerfectCharCount() {  
  51.         return perfectCharCount;  
  52.     }  
  53.     public void setPerfectCharCount(int perfectCharCount) {  
  54.         this.perfectCharCount = perfectCharCount;  
  55.     }  
  56.     public int getWrongCharCount() {  
  57.         return wrongCharCount;  
  58.     }  
  59.     public void setWrongCharCount(int wrongCharCount) {  
  60.         this.wrongCharCount = wrongCharCount;  
  61.     }  
  62.     @Override  
  63.     public String toString(){  
  64.         return segmentationAlgorithm.name()+"("+segmentationAlgorithm.getDes()+"):"  
  65.                 +"\n"  
  66.                 +"分词速度:"+segSpeed+" 字符/毫秒"  
  67.                 +"\n"  
  68.                 +"行数完美率:"+getLinePerfectRate()+"%"  
  69.                 +"  行数错误率:"+getLineWrongRate()+"%"  
  70.                 +"  总的行数:"+totalLineCount  
  71.                 +"  完美行数:"+perfectLineCount  
  72.                 +"  错误行数:"+wrongLineCount  
  73.                 +"\n"  
  74.                 +"字数完美率:"+getCharPerfectRate()+"%"  
  75.                 +" 字数错误率:"+getCharWrongRate()+"%"  
  76.                 +" 总的字数:"+totalCharCount  
  77.                 +" 完美字数:"+perfectCharCount  
  78.                 +" 错误字数:"+wrongCharCount;  
  79.     }  
  80.     @Override  
  81.     public int compareTo(Object o) {  
  82.         EvaluationResult other = (EvaluationResult)o;  
  83.         if(other.getLinePerfectRate() - getLinePerfectRate() > 0){  
  84.             return 1;  
  85.         }  
  86.         if(other.getLinePerfectRate() - getLinePerfectRate() < 0){  
  87.             return -1;  
  88.         }  
  89.         return 0;  
  90.     }  
  91. }  

 

word分词使用trigram评估结果:

 

Java代码   收藏代码
  1. BidirectionalMaximumMinimumMatching(双向最大最小匹配算法):  
  2. 分词速度:265.62566 字符/毫秒  
  3. 行数完美率:55.352688%  行数错误率:44.647312%  总的行数:2533709  完美行数:1402476  错误行数:1131233  
  4. 字数完美率:46.23227% 字数错误率:53.76773% 总的字数:28374490 完美字数:13118171 错误字数:15256319  
  5.   
  6. BidirectionalMaximumMatching(双向最大匹配算法):  
  7. 分词速度:335.62155 字符/毫秒  
  8. 行数完美率:50.16934%  行数错误率:49.83066%  总的行数:2533709  完美行数:1271145  错误行数:1262564  
  9. 字数完美率:40.692997% 字数错误率:59.307003% 总的字数:28374490 完美字数:11546430 错误字数:16828060  
  10.   
  11. ReverseMaximumMatching(逆向最大匹配算法):  
  12. 分词速度:686.71045 字符/毫秒  
  13. 行数完美率:46.723125%  行数错误率:53.27688%  总的行数:2533709  完美行数:1183828  错误行数:1349881  
  14. 字数完美率:36.67598% 字数错误率:63.32402% 总的字数:28374490 完美字数:10406622 错误字数:17967868  
  15.   
  16. MaximumMatching(正向最大匹配算法):  
  17. 分词速度:733.9535 字符/毫秒  
  18. 行数完美率:46.661713%  行数错误率:53.338287%  总的行数:2533709  完美行数:1182272  错误行数:1351437  
  19. 字数完美率:36.72861% 字数错误率:63.271393% 总的字数:28374490 完美字数:10421556 错误字数:17952934  
  20.   
  21. BidirectionalMinimumMatching(双向最小匹配算法):  
  22. 分词速度:432.87375 字符/毫秒  
  23. 行数完美率:45.863907%  行数错误率:54.136093%  总的行数:2533709  完美行数:1162058  错误行数:1371651  
  24. 字数完美率:35.942123% 字数错误率:64.05788% 总的字数:28374490 完美字数:10198395 错误字数:18176095  
  25.   
  26. ReverseMinimumMatching(逆向最小匹配算法):  
  27. 分词速度:1033.58636 字符/毫秒  
  28. 行数完美率:41.776066%  行数错误率:58.223934%  总的行数:2533709  完美行数:1058484  错误行数:1475225  
  29. 字数完美率:31.678978% 字数错误率:68.32102% 总的字数:28374490 完美字数:8988748 错误字数:19385742  
  30.   
  31. MinimumMatching(正向最小匹配算法):  
  32. 分词速度:1175.4431 字符/毫秒  
  33. 行数完美率:36.853836%  行数错误率:63.146164%  总的行数:2533709  完美行数:933769  错误行数:1599940  
  34. 字数完美率:26.859812% 字数错误率:73.14019% 总的字数:28374490 完美字数:7621334 错误字数:20753156  

 

 word分词使用bigram评估结果:

 

Java代码   收藏代码
  1. BidirectionalMaximumMinimumMatching(双向最大最小匹配算法):  
  2. 分词速度:233.49121 字符/毫秒  
  3. 行数完美率:55.31531%  行数错误率:44.68469%  总的行数:2533709  完美行数:1401529  错误行数:1132180  
  4. 字数完美率:45.834396% 字数错误率:54.165604% 总的字数:28374490 完美字数:13005277 错误字数:15369213  
  5.   
  6. BidirectionalMaximumMatching(双向最大匹配算法):  
  7. 分词速度:303.59401 字符/毫秒  
  8. 行数完美率:52.007233%  行数错误率:47.992767%  总的行数:2533709  完美行数:1317712  错误行数:1215997  
  9. 字数完美率:42.424194% 字数错误率:57.575806% 总的字数:28374490 完美字数:12037649 错误字数:16336841  
  10.   
  11. BidirectionalMinimumMatching(双向最小匹配算法):  
  12. 分词速度:349.67215 字符/毫秒  
  13. 行数完美率:46.766422%  行数错误率:53.23358%  总的行数:2533709  完美行数:1184925  错误行数:1348784  
  14. 字数完美率:36.52718% 字数错误率:63.47282% 总的字数:28374490 完美字数:10364401 错误字数:18010089  
  15.   
  16. ReverseMaximumMatching(逆向最大匹配算法):  
  17. 分词速度:598.04272 字符/毫秒  
  18. 行数完美率:46.723125%  行数错误率:53.27688%  总的行数:2533709  完美行数:1183828  错误行数:1349881  
  19. 字数完美率:36.67598% 字数错误率:63.32402% 总的字数:28374490 完美字数:10406622 错误字数:17967868  
  20.   
  21. MaximumMatching(正向最大匹配算法):  
  22. 分词速度:676.7993 字符/毫秒  
  23. 行数完美率:46.661713%  行数错误率:53.338287%  总的行数:2533709  完美行数:1182272  错误行数:1351437  
  24. 字数完美率:36.72861% 字数错误率:63.271393% 总的字数:28374490 完美字数:10421556 错误字数:17952934  
  25.   
  26. ReverseMinimumMatching(逆向最小匹配算法):  
  27. 分词速度:806.9586 字符/毫秒  
  28. 行数完美率:41.776066%  行数错误率:58.223934%  总的行数:2533709  完美行数:1058484  错误行数:1475225  
  29. 字数完美率:31.678978% 字数错误率:68.32102% 总的字数:28374490 完美字数:8988748 错误字数:19385742  
  30.   
  31. MinimumMatching(正向最小匹配算法):  
  32. 分词速度:1020.9208 字符/毫秒  
  33. 行数完美率:36.853836%  行数错误率:63.146164%  总的行数:2533709  完美行数:933769  错误行数:1599940  
  34. 字数完美率:26.859812% 字数错误率:73.14019% 总的字数:28374490 完美字数:7621334 错误字数:20753156  

 

Ansj0.9的评估结果如下:

 

Java代码   收藏代码
  1. Ansj ToAnalysis 精准分词:  
  2. 分词速度:495.9188 字符/毫秒  
  3. 行数完美率:58.609295%  行数错误率:41.390705%  总的行数:2533709  完美行数:1484989  错误行数:1048720  
  4. 字数完美率:50.97614%   字数错误率:49.023857%  总的字数:28374490 完美字数:14464220 错误字数:13910270  
  5.   
  6. Ansj NlpAnalysis NLP分词:  
  7. 分词速度:350.7527 字符/毫秒  
  8. 行数完美率:58.60353%  行数错误率:41.396465%  总的行数:2533709  完美行数:1484843  错误行数:1048866  
  9. 字数完美率:50.75546%  字数错误率:49.244545%  总的字数:28374490 完美字数:14401602 错误字数:13972888  
  10.   
  11. Ansj BaseAnalysis 基本分词:  
  12. 分词速度:532.65424 字符/毫秒  
  13. 行数完美率:54.028584%  行数错误率:45.97142%  总的行数:2533709  完美行数:1368927  错误行数:1164782  
  14. 字数完美率:46.84512%   字数错误率:53.15488%  总的字数:28374490 完美字数:13292064 错误字数:15082426  
  15.   
  16. Ansj IndexAnalysis 面向索引的分词:  
  17. 分词速度:564.6103 字符/毫秒  
  18. 行数完美率:53.510803%  行数错误率:46.489197%  总的行数:2533709  完美行数:1355808  错误行数:1177901  
  19. 字数完美率:46.355087%  字数错误率:53.644913%  总的字数:28374490 完美字数:13153019 错误字数:15221471  

 

Ansj1.4的评估结果如下:

 

Java代码   收藏代码
  1. Ansj ToAnalysis 精准分词:  
  2. 分词速度:581.7306 字符/毫秒  
  3. 行数完美率:58.60302%  行数错误率:41.39698%  总的行数:2533709  完美行数:1484830  错误行数:1048879  
  4. 字数完美率:50.968987% 字数错误率:49.031013% 总的字数:28374490 完美字数:14462190 错误字数:13912300  
  5.   
  6. Ansj NlpAnalysis NLP分词:  
  7. 分词速度:138.81165 字符/毫秒  
  8. 行数完美率:58.1515%  行数错误率:41.8485%  总的行数:2533687  完美行数:1473377  错误行数:1060310  
  9. 字数完美率:49.806484% 字数错误率:50.19352% 总的字数:28374398 完美字数:14132290 错误字数:14242108  
  10.   
  11. Ansj BaseAnalysis 基本分词:  
  12. 分词速度:627.68475 字符/毫秒  
  13. 行数完美率:55.3174%  行数错误率:44.6826%  总的行数:2533709  完美行数:1401582  错误行数:1132127  
  14. 字数完美率:48.177986% 字数错误率:51.822014% 总的字数:28374490 完美字数:13670258 错误字数:14704232  
  15.   
  16. Ansj IndexAnalysis 面向索引的分词:  
  17. 分词速度:715.55176 字符/毫秒  
  18. 行数完美率:50.89444%  行数错误率:49.10556%  总的行数:2533709  完美行数:1289517  错误行数:1244192  
  19. 字数完美率:42.965115% 字数错误率:57.034885% 总的字数:28374490 完美字数:12191132 错误字数:16183358  

 

 Ansj分词评估程序如下:

 

Java代码   收藏代码
  1. import java.io.BufferedReader;  
  2. import java.io.BufferedWriter;  
  3. import java.io.FileInputStream;  
  4. import java.io.FileOutputStream;  
  5. import java.io.IOException;  
  6. import java.io.InputStreamReader;  
  7. import java.io.OutputStreamWriter;  
  8. import java.nio.file.Files;  
  9. import java.nio.file.Paths;  
  10. import java.util.ArrayList;  
  11. import java.util.Collections;  
  12. import java.util.List;  
  13. import org.ansj.domain.Term;  
  14. import org.ansj.splitWord.analysis.BaseAnalysis;  
  15. import org.ansj.splitWord.analysis.IndexAnalysis;  
  16. import org.ansj.splitWord.analysis.NlpAnalysis;  
  17. import org.ansj.splitWord.analysis.ToAnalysis;  
  18.   
  19. /** 
  20.  * Ansj分词器分词效果评估 
  21.  * @author 杨尚川 
  22.  */  
  23. public class AnsjEvaluation {  
  24.   
  25.     public static void main(String[] args) throws Exception{  
  26.         // 测试文件 d:/test-text.txt 和 标准分词结果文件 d:/standard-text.txt 的下载地址:  
  27.         // http://pan.baidu.com/s/1hqihzjY  
  28.           
  29.         List<EvaluationResult> list = new ArrayList<>();  
  30.         // 对文本进行分词  
  31.         float rate = seg("d:/test-text.txt""d:/result-text-BaseAnalysis.txt""BaseAnalysis");  
  32.         // 对分词结果进行评估  
  33.         EvaluationResult result = evaluation("d:/result-text-BaseAnalysis.txt""d:/standard-text.txt");  
  34.         result.setAnalyzer("Ansj BaseAnalysis 基本分词");  
  35.         result.setSegSpeed(rate);  
  36.         list.add(result);  
  37.           
  38.         // 对文本进行分词  
  39.         rate = seg("d:/test-text.txt""d:/result-text-ToAnalysis.txt""ToAnalysis");  
  40.         // 对分词结果进行评估  
  41.         result = evaluation("d:/result-text-ToAnalysis.txt""d:/standard-text.txt");  
  42.         result.setAnalyzer("Ansj ToAnalysis 精准分词");  
  43.         result.setSegSpeed(rate);  
  44.         list.add(result);  
  45.           
  46.         // 对文本进行分词  
  47.         rate = seg("d:/test-text.txt""d:/result-text-NlpAnalysis.txt""NlpAnalysis");  
  48.         // 对分词结果进行评估  
  49.         result = evaluation("d:/result-text-NlpAnalysis.txt""d:/standard-text.txt");  
  50.         result.setAnalyzer("Ansj NlpAnalysis NLP分词");  
  51.         result.setSegSpeed(rate);  
  52.         list.add(result);  
  53.           
  54.         // 对文本进行分词  
  55.         rate = seg("d:/test-text.txt""d:/result-text-IndexAnalysis.txt""IndexAnalysis");  
  56.         // 对分词结果进行评估  
  57.         result = evaluation("d:/result-text-IndexAnalysis.txt""d:/standard-text.txt");  
  58.         result.setAnalyzer("Ansj IndexAnalysis 面向索引的分词");  
  59.         result.setSegSpeed(rate);  
  60.         list.add(result);  
  61.           
  62.         //输出评估结果  
  63.         Collections.sort(list);  
  64.         System.out.println("");  
  65.         for(EvaluationResult r : list){  
  66.             System.out.println(r+"\n");  
  67.         }  
  68.     }  
  69.     private static float seg(final String input, final String output, final String type) throws Exception{  
  70.         float rate = 0;  
  71.         try(BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(input),"utf-8"));  
  72.                 BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output),"utf-8"))){  
  73.             long size = Files.size(Paths.get(input));  
  74.             System.out.println("size:"+size);  
  75.             System.out.println("文件大小:"+(float)size/1024/1024+" MB");  
  76.             int textLength=0;  
  77.             int progress=0;  
  78.             long start = System.currentTimeMillis();  
  79.             String line = null;  
  80.             while((line = reader.readLine()) != null){  
  81.                 if("".equals(line.trim())){  
  82.                     writer.write("\n");  
  83.                     continue;  
  84.                 }  
  85.                 textLength += line.length();  
  86.                 switch(type){  
  87.                     case "BaseAnalysis":  
  88.                         for(Term term : BaseAnalysis.parse(line)){  
  89.                             writer.write(term.getName()+" ");  
  90.                         }  
  91.                         break;  
  92.                     case "ToAnalysis":  
  93.                         for(Term term : ToAnalysis.parse(line)){  
  94.                             writer.write(term.getName()+" ");  
  95.                         }  
  96.                         break;  
  97.                     case "NlpAnalysis":  
  98.                         try{  
  99.                             for(Term term : NlpAnalysis.parse(line)){  
  100.                                 writer.write(term.getName()+" ");  
  101.                             }  
  102.                         }catch(Exception e){}  
  103.                         break;  
  104.                     case "IndexAnalysis":  
  105.                         for(Term term : IndexAnalysis.parse(line)){  
  106.                             writer.write(term.getName()+" ");  
  107.                         }  
  108.                         break;  
  109.                 }                  
  110.                 writer.write("\n");  
  111.                 progress += line.length();  
  112.                 if( progress > 500000){  
  113.                     progress = 0;  
  114.                     System.out.println("分词进度:"+(int)(textLength*2.99/size*100)+"%");  
  115.                 }  
  116.             }  
  117.             long cost = System.currentTimeMillis() - start;  
  118.             rate = textLength/(float)cost;  
  119.             System.out.println("字符数目:"+textLength);  
  120.             System.out.println("分词耗时:"+cost+" 毫秒");  
  121.             System.out.println("分词速度:"+rate+" 字符/毫秒");  
  122.         }  
  123.         return rate;  
  124.     }  
  125.     /** 
  126.      * 分词效果评估 
  127.      * @param resultText 实际分词结果文件路径 
  128.      * @param standardText 标准分词结果文件路径 
  129.      * @return 评估结果 
  130.      */  
  131.     private static EvaluationResult evaluation(String resultText, String standardText) {  
  132.         int perfectLineCount=0;  
  133.         int wrongLineCount=0;  
  134.         int perfectCharCount=0;  
  135.         int wrongCharCount=0;  
  136.         try(BufferedReader resultReader = new BufferedReader(new InputStreamReader(new FileInputStream(resultText),"utf-8"));  
  137.             BufferedReader standardReader = new BufferedReader(new InputStreamReader(new FileInputStream(standardText),"utf-8"))){  
  138.             String result;  
  139.             while( (result = resultReader.readLine()) != null ){  
  140.                 result = result.trim();  
  141.                 String standard = standardReader.readLine().trim();  
  142.                 if(result.equals("")){  
  143.                     continue;  
  144.                 }  
  145.                 if(result.equals(standard)){  
  146.                     //分词结果和标准一模一样  
  147.                     perfectLineCount++;  
  148.                     perfectCharCount+=standard.replaceAll("\\s+""").length();  
  149.                 }else{  
  150.                     //分词结果和标准不一样  
  151.                     wrongLineCount++;  
  152.                     wrongCharCount+=standard.replaceAll("\\s+""").length();  
  153.                 }  
  154.             }  
  155.         } catch (IOException ex) {  
  156.             System.err.println("分词效果评估失败:" + ex.getMessage());  
  157.         }  
  158.         int totalLineCount = perfectLineCount+wrongLineCount;  
  159.         int totalCharCount = perfectCharCount+wrongCharCount;  
  160.         EvaluationResult er = new EvaluationResult();  
  161.         er.setPerfectCharCount(perfectCharCount);  
  162.         er.setPerfectLineCount(perfectLineCount);  
  163.         er.setTotalCharCount(totalCharCount);  
  164.         er.setTotalLineCount(totalLineCount);  
  165.         er.setWrongCharCount(wrongCharCount);  
  166.         er.setWrongLineCount(wrongLineCount);       
  167.         return er;  
  168.     }  
  169.     /** 
  170.      * 分词结果 
  171.      */  
  172.     private static class EvaluationResult implements Comparable{  
  173.         private String analyzer;  
  174.         private float segSpeed;  
  175.         private int totalLineCount;  
  176.         private int perfectLineCount;  
  177.         private int wrongLineCount;  
  178.         private int totalCharCount;  
  179.         private int perfectCharCount;  
  180.         private int wrongCharCount;  
  181.   
  182.         public String getAnalyzer() {  
  183.             return analyzer;  
  184.         }  
  185.         public void setAnalyzer(String analyzer) {  
  186.             this.analyzer = analyzer;  
  187.         }  
  188.         public float getSegSpeed() {  
  189.             return segSpeed;  
  190.         }  
  191.         public void setSegSpeed(float segSpeed) {  
  192.             this.segSpeed = segSpeed;  
  193.         }  
  194.         public float getLinePerfectRate(){  
  195.             return perfectLineCount/(float)totalLineCount*100;  
  196.         }  
  197.         public float getLineWrongRate(){  
  198.             return wrongLineCount/(float)totalLineCount*100;  
  199.         }  
  200.         public float getCharPerfectRate(){  
  201.             return perfectCharCount/(float)totalCharCount*100;  
  202.         }  
  203.         public float getCharWrongRate(){  
  204.             return wrongCharCount/(float)totalCharCount*100;  
  205.         }  
  206.         public int getTotalLineCount() {  
  207.             return totalLineCount;  
  208.         }  
  209.         public void setTotalLineCount(int totalLineCount) {  
  210.             this.totalLineCount = totalLineCount;  
  211.         }  
  212.         public int getPerfectLineCount() {  
  213.             return perfectLineCount;  
  214.         }  
  215.         public void setPerfectLineCount(int perfectLineCount) {  
  216.             this.perfectLineCount = perfectLineCount;  
  217.         }  
  218.         public int getWrongLineCount() {  
  219.             return wrongLineCount;  
  220.         }  
  221.         public void setWrongLineCount(int wrongLineCount) {  
  222.             this.wrongLineCount = wrongLineCount;  
  223.         }  
  224.         public int getTotalCharCount() {  
  225.             return totalCharCount;  
  226.         }  
  227.         public void setTotalCharCount(int totalCharCount) {  
  228.             this.totalCharCount = totalCharCount;  
  229.         }  
  230.         public int getPerfectCharCount() {  
  231.             return perfectCharCount;  
  232.         }  
  233.         public void setPerfectCharCount(int perfectCharCount) {  
  234.             this.perfectCharCount = perfectCharCount;  
  235.         }  
  236.         public int getWrongCharCount() {  
  237.             return wrongCharCount;  
  238.         }  
  239.         public void setWrongCharCount(int wrongCharCount) {  
  240.             this.wrongCharCount = wrongCharCount;  
  241.         }  
  242.         @Override  
  243.         public String toString(){  
  244.             return analyzer+":"  
  245.                     +"\n"  
  246.                     +"分词速度:"+segSpeed+" 字符/毫秒"  
  247.                     +"\n"  
  248.                     +"行数完美率:"+getLinePerfectRate()+"%"  
  249.                     +"  行数错误率:"+getLineWrongRate()+"%"  
  250.                     +"  总的行数:"+totalLineCount  
  251.                     +"  完美行数:"+perfectLineCount  
  252.                     +"  错误行数:"+wrongLineCount  
  253.                     +"\n"  
  254.                     +"字数完美率:"+getCharPerfectRate()+"%"  
  255.                     +" 字数错误率:"+getCharWrongRate()+"%"  
  256.                     +" 总的字数:"+totalCharCount  
  257.                     +" 完美字数:"+perfectCharCount  
  258.                     +" 错误字数:"+wrongCharCount;  
  259.         }  
  260.         @Override  
  261.         public int compareTo(Object o) {  
  262.             EvaluationResult other = (EvaluationResult)o;  
  263.             if(other.getLinePerfectRate() - getLinePerfectRate() > 0){  
  264.                 return 1;  
  265.             }  
  266.             if(other.getLinePerfectRate() - getLinePerfectRate() < 0){  
  267.                 return -1;  
  268.             }  
  269.             return 0;  
  270.         }  
  271.     }  
  272. }  

 

 

MMSeg4j1.9.1的评估结果如下:

 

Java代码   收藏代码
  1. MMSeg4j ComplexSeg:  
  2. 分词速度:794.24805 字符/毫秒  
  3. 行数完美率:38.817604%  行数错误率:61.182396%  总的行数:2533688  完美行数:983517  错误行数:1550171  
  4. 字数完美率:29.604435% 字数错误率:70.39557% 总的字数:28374428 完美字数:8400089 错误字数:19974339  
  5.   
  6. MMSeg4j SimpleSeg:  
  7. 分词速度:1026.1058 字符/毫秒  
  8. 行数完美率:37.570095%  行数错误率:62.429905%  总的行数:2533688  完美行数:951909  错误行数:1581779  
  9. 字数完美率:28.455273% 字数错误率:71.54473% 总的字数:28374428 完美字数:8074021 错误字数:20300407  
  10.   
  11. MMSeg4j MaxWordSeg:  
  12. 分词速度:813.0676 字符/毫秒  
  13. 行数完美率:34.27573%  行数错误率:65.72427%  总的行数:2533688  完美行数:868440  错误行数:1665248  
  14. 字数完美率:25.20896% 字数错误率:74.79104% 总的字数:28374428 完美字数:7152898 错误字数:21221530  

 

MMSeg4j1.9.1分词评估程序如下:

 

Java代码   收藏代码
  1. import com.chenlb.mmseg4j.ComplexSeg;  
  2. import com.chenlb.mmseg4j.Dictionary;  
  3. import com.chenlb.mmseg4j.MMSeg;  
  4. import com.chenlb.mmseg4j.MaxWordSeg;  
  5. import com.chenlb.mmseg4j.Seg;  
  6. import com.chenlb.mmseg4j.SimpleSeg;  
  7. import com.chenlb.mmseg4j.Word;  
  8. import java.io.BufferedReader;  
  9. import java.io.BufferedWriter;  
  10. import java.io.FileInputStream;  
  11. import java.io.FileOutputStream;  
  12. import java.io.IOException;  
  13. import java.io.InputStreamReader;  
  14. import java.io.OutputStreamWriter;  
  15. import java.io.StringReader;  
  16. import java.nio.file.Files;  
  17. import java.nio.file.Paths;  
  18. import java.util.ArrayList;  
  19. import java.util.Collections;  
  20. import java.util.List;  
  21.   
  22. /** 
  23.  * MMSeg4j分词器分词效果评估 
  24.  * @author 杨尚川 
  25.  */  
  26. public class MMSeg4jEvaluation {  
  27.   
  28.     public static void main(String[] args) throws Exception{  
  29.         // 测试文件 d:/test-text.txt 和 标准分词结果文件 d:/standard-text.txt 的下载地址:  
  30.         // http://pan.baidu.com/s/1hqihzjY  
  31.           
  32.         List<EvaluationResult> list = new ArrayList<>();  
  33.         Dictionary dic = Dictionary.getInstance();  
  34.         // 对文本进行分词  
  35.         float rate = seg("d:/test-text.txt""d:/result-text-ComplexSeg.txt"new ComplexSeg(dic));  
  36.         // 对分词结果进行评估  
  37.         EvaluationResult result = evaluation("d:/result-text-ComplexSeg.txt""d:/standard-text.txt");  
  38.         result.setAnalyzer("MMSeg4j ComplexSeg");  
  39.         result.setSegSpeed(rate);  
  40.         list.add(result);  
  41.           
  42.         // 对文本进行分词  
  43.         rate = seg("d:/test-text.txt""d:/result-text-SimpleSeg.txt"new SimpleSeg(dic));  
  44.         // 对分词结果进行评估  
  45.         result = evaluation("d:/result-text-SimpleSeg.txt""d:/standard-text.txt");  
  46.         result.setAnalyzer("MMSeg4j SimpleSeg");  
  47.         result.setSegSpeed(rate);  
  48.         list.add(result);  
  49.           
  50.         // 对文本进行分词  
  51.         rate = seg("d:/test-text.txt""d:/result-text-MaxWordSeg.txt"new MaxWordSeg(dic));  
  52.         // 对分词结果进行评估  
  53.         result = evaluation("d:/result-text-MaxWordSeg.txt""d:/standard-text.txt");  
  54.         result.setAnalyzer("MMSeg4j MaxWordSeg");  
  55.         result.setSegSpeed(rate);  
  56.         list.add(result);  
  57.           
  58.         //输出评估结果  
  59.         Collections.sort(list);  
  60.         System.out.println("");  
  61.         for(EvaluationResult r : list){  
  62.             System.out.println(r+"\n");  
  63.         }  
  64.     }  
  65.     private static float seg(final String input, final String output, final Seg seg) throws Exception{  
  66.         float rate = 0;  
  67.         try(BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(input),"utf-8"));  
  68.                 BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output),"utf-8"))){  
  69.             long size = Files.size(Paths.get(input));  
  70.             System.out.println("size:"+size);  
  71.             System.out.println("文件大小:"+(float)size/1024/1024+" MB");  
  72.             int textLength=0;  
  73.             int progress=0;  
  74.             long start = System.currentTimeMillis();  
  75.             String line = null;  
  76.             while((line = reader.readLine()) != null){  
  77.                 if("".equals(line.trim())){  
  78.                     writer.write("\n");  
  79.                     continue;  
  80.                 }  
  81.                 textLength += line.length();  
  82.                 writer.write(seg(line, seg));  
  83.                 writer.write("\n");  
  84.                 progress += line.length();  
  85.                 if( progress > 500000){  
  86.                     progress = 0;  
  87.                     System.out.println("分词进度:"+(int)(textLength*2.99/size*100)+"%");  
  88.                 }  
  89.             }  
  90.             long cost = System.currentTimeMillis() - start;  
  91.             rate = textLength/(float)cost;  
  92.             System.out.println("字符数目:"+textLength);  
  93.             System.out.println("分词耗时:"+cost+" 毫秒");  
  94.             System.out.println("分词速度:"+rate+" 字符/毫秒");  
  95.         }  
  96.         return rate;  
  97.     }  
  98.     private static String seg(String text, Seg seg) throws IOException {  
  99.         StringBuilder result = new StringBuilder();  
  100.         MMSeg mmSeg = new MMSeg(new StringReader(text), seg);  
  101.         Word word = null;  
  102.         while((word=mmSeg.next())!=null) {  
  103.             result.append(word.getString()).append(" ");              
  104.         }  
  105.         return result.toString().trim();  
  106.     }  
  107.     /** 
  108.      * 分词效果评估 
  109.      * @param resultText 实际分词结果文件路径 
  110.      * @param standardText 标准分词结果文件路径 
  111.      * @return 评估结果 
  112.      */  
  113.     private static EvaluationResult evaluation(String resultText, String standardText) {  
  114.         int perfectLineCount=0;  
  115.         int wrongLineCount=0;  
  116.         int perfectCharCount=0;  
  117.         int wrongCharCount=0;  
  118.         try(BufferedReader resultReader = new BufferedReader(new InputStreamReader(new FileInputStream(resultText),"utf-8"));  
  119.             BufferedReader standardReader = new BufferedReader(new InputStreamReader(new FileInputStream(standardText),"utf-8"))){  
  120.             String result;  
  121.             while( (result = resultReader.readLine()) != null ){  
  122.                 result = result.trim();  
  123.                 String standard = standardReader.readLine().trim();  
  124.                 if(result.equals("")){  
  125.                     continue;  
  126.                 }  
  127.                 if(result.equals(standard)){  
  128.                     //分词结果和标准一模一样  
  129.                     perfectLineCount++;  
  130.                     perfectCharCount+=standard.replaceAll("\\s+""").length();  
  131.                 }else{  
  132.                     //分词结果和标准不一样  
  133.                     wrongLineCount++;  
  134.                     wrongCharCount+=standard.replaceAll("\\s+""").length();  
  135.                 }  
  136.             }  
  137.         } catch (IOException ex) {  
  138.             System.err.println("分词效果评估失败:" + ex.getMessage());  
  139.         }  
  140.         int totalLineCount = perfectLineCount+wrongLineCount;  
  141.         int totalCharCount = perfectCharCount+wrongCharCount;  
  142.         EvaluationResult er = new EvaluationResult();  
  143.         er.setPerfectCharCount(perfectCharCount);  
  144.         er.setPerfectLineCount(perfectLineCount);  
  145.         er.setTotalCharCount(totalCharCount);  
  146.         er.setTotalLineCount(totalLineCount);  
  147.         er.setWrongCharCount(wrongCharCount);  
  148.         er.setWrongLineCount(wrongLineCount);       
  149.         return er;  
  150.     }  
  151.     /** 
  152.      * 分词结果 
  153.      */  
  154.     private static class EvaluationResult implements Comparable{  
  155.         private String analyzer;  
  156.         private float segSpeed;  
  157.         private int totalLineCount;  
  158.         private int perfectLineCount;  
  159.         private int wrongLineCount;  
  160.         private int totalCharCount;  
  161.         private int perfectCharCount;  
  162.         private int wrongCharCount;  
  163.   
  164.         public String getAnalyzer() {  
  165.             return analyzer;  
  166.         }  
  167.         public void setAnalyzer(String analyzer) {  
  168.             this.analyzer = analyzer;  
  169.         }  
  170.         public float getSegSpeed() {  
  171.             return segSpeed;  
  172.         }  
  173.         public void setSegSpeed(float segSpeed) {  
  174.             this.segSpeed = segSpeed;  
  175.         }  
  176.         public float getLinePerfectRate(){  
  177.             return perfectLineCount/(float)totalLineCount*100;  
  178.         }  
  179.         public float getLineWrongRate(){  
  180.             return wrongLineCount/(float)totalLineCount*100;  
  181.         }  
  182.         public float getCharPerfectRate(){  
  183.             return perfectCharCount/(float)totalCharCount*100;  
  184.         }  
  185.         public float getCharWrongRate(){  
  186.             return wrongCharCount/(float)totalCharCount*100;  
  187.         }  
  188.         public int getTotalLineCount() {  
  189.             return totalLineCount;  
  190.         }  
  191.         public void setTotalLineCount(int totalLineCount) {  
  192.             this.totalLineCount = totalLineCount;  
  193.         }  
  194.         public int getPerfectLineCount() {  
  195.             return perfectLineCount;  
  196.         }  
  197.         public void setPerfectLineCount(int perfectLineCount) {  
  198.             this.perfectLineCount = perfectLineCount;  
  199.         }  
  200.         public int getWrongLineCount() {  
  201.             return wrongLineCount;  
  202.         }  
  203.         public void setWrongLineCount(int wrongLineCount) {  
  204.             this.wrongLineCount = wrongLineCount;  
  205.         }  
  206.         public int getTotalCharCount() {  
  207.             return totalCharCount;  
  208.         }  
  209.         public void setTotalCharCount(int totalCharCount) {  
  210.             this.totalCharCount = totalCharCount;  
  211.         }  
  212.         public int getPerfectCharCount() {  
  213.             return perfectCharCount;  
  214.         }  
  215.         public void setPerfectCharCount(int perfectCharCount) {  
  216.             this.perfectCharCount = perfectCharCount;  
  217.         }  
  218.         public int getWrongCharCount() {  
  219.             return wrongCharCount;  
  220.         }  
  221.         public void setWrongCharCount(int wrongCharCount) {  
  222.             this.wrongCharCount = wrongCharCount;  
  223.         }  
  224.         @Override  
  225.         public String toString(){  
  226.             return analyzer+":"  
  227.                     +"\n"  
  228.                     +"分词速度:"+segSpeed+" 字符/毫秒"  
  229.                     +"\n"  
  230.                     +"行数完美率:"+getLinePerfectRate()+"%"  
  231.                     +"  行数错误率:"+getLineWrongRate()+"%"  
  232.                     +"  总的行数:"+totalLineCount  
  233.                     +"  完美行数:"+perfectLineCount  
  234.                     +"  错误行数:"+wrongLineCount  
  235.                     +"\n"  
  236.                     +"字数完美率:"+getCharPerfectRate()+"%"  
  237.                     +" 字数错误率:"+getCharWrongRate()+"%"  
  238.                     +" 总的字数:"+totalCharCount  
  239.                     +" 完美字数:"+perfectCharCount  
  240.                     +" 错误字数:"+wrongCharCount;  
  241.         }  
  242.         @Override  
  243.         public int compareTo(Object o) {  
  244.             EvaluationResult other = (EvaluationResult)o;  
  245.             if(other.getLinePerfectRate() - getLinePerfectRate() > 0){  
  246.                 return 1;  
  247.             }  
  248.             if(other.getLinePerfectRate() - getLinePerfectRate() < 0){  
  249.                 return -1;  
  250.             }  
  251.             return 0;  
  252.         }  
  253.     }  
  254. }   

 

ik-analyzer2012_u6的评估结果如下:

 

Java代码   收藏代码
  1. IKAnalyzer 智能切分:  
  2. 分词速度:178.3516 字符/毫秒  
  3. 行数完美率:37.55943%  行数错误率:62.440567%  总的行数:2533686  完美行数:951638  错误行数:1582048  
  4. 字数完美率:27.978464% 字数错误率:72.02154% 总的字数:28374416 完美字数:7938726 错误字数:20435690  
  5.   
  6. IKAnalyzer 细粒度切分:  
  7. 分词速度:182.97859 字符/毫秒  
  8. 行数完美率:18.872742%  行数错误率:81.12726%  总的行数:2533686  完美行数:478176  错误行数:2055510  
  9. 字数完美率:10.936535% 字数错误率:89.06347% 总的字数:28374416 完美字数:3103178 错误字数:25271238  

 

 

ik-analyzer2012_u6分词评估程序如下:

 

Java代码   收藏代码
  1. import java.io.BufferedReader;  
  2. import java.io.BufferedWriter;  
  3. import java.io.FileInputStream;  
  4. import java.io.FileOutputStream;  
  5. import java.io.IOException;  
  6. import java.io.InputStreamReader;  
  7. import java.io.OutputStreamWriter;  
  8. import java.io.StringReader;  
  9. import java.nio.file.Files;  
  10. import java.nio.file.Paths;  
  11. import java.util.ArrayList;  
  12. import java.util.Collections;  
  13. import java.util.List;  
  14. import org.wltea.analyzer.core.IKSegmenter;  
  15. import org.wltea.analyzer.core.Lexeme;  
  16.   
  17. /** 
  18.  * IKAnalyzer分词器分词效果评估 
  19.  * @author 杨尚川 
  20.  */  
  21. public class IKAnalyzerEvaluation {  
  22.   
  23.     public static void main(String[] args) throws Exception{  
  24.         // 测试文件 d:/test-text.txt 和 标准分词结果文件 d:/standard-text.txt 的下载地址:  
  25.         // http://pan.baidu.com/s/1hqihzjY  
  26.           
  27.         List<EvaluationResult> list = new ArrayList<>();  
  28.           
  29.         // 对文本进行分词  
  30.         float rate = seg("d:/test-text.txt""d:/result-text-ComplexSeg.txt"true);  
  31.         // 对分词结果进行评估  
  32.         EvaluationResult result = evaluation("d:/result-text-ComplexSeg.txt""d:/standard-text.txt");  
  33.         result.setAnalyzer("IKAnalyzer 智能切分");  
  34.         result.setSegSpeed(rate);  
  35.         list.add(result);  
  36.           
  37.         // 对文本进行分词  
  38.         rate = seg("d:/test-text.txt""d:/result-text-SimpleSeg.txt"false);  
  39.         // 对分词结果进行评估  
  40.         result = evaluation("d:/result-text-SimpleSeg.txt""d:/standard-text.txt");  
  41.         result.setAnalyzer("IKAnalyzer 细粒度切分");  
  42.         result.setSegSpeed(rate);  
  43.         list.add(result);  
  44.           
  45.         //输出评估结果  
  46.         Collections.sort(list);  
  47.         System.out.println("");  
  48.         for(EvaluationResult r : list){  
  49.             System.out.println(r+"\n");  
  50.         }  
  51.     }  
  52.     private static float seg(final String input, final String output, final boolean useSmart) throws Exception{  
  53.         float rate = 0;  
  54.         try(BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(input),"utf-8"));  
  55.                 BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output),"utf-8"))){  
  56.             long size = Files.size(Paths.get(input));  
  57.             System.out.println("size:"+size);  
  58.             System.out.println("文件大小:"+(float)size/1024/1024+" MB");  
  59.             int textLength=0;  
  60.             int progress=0;  
  61.             long start = System.currentTimeMillis();  
  62.             String line = null;  
  63.             while((line = reader.readLine()) != null){  
  64.                 if("".equals(line.trim())){  
  65.                     writer.write("\n");  
  66.                     continue;  
  67.                 }  
  68.                 textLength += line.length();  
  69.                 writer.write(seg(line, useSmart));  
  70.                 writer.write("\n");  
  71.                 progress += line.length();  
  72.                 if( progress > 500000){  
  73.                     progress = 0;  
  74.                     System.out.println("分词进度:"+(int)(textLength*2.99/size*100)+"%");  
  75.                 }  
  76.             }  
  77.             long cost = System.currentTimeMillis() - start;  
  78.             rate = textLength/(float)cost;  
  79.             System.out.println("字符数目:"+textLength);  
  80.             System.out.println("分词耗时:"+cost+" 毫秒");  
  81.             System.out.println("分词速度:"+rate+" 字符/毫秒");  
  82.         }  
  83.         return rate;  
  84.     }  
  85.     private static String seg(String text, boolean useSmart) throws IOException {  
  86.         StringBuilder result = new StringBuilder();  
  87.         IKSegmenter ik = new IKSegmenter(new StringReader(text), useSmart);  
  88.         Lexeme word = null;  
  89.         while((word=ik.next())!=null) {  
  90.             result.append(word.getLexemeText()).append(" ");              
  91.         }  
  92.         return result.toString().trim();  
  93.     }  
  94.     /** 
  95.      * 分词效果评估 
  96.      * @param resultText 实际分词结果文件路径 
  97.      * @param standardText 标准分词结果文件路径 
  98.      * @return 评估结果 
  99.      */  
  100.     private static EvaluationResult evaluation(String resultText, String standardText) {  
  101.         int perfectLineCount=0;  
  102.         int wrongLineCount=0;  
  103.         int perfectCharCount=0;  
  104.         int wrongCharCount=0;  
  105.         try(BufferedReader resultReader = new BufferedReader(new InputStreamReader(new FileInputStream(resultText),"utf-8"));  
  106.             BufferedReader standardReader = new BufferedReader(new InputStreamReader(new FileInputStream(standardText),"utf-8"))){  
  107.             String result;  
  108.             while( (result = resultReader.readLine()) != null ){  
  109.                 result = result.trim();  
  110.                 String standard = standardReader.readLine().trim();  
  111.                 if(result.equals("")){  
  112.                     continue;  
  113.                 }  
  114.                 if(result.equals(standard)){  
  115.                     //分词结果和标准一模一样  
  116.                     perfectLineCount++;  
  117.                     perfectCharCount+=standard.replaceAll("\\s+""").length();  
  118.                 }else{  
  119.                     //分词结果和标准不一样  
  120.                     wrongLineCount++;  
  121.                     wrongCharCount+=standard.replaceAll("\\s+""").length();  
  122.                 }  
  123.             }  
  124.         } catch (IOException ex) {  
  125.             System.err.println("分词效果评估失败:" + ex.getMessage());  
  126.         }  
  127.         int totalLineCount = perfectLineCount+wrongLineCount;  
  128.         int totalCharCount = perfectCharCount+wrongCharCount;  
  129.         EvaluationResult er = new EvaluationResult();  
  130.         er.setPerfectCharCount(perfectCharCount);  
  131.         er.setPerfectLineCount(perfectLineCount);  
  132.         er.setTotalCharCount(totalCharCount);  
  133.         er.setTotalLineCount(totalLineCount);  
  134.         er.setWrongCharCount(wrongCharCount);  
  135.         er.setWrongLineCount(wrongLineCount);       
  136.         return er;  
  137.     }  
  138.     /** 
  139.      * 分词结果 
  140.      */  
  141.     private static class EvaluationResult implements Comparable{  
  142.         private String analyzer;  
  143.         private float segSpeed;  
  144.         private int totalLineCount;  
  145.         private int perfectLineCount;  
  146.         private int wrongLineCount;  
  147.         private int totalCharCount;  
  148.         private int perfectCharCount;  
  149.         private int wrongCharCount;  
  150.   
  151.         public String getAnalyzer() {  
  152.             return analyzer;  
  153.         }  
  154.         public void setAnalyzer(String analyzer) {  
  155.             this.analyzer = analyzer;  
  156.         }  
  157.         public float getSegSpeed() {  
  158.             return segSpeed;  
  159.         }  
  160.         public void setSegSpeed(float segSpeed) {  
  161.             this.segSpeed = segSpeed;  
  162.         }  
  163.         public float getLinePerfectRate(){  
  164.             return perfectLineCount/(float)totalLineCount*100;  
  165.         }  
  166.         public float getLineWrongRate(){  
  167.             return wrongLineCount/(float)totalLineCount*100;  
  168.         }  
  169.         public float getCharPerfectRate(){  
  170.             return perfectCharCount/(float)totalCharCount*100;  
  171.         }  
  172.         public float getCharWrongRate(){  
  173.             return wrongCharCount/(float)totalCharCount*100;  
  174.         }  
  175.         public int getTotalLineCount() {  
  176.             return totalLineCount;  
  177.         }  
  178.         public void setTotalLineCount(int totalLineCount) {  
  179.             this.totalLineCount = totalLineCount;  
  180.         }  
  181.         public int getPerfectLineCount() {  
  182.             return perfectLineCount;  
  183.         }  
  184.         public void setPerfectLineCount(int perfectLineCount) {  
  185.             this.perfectLineCount = perfectLineCount;  
  186.         }  
  187.         public int getWrongLineCount() {  
  188.             return wrongLineCount;  
  189.         }  
  190.         public void setWrongLineCount(int wrongLineCount) {  
  191.             this.wrongLineCount = wrongLineCount;  
  192.         }  
  193.         public int getTotalCharCount() {  
  194.             return totalCharCount;  
  195.         }  
  196.         public void setTotalCharCount(int totalCharCount) {  
  197.             this.totalCharCount = totalCharCount;  
  198.         }  
  199.         public int getPerfectCharCount() {  
  200.             return perfectCharCount;  
  201.         }  
  202.         public void setPerfectCharCount(int perfectCharCount) {  
  203.             this.perfectCharCount = perfectCharCount;  
  204.         }  
  205.         public int getWrongCharCount() {  
  206.             return wrongCharCount;  
  207.         }  
  208.         public void setWrongCharCount(int wrongCharCount) {  
  209.             this.wrongCharCount = wrongCharCount;  
  210.         }  
  211.         @Override  
  212.         public String toString(){  
  213.             return analyzer+":"  
  214.                     +"\n"  
  215.                     +"分词速度:"+segSpeed+" 字符/毫秒"  
  216.                     +"\n"  
  217.                     +"行数完美率:"+getLinePerfectRate()+"%"  
  218.                     +"  行数错误率:"+getLineWrongRate()+"%"  
  219.                     +"  总的行数:"+totalLineCount  
  220.                     +"  完美行数:"+perfectLineCount  
  221.                     +"  错误行数:"+wrongLineCount  
  222.                     +"\n"  
  223.                     +"字数完美率:"+getCharPerfectRate()+"%"  
  224.                     +" 字数错误率:"+getCharWrongRate()+"%"  
  225.                     +" 总的字数:"+totalCharCount  
  226.                     +" 完美字数:"+perfectCharCount  
  227.                     +" 错误字数:"+wrongCharCount;  
  228.         }  
  229.         @Override  
  230.         public int compareTo(Object o) {  
  231.             EvaluationResult other = (EvaluationResult)o;  
  232.             if(other.getLinePerfectRate() - getLinePerfectRate() > 0){  
  233.                 return 1;  
  234.             }  
  235.             if(other.getLinePerfectRate() - getLinePerfectRate() < 0){  
  236.                 return -1;  
  237.             }  
  238.             return 0;  
  239.         }  
  240.     }  
  241. }  

 

 

ansj、mmseg4j和ik-analyzer的评估程序可在附件中下载,word分词只需运行项目根目录下的evaluation.bat脚本即可。

 

 

参考资料:

1、word分词器分词效果评估测试数据集和标准数据集 

2、word分词器评估程序

3、word分词器主页

4、ansj分词器主页

5、mmseg4j分词器主页

6、ik-analyzer分词器主页 

你可能感兴趣的:(word分词器)