1
0
forked from GitHub/gf-core

linearization in the Java binding

This commit is contained in:
kr.angelov
2013-08-27 22:39:26 +00:00
parent e1df8e713c
commit e274cce213
3 changed files with 27 additions and 1 deletions

View File

@@ -20,8 +20,10 @@ public class Test {
System.out.println(entry.getKey()+" "+entry.getValue()+" "+entry.getValue().getName());
}
for (ExprProb ep : gr.getLanguages().get("ParseEng").parse("Phr", "test")) {
Concr eng = gr.getLanguages().get("ParseEng");
for (ExprProb ep : eng.parse("Phr", "where are you")) {
System.out.println("["+ep.getProb()+"] "+ep.getExpr());
System.out.println(eng.linearize(ep.getExpr()));
}
}
}

View File

@@ -244,6 +244,28 @@ Java_org_grammaticalframework_pgf_ExprIterator_fetchExprProb
return jexpprob;
}
JNIEXPORT jstring JNICALL
Java_org_grammaticalframework_pgf_Concr_linearize(JNIEnv* env, jobject self, jobject jexpr)
{
GuPool* tmp_pool = gu_local_pool();
GuExn* err = gu_new_exn(NULL, gu_kind(type), tmp_pool);
GuStringBuf* sbuf = gu_string_buf(tmp_pool);
GuWriter* wtr = gu_string_buf_writer(sbuf);
pgf_linearize(get_ref(env, self), gu_variant_from_ptr((void*) get_ref(env, jexpr)), wtr, err);
if (!gu_ok(err)) {
//
return NULL;
}
GuString str = gu_string_buf_freeze(sbuf, tmp_pool);
jstring jstr = gu2j_string(env, str);
gu_pool_free(tmp_pool);
return jstr;
}
JNIEXPORT void JNICALL
Java_org_grammaticalframework_pgf_Pool_free(JNIEnv* env, jobject self, jlong ref)
{

View File

@@ -9,6 +9,8 @@ public class Concr {
public Iterable<ExprProb> parse(String startCat, String s) {
return new Parser(this, startCat, s);
}
public native String linearize(Expr expr);
//////////////////////////////////////////////////////////////////
// private stuff