1
0
forked from GitHub/gf-core

word completion in the C parser now returns information about the function which generates the token

This commit is contained in:
Krasimir Angelov
2017-09-06 14:37:51 +02:00
parent ef071d9157
commit 301b100988
5 changed files with 19 additions and 5 deletions

View File

@@ -1254,9 +1254,12 @@ pgf_parsing_add_transition(PgfParsing* ps, PgfToken tok, PgfItem* item)
if (ps->prefix != NULL && *current == 0) { if (ps->prefix != NULL && *current == 0) {
if (gu_string_is_prefix(ps->prefix, tok)) { if (gu_string_is_prefix(ps->prefix, tok)) {
PgfProductionApply* papp = gu_variant_data(item->prod);
ps->tp = gu_new(PgfTokenProb, ps->out_pool); ps->tp = gu_new(PgfTokenProb, ps->out_pool);
ps->tp->tok = tok; ps->tp->tok = tok;
ps->tp->cat = item->conts->ccat->cnccat->abscat->name; ps->tp->cat = item->conts->ccat->cnccat->abscat->name;
ps->tp->fun = papp->fun->absfun->name;
ps->tp->prob = item->inside_prob + item->conts->outside_prob; ps->tp->prob = item->inside_prob + item->conts->outside_prob;
} }
} else { } else {

View File

@@ -200,6 +200,7 @@ pgf_parse_with_oracle(PgfConcr* concr, PgfType* typ,
typedef struct { typedef struct {
PgfToken tok; PgfToken tok;
PgfCId cat; PgfCId cat;
PgfCId fun;
prob_t prob; prob_t prob;
} PgfTokenProb; } PgfTokenProb;

View File

@@ -731,8 +731,8 @@ Java_org_grammaticalframework_pgf_TokenIterator_fetchTokenProb(JNIEnv* env, jcla
return NULL; return NULL;
jclass tp_class = (*env)->FindClass(env, "org/grammaticalframework/pgf/TokenProb"); jclass tp_class = (*env)->FindClass(env, "org/grammaticalframework/pgf/TokenProb");
jmethodID tp_constrId = (*env)->GetMethodID(env, tp_class, "<init>", "(DLjava/lang/String;Ljava/lang/String;)V"); jmethodID tp_constrId = (*env)->GetMethodID(env, tp_class, "<init>", "(DLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
jobject jtp = (*env)->NewObject(env, tp_class, tp_constrId, tp->prob, gu2j_string(env,tp->tok), gu2j_string(env,tp->cat)); jobject jtp = (*env)->NewObject(env, tp_class, tp_constrId, (double) tp->prob, gu2j_string(env,tp->tok), gu2j_string(env,tp->cat), gu2j_string(env,tp->fun));
return jtp; return jtp;
} }

View File

@@ -4,12 +4,14 @@ package org.grammaticalframework.pgf;
public class TokenProb { public class TokenProb {
private String tok; private String tok;
private String cat; private String cat;
private String fun;
private double prob; private double prob;
public TokenProb(double prob, String tok, String cat) { public TokenProb(double prob, String tok, String cat, String fun) {
this.prob = prob; this.prob = prob;
this.tok = tok; this.tok = tok;
this.cat = cat; this.cat = cat;
this.fun = fun;
} }
/** Returns the negative logarithmic probability. */ /** Returns the negative logarithmic probability. */
@@ -26,4 +28,9 @@ public class TokenProb {
public String getCategory() { public String getCategory() {
return cat; return cat;
} }
/** Returns the function from which this word was predicted. */
public String getFunction() {
return fun;
}
} }

View File

@@ -1163,7 +1163,10 @@ Iter_fetch_token(IterObject* self)
PyObject* py_tok = PyString_FromString(tp->tok); PyObject* py_tok = PyString_FromString(tp->tok);
PyObject* py_cat = PyString_FromString(tp->cat); PyObject* py_cat = PyString_FromString(tp->cat);
PyObject* res = Py_BuildValue("(f,O,O)", tp->prob, py_tok, py_cat); PyObject* py_fun = PyString_FromString(tp->fun);
PyObject* res = Py_BuildValue("(f,O,O,O)", tp->prob, py_tok, py_cat, py_fun);
Py_DECREF(py_fun);
Py_DECREF(py_cat);
Py_DECREF(py_tok); Py_DECREF(py_tok);
return res; return res;