From 3381ae1aa009fd26455639bf4affb262414ab40e Mon Sep 17 00:00:00 2001 From: krasimir Date: Mon, 30 May 2016 11:25:59 +0000 Subject: added getFunctionProb in the Java and C API --- src/runtime/java/jpgf.c | 12 ++++++++++++ src/runtime/java/org/grammaticalframework/pgf/PGF.java | 6 ++++++ 2 files changed, 18 insertions(+) (limited to 'src/runtime/java') diff --git a/src/runtime/java/jpgf.c b/src/runtime/java/jpgf.c index bbe8ff2f6..9383ccc20 100644 --- a/src/runtime/java/jpgf.c +++ b/src/runtime/java/jpgf.c @@ -178,6 +178,18 @@ Java_org_grammaticalframework_pgf_PGF_getFunctionType(JNIEnv* env, jobject self, return jtype; } +JNIEXPORT jdouble JNICALL +Java_org_grammaticalframework_pgf_PGF_getFunctionProb(JNIEnv* env, jobject self, jstring jid) +{ + PgfPGF* pgf = get_ref(env, self); + GuPool* tmp_pool = gu_local_pool(); + PgfCId id = j2gu_string(env, jid, tmp_pool); + double prob = pgf_function_prob(pgf, id); + gu_pool_free(tmp_pool); + + return prob; +} + typedef struct { GuMapItor fn; JNIEnv *env; diff --git a/src/runtime/java/org/grammaticalframework/pgf/PGF.java b/src/runtime/java/org/grammaticalframework/pgf/PGF.java index 6d999f97b..c19264f62 100644 --- a/src/runtime/java/org/grammaticalframework/pgf/PGF.java +++ b/src/runtime/java/org/grammaticalframework/pgf/PGF.java @@ -42,6 +42,12 @@ public class PGF { */ public native Type getFunctionType(String fun); + /** Returns the negative logarithmic probability of the function + * with the given name. + * @param fun The name of the function. + */ + public native double getFunctionProb(String fun); + /** Returns an iterable over the set of all expression in * the given category. The expressions are enumerated in decreasing * probability order. -- cgit v1.2.3