summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/runtime/c/pgf/pgf.c11
-rw-r--r--src/runtime/c/pgf/pgf.h3
-rw-r--r--src/runtime/java/jpgf.c12
-rw-r--r--src/runtime/java/org/grammaticalframework/pgf/PGF.java6
4 files changed, 32 insertions, 0 deletions
diff --git a/src/runtime/c/pgf/pgf.c b/src/runtime/c/pgf/pgf.c
index 0070e5f48..370b9411b 100644
--- a/src/runtime/c/pgf/pgf.c
+++ b/src/runtime/c/pgf/pgf.c
@@ -165,6 +165,17 @@ pgf_function_type(PgfPGF* pgf, PgfCId funname)
return absfun->type;
}
+double
+pgf_function_prob(PgfPGF* pgf, PgfCId funname)
+{
+ PgfAbsFun* absfun =
+ gu_seq_binsearch(pgf->abstract.funs, pgf_absfun_order, PgfAbsFun, funname);
+ if (absfun == NULL)
+ return INFINITY;
+
+ return absfun->ep.prob;
+}
+
GuString
pgf_print_name(PgfConcr* concr, PgfCId id)
{
diff --git a/src/runtime/c/pgf/pgf.h b/src/runtime/c/pgf/pgf.h
index 4a6199c6f..365d20d73 100644
--- a/src/runtime/c/pgf/pgf.h
+++ b/src/runtime/c/pgf/pgf.h
@@ -66,6 +66,9 @@ pgf_iter_functions_by_cat(PgfPGF* pgf, PgfCId catname,
PgfType*
pgf_function_type(PgfPGF* pgf, PgfCId funname);
+double
+pgf_function_prob(PgfPGF* pgf, PgfCId funname);
+
GuString
pgf_print_name(PgfConcr*, PgfCId id);
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.