mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
now the named entities recognizer returns dictionary entries if the name is known
This commit is contained in:
@@ -9,7 +9,7 @@ Phrasebook:
|
|||||||
cd ../phrasebook ; make forApp ; cd ../app
|
cd ../phrasebook ; make forApp ; cd ../app
|
||||||
|
|
||||||
S=-s
|
S=-s
|
||||||
GFMKT=mkdir -p $(GFODIR) && gf $S -make -literal=Symb -probs=$(PROBSFILE) -gfo-dir $(GFODIR)
|
GFMKT=mkdir -p $(GFODIR) && gf $S -make -literal=PN -probs=$(PROBSFILE) -gfo-dir $(GFODIR)
|
||||||
|
|
||||||
APP=AppEng.pgf AppBul.pgf AppChi.pgf AppGer.pgf AppSwe.pgf AppHin.pgf AppFin.pgf AppFre.pgf AppIta.pgf AppSpa.pgf AppDut.pgf
|
APP=AppEng.pgf AppBul.pgf AppChi.pgf AppGer.pgf AppSwe.pgf AppHin.pgf AppFin.pgf AppFre.pgf AppIta.pgf AppSpa.pgf AppDut.pgf
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ public class Test {
|
|||||||
System.out.println(gr.getAbstractName());
|
System.out.println(gr.getAbstractName());
|
||||||
for (Map.Entry<String,Concr> entry : gr.getLanguages().entrySet()) {
|
for (Map.Entry<String,Concr> entry : gr.getLanguages().entrySet()) {
|
||||||
System.out.println(entry.getKey()+" "+entry.getValue()+" "+entry.getValue().getName());
|
System.out.println(entry.getKey()+" "+entry.getValue()+" "+entry.getValue().getName());
|
||||||
|
entry.getValue().addLiteral("PN", new NercLiteralCallback(gr,entry.getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
int count = 10;
|
int count = 10;
|
||||||
|
|||||||
@@ -4,6 +4,14 @@ import java.util.Collections;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
public class NercLiteralCallback implements LiteralCallback {
|
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) {
|
public CallbackResult match(int lin_idx, String sentence, int offset) {
|
||||||
StringBuilder sbuilder = new StringBuilder();
|
StringBuilder sbuilder = new StringBuilder();
|
||||||
|
|
||||||
@@ -29,8 +37,26 @@ public class NercLiteralCallback implements LiteralCallback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
Expr expr = new Expr(sbuilder.toString());
|
String name = sbuilder.toString();
|
||||||
expr = new Expr("MkSymb", expr);
|
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);
|
return new CallbackResult(new ExprProb(expr, 0), end_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -495,7 +495,7 @@ public class Translator {
|
|||||||
long t1 = System.currentTimeMillis();
|
long t1 = System.currentTimeMillis();
|
||||||
mConcr = mGrammarLoader.getGrammar().getLanguages().get(mLanguage.getConcrete());
|
mConcr = mGrammarLoader.getGrammar().getLanguages().get(mLanguage.getConcrete());
|
||||||
mConcr.load(in);
|
mConcr.load(in);
|
||||||
mConcr.addLiteral("Symb", new NercLiteralCallback());
|
mConcr.addLiteral("PN", new NercLiteralCallback(mGrammarLoader.getGrammar(), mConcr));
|
||||||
long t2 = System.currentTimeMillis();
|
long t2 = System.currentTimeMillis();
|
||||||
Log.d(TAG, name + " loaded ("+(t2-t1)+" ms)");
|
Log.d(TAG, name + " loaded ("+(t2-t1)+" ms)");
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user