mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
added linearizeAll in the Java API
This commit is contained in:
@@ -695,6 +695,68 @@ Java_org_grammaticalframework_pgf_Concr_linearize(JNIEnv* env, jobject self, job
|
|||||||
return jstr;
|
return jstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jobject JNICALL
|
||||||
|
Java_org_grammaticalframework_pgf_Concr_linearizeAll(JNIEnv* env, jobject self, jobject jexpr)
|
||||||
|
{
|
||||||
|
PgfConcr* concr = get_ref(env, self);
|
||||||
|
|
||||||
|
jclass list_class = (*env)->FindClass(env, "java/util/ArrayList");
|
||||||
|
jmethodID list_constrId = (*env)->GetMethodID(env, list_class, "<init>", "()V");
|
||||||
|
jobject strings = (*env)->NewObject(env, list_class, list_constrId);
|
||||||
|
|
||||||
|
jmethodID addId = (*env)->GetMethodID(env, list_class, "add", "(Ljava/lang/Object;)Z");
|
||||||
|
|
||||||
|
GuPool* tmp_pool = gu_local_pool();
|
||||||
|
GuExn* err = gu_exn(tmp_pool);
|
||||||
|
|
||||||
|
GuEnum* cts =
|
||||||
|
pgf_lzr_concretize(concr,
|
||||||
|
gu_variant_from_ptr((void*) get_ref(env, jexpr)),
|
||||||
|
err, tmp_pool);
|
||||||
|
if (!gu_ok(err)) {
|
||||||
|
gu_pool_free(tmp_pool);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
PgfCncTree ctree = gu_next(cts, PgfCncTree, tmp_pool);
|
||||||
|
if (gu_variant_is_null(ctree))
|
||||||
|
break;
|
||||||
|
|
||||||
|
GuPool* step_pool = gu_local_pool();
|
||||||
|
GuStringBuf* sbuf = gu_string_buf(step_pool);
|
||||||
|
GuOut* out = gu_string_buf_out(sbuf);
|
||||||
|
|
||||||
|
ctree = pgf_lzr_wrap_linref(ctree, step_pool);
|
||||||
|
pgf_lzr_linearize_simple(concr, ctree, 0, out, err, step_pool);
|
||||||
|
if (!gu_ok(err)) {
|
||||||
|
gu_pool_free(step_pool);
|
||||||
|
|
||||||
|
if (gu_exn_caught(err, PgfLinNonExist)) {
|
||||||
|
continue;
|
||||||
|
} else if (gu_exn_caught(err, PgfExn)) {
|
||||||
|
GuString msg = (GuString) gu_exn_caught_data(err);
|
||||||
|
throw_string_exception(env, "org/grammaticalframework/pgf/PGFError", msg);
|
||||||
|
} else {
|
||||||
|
throw_string_exception(env, "org/grammaticalframework/pgf/PGFError", "The expression cannot be linearized");
|
||||||
|
}
|
||||||
|
gu_pool_free(tmp_pool);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
GuString str = gu_string_buf_freeze(sbuf, step_pool);
|
||||||
|
jstring jstr = gu2j_string(env, str);
|
||||||
|
|
||||||
|
(*env)->CallBooleanMethod(env, strings, addId, jstr);
|
||||||
|
|
||||||
|
gu_pool_free(step_pool);
|
||||||
|
}
|
||||||
|
|
||||||
|
gu_pool_free(tmp_pool);
|
||||||
|
|
||||||
|
return strings;
|
||||||
|
}
|
||||||
|
|
||||||
JNIEXPORT jobject JNICALL
|
JNIEXPORT jobject JNICALL
|
||||||
Java_org_grammaticalframework_pgf_Concr_tabularLinearize(JNIEnv* env, jobject self, jobject jexpr)
|
Java_org_grammaticalframework_pgf_Concr_tabularLinearize(JNIEnv* env, jobject self, jobject jexpr)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ public class Concr {
|
|||||||
/** Computes the linearization of the abstract expression. */
|
/** Computes the linearization of the abstract expression. */
|
||||||
public native String linearize(Expr expr);
|
public native String linearize(Expr expr);
|
||||||
|
|
||||||
|
/** Computes all linearizations of the abstract expression and returns an iterator over the alternatives. */
|
||||||
|
public native Iterable<String> linearizeAll(Expr expr);
|
||||||
|
|
||||||
/** Linearizes the expression as an inflection table.
|
/** Linearizes the expression as an inflection table.
|
||||||
* @return a map from the name of the inflection form to its value.
|
* @return a map from the name of the inflection form to its value.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user