mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-10 13:29:32 -06:00
now the named entities recognizer returns dictionary entries if the name is known
This commit is contained in:
@@ -18,6 +18,7 @@ public class Test {
|
||||
System.out.println(gr.getAbstractName());
|
||||
for (Map.Entry<String,Concr> entry : gr.getLanguages().entrySet()) {
|
||||
System.out.println(entry.getKey()+" "+entry.getValue()+" "+entry.getValue().getName());
|
||||
entry.getValue().addLiteral("PN", new NercLiteralCallback(gr,entry.getValue()));
|
||||
}
|
||||
|
||||
int count = 10;
|
||||
|
||||
@@ -4,6 +4,14 @@ import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class NercLiteralCallback implements LiteralCallback {
|
||||
private PGF pgf;
|
||||
private Concr concr;
|
||||
|
||||
public NercLiteralCallback(PGF pgf, Concr concr) {
|
||||
this.pgf = pgf;
|
||||
this.concr = concr;
|
||||
}
|
||||
|
||||
public CallbackResult match(int lin_idx, String sentence, int offset) {
|
||||
StringBuilder sbuilder = new StringBuilder();
|
||||
|
||||
@@ -29,8 +37,26 @@ public class NercLiteralCallback implements LiteralCallback {
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
Expr expr = new Expr(sbuilder.toString());
|
||||
expr = new Expr("MkSymb", expr);
|
||||
String name = sbuilder.toString();
|
||||
String lemma = null;
|
||||
double prob = 0;
|
||||
for (MorphoAnalysis an : concr.lookupMorpho(name)) {
|
||||
if ("PN".equals(pgf.getFunctionType(an.getLemma()).getCategory()) &&
|
||||
prob < an.getProb()) {
|
||||
lemma = an.getLemma();
|
||||
prob = an.getProb();
|
||||
}
|
||||
}
|
||||
|
||||
Expr expr;
|
||||
if (lemma == null) {
|
||||
expr = new Expr(name);
|
||||
expr = new Expr("MkSymb", expr);
|
||||
expr = new Expr("SymbPN", expr);
|
||||
} else {
|
||||
expr = new Expr(lemma, new Expr[0]);
|
||||
}
|
||||
|
||||
return new CallbackResult(new ExprProb(expr, 0), end_offset);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user