Skip to content

Commit cb7d951

Browse files
committed
seqeval
1 parent bf8fa6b commit cb7d951

File tree

2 files changed

+40
-24
lines changed

2 files changed

+40
-24
lines changed

fnlp-core/src/main/java/org/fnlp/ml/eval/SeqEval.java

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -525,54 +525,70 @@ public String calcByType() {
525525
public double[] calcPRF() {
526526

527527
/**
528-
* 估计的中正确的,key是字符串长度,value是这种长度的个数
528+
* 估计的中正确的
529529
*/
530-
Map<String,Double> mpc = new TreeMap<String,Double>();
530+
int mpc = 0;
531531
/**
532-
* 估计的,key是字符串长度,value是这种长度的个数
532+
* 估计的
533533
*/
534-
Map<String,Double> mp = new TreeMap<String,Double>();
534+
int mp = 0;
535535
/**
536-
* 正确的,key是字符串长度,value是这种长度的个数
536+
* 正确的
537537
*/
538-
Map<String,Double> mc = new TreeMap<String,Double>();
538+
int mc = 0;
539539

540540
/**
541541
* OOV
542542
*/
543-
Map<String,Double> oov = new TreeMap<String,Double>();
543+
int oov = 0;
544+
int coov =0;
544545

545546
for(int i=0;i<entityCs.size();i++){
546547
LinkedList<Entity> cList = entityCs.get(i);
547548
LinkedList<Entity> pList = entityPs.get(i);
548549
LinkedList<Entity> cpList = entityCinPs.get(i);
549550

550-
for(Entity entity:cList){
551-
552-
adjust(mc, "", 1.0);
553-
if(dict!=null&&dict.size()>0){
551+
for(Entity entity:cList){
552+
if(dict!=null&&dict.size()>0){
554553
String s = entity.getEntityStr();
555554
if(!dict.contains(s)){
556-
adjust(oov, "", 1.0);
555+
oov++;
557556
}
558557
}
559558
}
560559

561-
for(Entity entity:pList){
562-
adjust(mp, "", 1.0);
560+
for(Entity entity:cpList){
561+
if(dict!=null&&dict.size()>0){
562+
String s = entity.getEntityStr();
563+
if(!dict.contains(s)){
564+
coov++;
565+
}
566+
}
563567
}
564568

565-
for(Entity entity:cpList){
566-
adjust(mpc, "", 1.0);
567-
}
569+
570+
571+
mc+=cList.size();
572+
mp+=pList.size();
573+
mpc+=cpList.size();
568574
}
569575

570-
String key = "";
571-
double pre = (Double) mpc.get(key)/(Double) mp.get(key)*100;
572-
double recall = (Double)mpc.get(key)/(Double)mc.get(key)*100;
573-
double FB1 = (pre*recall*2)/(recall+pre)*100;
576+
double pre =0;
577+
if(mp!=0)
578+
pre = (double) mpc/(double) mp*100;
579+
double recall = 0;
580+
if(mc!=0)
581+
recall = (double)mpc/(double)mc*100;
582+
583+
double FB1=0;
584+
if(recall+pre!=0)
585+
FB1 = (pre*recall*2)/(recall+pre)*100;
586+
587+
double oovrecall = 0;
588+
if(oov!=0)
589+
oovrecall = (double)coov/(double)oov*100;
574590

575-
return new double[]{pre,recall,FB1};
591+
return new double[]{pre,recall,FB1,oovrecall};
576592

577593
}
578594

fnlp-train/src/main/java/org/fnlp/train/seg/DICT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public class DICT {
4848
*/
4949
public static void main(String[] args) throws Exception {
5050
DICT dic = new DICT();
51-
String file = "./tmpdata/FNLPDATA/all.cws";
52-
String dicfile = "./tmpdata/FNLPDATA/all.dict";
51+
String file = "D:\\项目\\9.评测\\NLPCC2015分词\\data21_No_0\\trainSeg.txt";
52+
String dicfile = "D:\\项目\\9.评测\\NLPCC2015分词\\data21_No_0\\all.dict";
5353
BMES2DICT(file,dicfile);
5454

5555
System.out.println(new Date().toString());

0 commit comments

Comments
 (0)