now the named entities recognizer returns dictionary entries if the name is known

This commit is contained in:
kr.angelov
2014-06-17 06:57:12 +00:00
parent 9944916127
commit fe49ddf16d
4 changed files with 31 additions and 4 deletions

View File

@@ -9,7 +9,7 @@ Phrasebook:
cd ../phrasebook ; make forApp ; cd ../app
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

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -495,7 +495,7 @@ public class Translator {
long t1 = System.currentTimeMillis();
mConcr = mGrammarLoader.getGrammar().getLanguages().get(mLanguage.getConcrete());
mConcr.load(in);
mConcr.addLiteral("Symb", new NercLiteralCallback());
mConcr.addLiteral("PN", new NercLiteralCallback(mGrammarLoader.getGrammar(), mConcr));
long t2 = System.currentTimeMillis();
Log.d(TAG, name + " loaded ("+(t2-t1)+" ms)");
} catch (FileNotFoundException e) {