mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-10 05:29:30 -06:00
change the API for literals in Java and Python. The input sentence is no longer a parameter to the callbacks.
This commit is contained in:
@@ -422,9 +422,8 @@ jpgf_literal_callback_match(PgfLiteralCallback* self, PgfConcr* concr,
|
||||
JNIEnv *env;
|
||||
(*cachedJVM)->AttachCurrentThread(cachedJVM, (void**)&env, NULL);
|
||||
|
||||
jstring jsentence = gu2j_string(env, sentence);
|
||||
size_t joffset = gu2j_string_offset(sentence, *poffset);
|
||||
jobject result = (*env)->CallObjectMethod(env, callback->jcallback, callback->match_methodId, lin_idx, jsentence, joffset);
|
||||
jobject result = (*env)->CallObjectMethod(env, callback->jcallback, callback->match_methodId, lin_idx, joffset);
|
||||
if (result == NULL)
|
||||
return NULL;
|
||||
|
||||
@@ -539,7 +538,7 @@ JNIEXPORT void JNICALL Java_org_grammaticalframework_pgf_Parser_addLiteralCallba
|
||||
callback->fin.fn = jpgf_literal_callback_fin;
|
||||
|
||||
jclass callback_class = (*env)->GetObjectClass(env, jcallback);
|
||||
callback->match_methodId = (*env)->GetMethodID(env, callback_class, "match", "(ILjava/lang/String;I)Lorg/grammaticalframework/pgf/LiteralCallback$CallbackResult;");
|
||||
callback->match_methodId = (*env)->GetMethodID(env, callback_class, "match", "(II)Lorg/grammaticalframework/pgf/LiteralCallback$CallbackResult;");
|
||||
callback->predict_methodId = (*env)->GetMethodID(env, callback_class, "predict", "(ILjava/lang/String;)Ljava/util/Iterator;");
|
||||
|
||||
gu_pool_finally(pool, &callback->fin);
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.grammaticalframework.pgf;
|
||||
import java.util.Iterator;
|
||||
|
||||
public interface LiteralCallback {
|
||||
public CallbackResult match(int lin_idx, String sentence, int start_offset);
|
||||
public CallbackResult match(int lin_idx, int start_offset);
|
||||
|
||||
public Iterator<TokenProb> predict(int lin_idx, String prefix);
|
||||
|
||||
|
||||
@@ -11,13 +11,15 @@ import java.util.Iterator;
|
||||
public class NercLiteralCallback implements LiteralCallback {
|
||||
private PGF pgf;
|
||||
private Concr concr;
|
||||
private String sentence;
|
||||
|
||||
public NercLiteralCallback(PGF pgf, Concr concr) {
|
||||
public NercLiteralCallback(PGF pgf, Concr concr, String sentence) {
|
||||
this.pgf = pgf;
|
||||
this.concr = concr;
|
||||
this.sentence = sentence;
|
||||
}
|
||||
|
||||
public CallbackResult match(int lin_idx, String sentence, int offset) {
|
||||
public CallbackResult match(int lin_idx, int offset) {
|
||||
StringBuilder sbuilder = new StringBuilder();
|
||||
|
||||
int i = 0;
|
||||
|
||||
@@ -8,12 +8,14 @@ import java.util.Iterator;
|
||||
*/
|
||||
public class UnknownLiteralCallback implements LiteralCallback {
|
||||
private Concr concr;
|
||||
private String sentence;
|
||||
|
||||
public UnknownLiteralCallback(Concr concr) {
|
||||
public UnknownLiteralCallback(Concr concr, String sentence) {
|
||||
this.concr = concr;
|
||||
this.sentence = sentence;
|
||||
}
|
||||
|
||||
public CallbackResult match(int lin_idx, String sentence, int offset) {
|
||||
public CallbackResult match(int lin_idx, int offset) {
|
||||
if (offset < sentence.length() &&
|
||||
!Character.isUpperCase(sentence.charAt(offset))) {
|
||||
int start_offset = offset;
|
||||
|
||||
Reference in New Issue
Block a user