mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-22 19:22:50 -06:00
added API in the C runtime and the Java binding for checking whether a given function is linearizable in a given language. This is used in the Android UI for better vizualizations
This commit is contained in:
@@ -158,3 +158,11 @@ pgf_print_name(PgfConcr* concr, PgfCId id)
|
|||||||
name = id;
|
name = id;
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
pgf_has_linearization(PgfConcr* concr, PgfCId id)
|
||||||
|
{
|
||||||
|
PgfCncOverloadMap* overl_table =
|
||||||
|
gu_map_get(concr->fun_indices, id, PgfCncOverloadMap*);
|
||||||
|
return (overl_table != NULL);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,27 +1,3 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010 University of Gothenburg.
|
|
||||||
*
|
|
||||||
* This file is part of libpgf.
|
|
||||||
*
|
|
||||||
* Libpgf is free software: you can redistribute it and/or modify it under
|
|
||||||
* the terms of the GNU Lesser General Public License as published by the
|
|
||||||
* Free Software Foundation, either version 3 of the License, or (at your
|
|
||||||
* option) any later version.
|
|
||||||
*
|
|
||||||
* Libpgf is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
||||||
* License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with libpgf. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @file
|
|
||||||
*
|
|
||||||
* The public libpgf API.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef PGF_H_
|
#ifndef PGF_H_
|
||||||
#define PGF_H_
|
#define PGF_H_
|
||||||
|
|
||||||
@@ -114,6 +90,9 @@ pgf_function_type(PgfPGF* pgf, PgfCId funname);
|
|||||||
GuString
|
GuString
|
||||||
pgf_print_name(PgfConcr*, PgfCId id);
|
pgf_print_name(PgfConcr*, PgfCId id);
|
||||||
|
|
||||||
|
bool
|
||||||
|
pgf_has_linearization(PgfConcr* concr, PgfCId id);
|
||||||
|
|
||||||
void
|
void
|
||||||
pgf_linearize(PgfConcr* concr, PgfExpr expr, GuOut* out, GuExn* err);
|
pgf_linearize(PgfConcr* concr, PgfExpr expr, GuOut* out, GuExn* err);
|
||||||
|
|
||||||
|
|||||||
@@ -472,6 +472,17 @@ Java_org_grammaticalframework_pgf_Concr_lookupMorpho(JNIEnv* env, jobject self,
|
|||||||
return analyses;
|
return analyses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jboolean JNICALL
|
||||||
|
Java_org_grammaticalframework_pgf_Concr_hasLinearization(JNIEnv* env, jobject self, jstring jid)
|
||||||
|
{
|
||||||
|
PgfConcr* concr = get_ref(env, self);
|
||||||
|
GuPool* tmp_pool = gu_new_pool();
|
||||||
|
PgfCId id = j2gu_string(env, jid, tmp_pool);
|
||||||
|
bool res = pgf_has_linearization(concr, id);
|
||||||
|
gu_pool_free(tmp_pool);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_org_grammaticalframework_pgf_Pool_free(JNIEnv* env, jobject self, jlong ref)
|
Java_org_grammaticalframework_pgf_Pool_free(JNIEnv* env, jobject self, jlong ref)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ public class Concr {
|
|||||||
|
|
||||||
public native List<MorphoAnalysis> lookupMorpho(String sentence);
|
public native List<MorphoAnalysis> lookupMorpho(String sentence);
|
||||||
|
|
||||||
|
public native boolean hasLinearization(String id);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
// private stuff
|
// private stuff
|
||||||
|
|
||||||
|
|||||||
@@ -211,8 +211,7 @@ public class LexicalEntryActivity extends ListActivity {
|
|||||||
TextView descView =
|
TextView descView =
|
||||||
(TextView) convertView.findViewById(R.id.lexical_desc);
|
(TextView) convertView.findViewById(R.id.lexical_desc);
|
||||||
|
|
||||||
Expr e = Expr.readExpr(lemma);
|
String phrase = mTranslator.generateTranslationEntry(lemma);
|
||||||
String phrase = mTranslator.generateTranslationEntry(e);
|
|
||||||
descView.setText(phrase);
|
descView.setText(phrase);
|
||||||
|
|
||||||
convertView.setOnClickListener(new OnClickListener() {
|
convertView.setOnClickListener(new OnClickListener() {
|
||||||
|
|||||||
@@ -131,10 +131,14 @@ public class Translator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String generateTranslationEntry(Expr e) {
|
public String generateTranslationEntry(String lemma) {
|
||||||
|
Expr e = Expr.readExpr(lemma);
|
||||||
Concr sourceLang = getConcr(getSourceLanguage().getConcrete());
|
Concr sourceLang = getConcr(getSourceLanguage().getConcrete());
|
||||||
Concr targetLang = getConcr(getTargetLanguage().getConcrete());
|
Concr targetLang = getConcr(getTargetLanguage().getConcrete());
|
||||||
return sourceLang.linearize(e) + " - " + targetLang.linearize(e);
|
if (targetLang.hasLinearization(lemma))
|
||||||
|
return sourceLang.linearize(e) + " - " + targetLang.linearize(e);
|
||||||
|
else
|
||||||
|
return sourceLang.linearize(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String,String> tabularLinearize(Expr e) {
|
public Map<String,String> tabularLinearize(Expr e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user