Skip to content

Commit

Permalink
fix nature recognitionTest
Browse files Browse the repository at this point in the history
  • Loading branch information
孙健 committed Nov 20, 2017
1 parent d74ff29 commit f826ed0
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ jrat.xml
target/
train_file/*
/target/

crf.model

6 changes: 5 additions & 1 deletion src/main/java/org/ansj/app/crf/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import org.ansj.app.crf.pojo.Element;
import org.nlpcn.commons.lang.util.WordAlert;
import org.nlpcn.commons.lang.util.logging.Log;
import org.nlpcn.commons.lang.util.logging.LogFactory;

import java.util.ArrayList;
import java.util.List;

public class Config {

private static final Log LOG = LogFactory.getLog() ;

public String splitStr = "\\s+";

public Config(int[][] template) {
Expand Down Expand Up @@ -125,7 +129,7 @@ public static List<Element> wordAlert(String word) {
element.len = tempSb.length();
list.add(element);
} else {
System.out.println("err!");
LOG.error("err! status :"+status);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/ansj/domain/AnsjItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ public void initValue(String[] split) {
if (status > 1) {
name = split[1];
termNatures = new TermNatures(split[5], index);
}else{
termNatures = new TermNatures(TermNature.NULL);
}
// else{ 理论上不需要了
// termNatures = new TermNatures(TermNature.NULL);
// }
}

@Override
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/org/ansj/domain/TermNatures.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.ansj.domain;

import java.io.Serializable;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;

/**
* 每一个term都拥有一个词性集合
Expand Down Expand Up @@ -75,9 +76,13 @@ public TermNatures(String natureStr, int id) {
this.id = id;
this.termNatures = termNatures;

//{n=2707,q=0,q_mq=0,r=0,v=1}

natureStr = natureStr.substring(1, natureStr.length() - 1);
String[] split = natureStr.split(",");
TermNature[] all = new TermNature[split.length];

List<TermNature> all = new ArrayList<>();

TermNature maxTermNature = null;
int maxFreq = 0, frequency = -1;
int size = 0;
Expand All @@ -88,17 +93,17 @@ public TermNatures(String natureStr, int id) {
if (strs[0].startsWith("q_")) { //内置词性
this.numAttr = new NumNatureAttr(false, true, strs[0].replaceFirst("q_", ""));
} else {
all[i] = new TermNature(strs[0], frequency);
TermNature termNature = new TermNature(strs[0], frequency);
all.add(termNature);
if (maxFreq <= frequency) {
maxFreq = frequency;
maxTermNature = all[i];
maxTermNature = termNature;
}
size++;
}
}


termNatures = Arrays.copyOf(all, size);
termNatures = all.toArray(new TermNature[all.size()]);

if (maxTermNature != null) {
this.nature = maxTermNature.nature;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/ansj/util/MathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,4 @@ public static double lnSum(float... fs) {
return result;
}

public static void main(String[] args) {
System.out.println(Math.log(0.1));
}

}

0 comments on commit f826ed0

Please sign in to comment.