mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 11:42:49 -06:00
an initial skeleton for building a Java binding to the C runtime
This commit is contained in:
7
src/runtime/java/Makefile
Normal file
7
src/runtime/java/Makefile
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
all:
|
||||||
|
libtool --mode=compile gcc -I /usr/lib/jvm/java-6-openjdk/include -std=c99 -c jpgf.c
|
||||||
|
libtool --mode=link gcc -g -O -o libjpgf.la jpgf.lo -rpath /usr/lib -lpgf -lgu
|
||||||
|
libtool --mode=install cp libjpgf.la /usr/lib/libjpgf.la
|
||||||
|
|
||||||
|
headers:
|
||||||
|
javah org.grammaticalframework.PGF
|
||||||
31
src/runtime/java/jpgf.c
Normal file
31
src/runtime/java/jpgf.c
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#include <pgf/pgf.h>
|
||||||
|
#include <gu/mem.h>
|
||||||
|
#include "org_grammaticalframework_PGF.h"
|
||||||
|
|
||||||
|
JNIEXPORT jobject JNICALL
|
||||||
|
Java_org_grammaticalframework_PGF_readPGF(JNIEnv *env, jclass cls, jstring s)
|
||||||
|
{
|
||||||
|
const char *fpath = (*env)->GetStringUTFChars(env, s, 0);
|
||||||
|
|
||||||
|
GuPool* pool = gu_new_pool();
|
||||||
|
GuPool* tmp_pool = gu_local_pool();
|
||||||
|
|
||||||
|
// Create an exception frame that catches all errors.
|
||||||
|
GuExn* err = gu_new_exn(NULL, gu_kind(type), tmp_pool);
|
||||||
|
|
||||||
|
// Read the PGF grammar.
|
||||||
|
PgfPGF* pgf = pgf_read(fpath, pool, err);
|
||||||
|
if (!gu_ok(err)) {
|
||||||
|
gu_pool_free(pool);
|
||||||
|
gu_pool_free(tmp_pool);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
gu_pool_free(tmp_pool);
|
||||||
|
|
||||||
|
(*env)->ReleaseStringUTFChars(env, s, fpath);
|
||||||
|
|
||||||
|
jmethodID constrId = (*env)->GetMethodID(env, cls, "<init>", "(II)V");
|
||||||
|
|
||||||
|
return (*env)->NewObject(env, cls, constrId, (int) pool, (int) pgf);
|
||||||
|
}
|
||||||
25
src/runtime/java/org/grammaticalframework/PGF.java
Normal file
25
src/runtime/java/org/grammaticalframework/PGF.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package org.grammaticalframework;
|
||||||
|
|
||||||
|
public class PGF {
|
||||||
|
static native PGF readPGF(String path);
|
||||||
|
|
||||||
|
private int pool;
|
||||||
|
private int gr;
|
||||||
|
|
||||||
|
private PGF(int pool, int gr) {
|
||||||
|
this.pool = pool;
|
||||||
|
this.gr = gr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
System.loadLibrary("jpgf");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test() {
|
||||||
|
System.out.println("pool="+pool+", gr="+gr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
readPGF("/home/krasimir/www.grammaticalframework.org/treebanks/PennTreebank/ParseEngAbs.pgf").test();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user