forked from GitHub/gf-core
more carefull tracking of references in the Java binding
This commit is contained in:
@@ -24,7 +24,7 @@ public class Test {
|
|||||||
Concr ger = gr.getLanguages().get("PhrasebookGer");
|
Concr ger = gr.getLanguages().get("PhrasebookGer");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (ExprProb ep : eng.parse(gr.getStartCat(), "where is the conference")) {
|
for (ExprProb ep : eng.parse(gr.getStartCat(), "where is the hotel")) {
|
||||||
System.out.println("["+ep.getProb()+"] "+ep.getExpr());
|
System.out.println("["+ep.getProb()+"] "+ep.getExpr());
|
||||||
System.out.println(ger.linearize(ep.getExpr()));
|
System.out.println(ger.linearize(ep.getExpr()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ Java_org_grammaticalframework_pgf_Concr_getName(JNIEnv* env, jobject self)
|
|||||||
|
|
||||||
JNIEXPORT jobject JNICALL
|
JNIEXPORT jobject JNICALL
|
||||||
Java_org_grammaticalframework_pgf_Parser_parse
|
Java_org_grammaticalframework_pgf_Parser_parse
|
||||||
(JNIEnv* env, jclass self, jobject concr, jstring jstartCat, jstring js)
|
(JNIEnv* env, jclass clazz, jobject concr, jstring jstartCat, jstring js)
|
||||||
{
|
{
|
||||||
GuPool* pool = gu_new_pool();
|
GuPool* pool = gu_new_pool();
|
||||||
GuPool* out_pool = gu_new_pool();
|
GuPool* out_pool = gu_new_pool();
|
||||||
@@ -229,16 +229,19 @@ Java_org_grammaticalframework_pgf_Parser_parse
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jfieldID refId = (*env)->GetFieldID(env, (*env)->GetObjectClass(env, concr), "gr", "Lorg/grammaticalframework/pgf/PGF;");
|
||||||
|
jobject jpgf = (*env)->GetObjectField(env, concr, refId);
|
||||||
|
|
||||||
jclass expiter_class = (*env)->FindClass(env, "org/grammaticalframework/pgf/ExprIterator");
|
jclass expiter_class = (*env)->FindClass(env, "org/grammaticalframework/pgf/ExprIterator");
|
||||||
jmethodID constrId = (*env)->GetMethodID(env, expiter_class, "<init>", "(Lorg/grammaticalframework/pgf/Concr;JJJ)V");
|
jmethodID constrId = (*env)->GetMethodID(env, expiter_class, "<init>", "(Lorg/grammaticalframework/pgf/PGF;JJJ)V");
|
||||||
jobject jexpiter = (*env)->NewObject(env, expiter_class, constrId, concr, (jlong) pool, (jlong) out_pool, (jlong) res);
|
jobject jexpiter = (*env)->NewObject(env, expiter_class, constrId, jpgf, (jlong) pool, (jlong) out_pool, (jlong) res);
|
||||||
|
|
||||||
return jexpiter;
|
return jexpiter;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jobject JNICALL
|
JNIEXPORT jobject JNICALL
|
||||||
Java_org_grammaticalframework_pgf_ExprIterator_fetchExprProb
|
Java_org_grammaticalframework_pgf_ExprIterator_fetchExprProb
|
||||||
(JNIEnv* env, jobject self, jlong enumRef, jobject out_pool)
|
(JNIEnv* env, jobject self, jlong enumRef, jobject pool, jobject gr)
|
||||||
{
|
{
|
||||||
GuEnum* res = (GuEnum*) enumRef;
|
GuEnum* res = (GuEnum*) enumRef;
|
||||||
|
|
||||||
@@ -247,9 +250,10 @@ Java_org_grammaticalframework_pgf_ExprIterator_fetchExprProb
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
jclass expprob_class = (*env)->FindClass(env, "org/grammaticalframework/pgf/ExprProb");
|
jclass expprob_class = (*env)->FindClass(env, "org/grammaticalframework/pgf/ExprProb");
|
||||||
jmethodID methodId = (*env)->GetStaticMethodID(env, expprob_class, "mkExprProb", "(Lorg/grammaticalframework/pgf/Pool;JD)Lorg/grammaticalframework/pgf/ExprProb;");
|
jmethodID methodId = (*env)->GetStaticMethodID(env, expprob_class, "mkExprProb",
|
||||||
|
"(Lorg/grammaticalframework/pgf/Pool;Lorg/grammaticalframework/pgf/PGF;JD)Lorg/grammaticalframework/pgf/ExprProb;");
|
||||||
jobject jexpprob = (*env)->CallStaticObjectMethod(env, expprob_class, methodId,
|
jobject jexpprob = (*env)->CallStaticObjectMethod(env, expprob_class, methodId,
|
||||||
out_pool, (jlong) gu_variant_to_ptr(ep->expr), (double) ep->prob);
|
pool, gr, (jlong) gu_variant_to_ptr(ep->expr), (double) ep->prob);
|
||||||
|
|
||||||
return jexpprob;
|
return jexpprob;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,15 @@ package org.grammaticalframework.pgf;
|
|||||||
|
|
||||||
public class Expr {
|
public class Expr {
|
||||||
private Pool pool;
|
private Pool pool;
|
||||||
|
private PGF gr;
|
||||||
private long ref;
|
private long ref;
|
||||||
|
|
||||||
Expr(Pool pool, long ref) {
|
Expr(Pool pool, PGF gr, long ref) {
|
||||||
this.pool = pool;
|
this.pool = pool;
|
||||||
|
this.gr = gr;
|
||||||
this.ref = ref;
|
this.ref = ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return showExpr(ref);
|
return showExpr(ref);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ package org.grammaticalframework.pgf;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
class ExprIterator implements Iterator<ExprProb> {
|
class ExprIterator implements Iterator<ExprProb> {
|
||||||
private Concr concr;
|
private PGF gr;
|
||||||
private Pool pool, out_pool;
|
private Pool pool, out_pool;
|
||||||
private long ref;
|
private long ref;
|
||||||
private ExprProb ep;
|
private ExprProb ep;
|
||||||
private boolean fetched;
|
private boolean fetched;
|
||||||
|
|
||||||
public ExprIterator(Concr concr, long pool, long out_pool, long ref) {
|
public ExprIterator(PGF gr, long pool, long out_pool, long ref) {
|
||||||
this.concr = concr;
|
this.gr = gr;
|
||||||
this.pool = new Pool(pool);
|
this.pool = new Pool(pool);
|
||||||
this.out_pool = new Pool(out_pool);
|
this.out_pool = new Pool(out_pool);
|
||||||
this.ref = ref;
|
this.ref = ref;
|
||||||
@@ -18,20 +18,20 @@ class ExprIterator implements Iterator<ExprProb> {
|
|||||||
this.fetched = false;
|
this.fetched = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private native ExprProb fetchExprProb(long ref, Pool out_pool);
|
private native ExprProb fetchExprProb(long ref, Pool pool, PGF gr);
|
||||||
|
|
||||||
private void fetch() {
|
private void fetch() {
|
||||||
if (!fetched) {
|
if (!fetched) {
|
||||||
ep = fetchExprProb(ref, out_pool);
|
ep = fetchExprProb(ref, out_pool, gr);
|
||||||
fetched = true;
|
fetched = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
fetch();
|
fetch();
|
||||||
return (ep != null);
|
return (ep != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExprProb next() {
|
public ExprProb next() {
|
||||||
fetch();
|
fetch();
|
||||||
fetched = false;
|
fetched = false;
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ public class ExprProb {
|
|||||||
this.prob = prob;
|
this.prob = prob;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ExprProb mkExprProb(Pool pool, long expr, double prob) {
|
private static ExprProb mkExprProb(Pool pool, PGF gr, long expr, double prob) {
|
||||||
return new ExprProb(new Expr(pool, expr), prob);
|
return new ExprProb(new Expr(pool, gr, expr), prob);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Expr getExpr() {
|
public Expr getExpr() {
|
||||||
|
|||||||
Reference in New Issue
Block a user