better dictionary visualization in the Android App

This commit is contained in:
kr.angelov
2013-11-27 22:16:05 +00:00
parent eea636966d
commit f5ec987c5d
9 changed files with 1309 additions and 1077 deletions

View File

@@ -212,6 +212,25 @@ Java_org_grammaticalframework_pgf_PGF_getStartCat(JNIEnv* env, jobject self)
return gu2j_string(env, pgf_start_cat(get_ref(env, self))); return gu2j_string(env, pgf_start_cat(get_ref(env, self)));
} }
JNIEXPORT jobject JNICALL
Java_org_grammaticalframework_pgf_PGF_getFunctionType(JNIEnv* env, jobject self, jstring jid)
{
PgfPGF* pgf = get_ref(env, self);
GuPool* tmp_pool = gu_new_pool();
PgfCId id = j2gu_string(env, jid, tmp_pool);
PgfType* tp = pgf_function_type(pgf, id);
gu_pool_free(tmp_pool);
if (tp == NULL)
return NULL;
jclass type_class = (*env)->FindClass(env, "org/grammaticalframework/pgf/Type");
jmethodID constrId = (*env)->GetMethodID(env, type_class, "<init>", "(Lorg/grammaticalframework/pgf/PGF;J)V");
jobject jtype = (*env)->NewObject(env, type_class, constrId, self, p2l(tp));
return jtype;
}
typedef struct { typedef struct {
GuMapItor fn; GuMapItor fn;
JNIEnv *env; JNIEnv *env;
@@ -535,6 +554,13 @@ Java_org_grammaticalframework_pgf_Expr_readExpr(JNIEnv* env, jclass clazz, jstri
return (*env)->NewObject(env, clazz, constrId, jpool, NULL, p2l(gu_variant_to_ptr(e))); return (*env)->NewObject(env, clazz, constrId, jpool, NULL, p2l(gu_variant_to_ptr(e)));
} }
JNIEXPORT jstring JNICALL
Java_org_grammaticalframework_pgf_Type_getCategory(JNIEnv* env, jobject self)
{
PgfType* tp = get_ref(env, self);
return gu2j_string(env, tp->cid);
}
JNIEXPORT jobject JNICALL JNIEXPORT jobject JNICALL
Java_org_grammaticalframework_pgf_Generator_generateAll(JNIEnv* env, jclass clazz, jobject jpgf, jstring jstartCat) Java_org_grammaticalframework_pgf_Generator_generateAll(JNIEnv* env, jclass clazz, jobject jpgf, jstring jstartCat)
{ {

View File

@@ -0,0 +1,7 @@
package org.grammaticalframework.pgf;
public class Hypo {
public native boolean getBindType();
public native String getVariable();
public native Type getType();
}

View File

@@ -1,4 +1,18 @@
package org.grammaticalframework.pgf; package org.grammaticalframework.pgf;
public class Type { public class Type {
public native String getCategory();
public native Expr[] getExprs();
public native Hypo[] getHypos();
//////////////////////////////////////////////////////////////////
// private stuff
private PGF gr;
private long ref;
private Type(PGF gr, long ref) {
this.gr = gr;
this.ref = ref;
}
} }

File diff suppressed because it is too large Load Diff

View File

@@ -1,67 +1,94 @@
<inflection_temlate> <inflection_template>
<noun> <inflection>
<h1>Noun</h1> <cat>N</cat>
<cat>N2</cat>
<table class="forms-table" rules="all"> <tag>n</tag>
<tr> <template>
<th>s</th> <h1>Noun</h1>
<td><form>s</form></td>
</tr> <table class="forms-table" rules="all">
<tr> <tr>
<th>c</th> <th>s</th>
<td><form>c</form></td> <td><form>s</form></td>
</tr> </tr>
</table> <tr>
</noun> <th>c</th>
<adjective> <td><form>c</form></td>
<h1>Adjective</h1> </tr>
</table>
<table class="forms-table" rules="all"> </template>
<tr> </inflection>
<th>s</th> <inflection>
<td><form>s</form></td> <cat>A</cat>
</tr> <cat>A2</cat>
</table> <tag>a</tag>
</adjective> <template>
<adverb> <h1>Adjective</h1>
<h1>Adverb</h1>
<p><form>s</form></p> <table class="forms-table" rules="all">
</adverb> <tr>
<prep> <th>s</th>
<h1>Preposition</h1> <td><form>s</form></td>
<p><form>prepPre</form> - <form>prepPost</form></p> </tr>
</prep> </table>
<verb> </template>
<h1>Verb</h1> </inflection>
<table class="forms-table" rules="all"> <inflection>
<tr> <cat>Adv</cat>
<th>s</th> <tag>adv</tag>
<td><form>s</form></td> <template>
</tr> <h1>Adverb</h1>
<tr> <p><form>s</form></p>
<th>dp</th> </template>
<td><form>dp</form></td> </inflection>
</tr> <inflection>
<tr> <cat>Prep</cat>
<th>ds</th> <tag>prep</tag>
<td><form>ds</form></td> <template>
</tr> <h1>Preposition</h1>
<tr> <p><form>prepPre</form> - <form>prepPost</form></p>
<th>ep</th> </template>
<td><form>ep</form></td> </inflection>
</tr> <inflection>
<tr> <cat>V</cat>
<th>neg</th> <cat>V2</cat>
<td><form>neg</form></td> <cat>V3</cat>
</tr> <cat>V2V</cat>
<tr> <cat>VV</cat>
<th>pp</th> <cat>VS</cat>
<td><form>pp</form></td> <tag>v</tag>
</tr> <template>
<tr> <h1>Verb</h1>
<th>sn</th> <table class="forms-table" rules="all">
<td><form>sn</form></td> <tr>
</tr> <th>s</th>
</table> <td><form>s</form></td>
</verb> </tr>
</inflection_temlate> <tr>
<th>dp</th>
<td><form>dp</form></td>
</tr>
<tr>
<th>ds</th>
<td><form>ds</form></td>
</tr>
<tr>
<th>ep</th>
<td><form>ep</form></td>
</tr>
<tr>
<th>neg</th>
<td><form>neg</form></td>
</tr>
<tr>
<th>pp</th>
<td><form>pp</form></td>
</tr>
<tr>
<th>sn</th>
<td><form>sn</form></td>
</tr>
</table>
</template>
</inflection>
</inflection_template>

View File

@@ -1,84 +1,111 @@
<inflection_temlate> <inflection_template>
<noun> <inflection>
<h1>Noun</h1> <cat>N</cat>
<cat>N2</cat>
<tag>n</tag>
<template>
<h1>Noun</h1>
<table class="forms-table" rules="all"> <table class="forms-table" rules="all">
<tr> <tr>
<th></th> <th></th>
<th>nom</th> <th>nom</th>
<th>gen</th> <th>gen</th>
</tr> </tr>
<tr> <tr>
<th>sg</th> <th>sg</th>
<td><form>s Sg Nom</form></td> <td><form>s Sg Nom</form></td>
<td><form>s Sg Gen</form></td> <td><form>s Sg Gen</form></td>
</tr> </tr>
<tr> <tr>
<th>pl</th> <th>pl</th>
<td><form>s Pl Nom</form></td> <td><form>s Pl Nom</form></td>
<td><form>s Pl Gen</form></td> <td><form>s Pl Gen</form></td>
</tr> </tr>
</table> </table>
</noun> </template>
<adjective> </inflection>
<h1>Adjective</h1> <inflection>
<cat>A</cat>
<table class="forms-table" rules="all"> <cat>A2</cat>
<tr> <tag>a</tag>
<th></th> <template>
<th>nom</th> <h1>Adjective</h1>
<th>gen</th>
</tr> <table class="forms-table" rules="all">
<tr> <tr>
<th>posit</th> <th></th>
<td><form>s (AAdj Posit Nom)</form></td> <th>nom</th>
<td><form>s (AAdj Posit Gen)</form></td> <th>gen</th>
</tr> </tr>
<tr> <tr>
<th>compar</th> <th>posit</th>
<td><form>s (AAdj Compar Nom)</form></td> <td><form>s (AAdj Posit Nom)</form></td>
<td><form>s (AAdj Compar Gen)</form></td> <td><form>s (AAdj Posit Gen)</form></td>
</tr> </tr>
<tr> <tr>
<th>superl</th> <th>compar</th>
<td><form>s (AAdj Superl Nom)</form></td> <td><form>s (AAdj Compar Nom)</form></td>
<td><form>s (AAdj Superl Gen)</form></td> <td><form>s (AAdj Compar Gen)</form></td>
</tr> </tr>
</table> <tr>
<h1>Adverb</h1> <th>superl</th>
<p><form>s AAdv</form></p> <td><form>s (AAdj Superl Nom)</form></td>
</adjective> <td><form>s (AAdj Superl Gen)</form></td>
<adverb> </tr>
<h1>Adverb</h1> </table>
<p><form>s</form></p> <h1>Adverb</h1>
</adverb> <p><form>s AAdv</form></p>
<prep> </template>
<h1>Preposition</h1> </inflection>
<p><form>s</form></p> <inflection>
</prep> <cat>Adv</cat>
<verb> <tag>adv</tag>
<h1>Verb</h1> <template>
<table class="forms-table" rules="all"> <h1>Adverb</h1>
<tr> <p><form>s</form></p>
<th>infitive</th> </template>
<td><form>s VInf</form></td> </inflection>
</tr> <inflection>
<tr> <cat>Prep</cat>
<th>present</th> <tag>prep</tag>
<td><form>s VPres</form></td> <template>
</tr> <h1>Preposition</h1>
<tr> <p><form>s</form></p>
<th>past</th> </template>
<td><form>s VPast</form></td> </inflection>
</tr> <inflection>
<tr> <cat>V</cat>
<th>past part.</th> <cat>V2</cat>
<td><form>s VPPart</form></td> <cat>V3</cat>
</tr> <cat>V2V</cat>
<tr> <cat>VV</cat>
<th>present part.</th> <cat>VS</cat>
<td><form>s VPresPart</form></td> <tag>v</tag>
</tr> <template>
</table> <h1>Verb</h1>
</verb> <table class="forms-table" rules="all">
</inflection_temlate> <tr>
<th>infitive</th>
<td><form>s VInf</form></td>
</tr>
<tr>
<th>present</th>
<td><form>s VPres</form></td>
</tr>
<tr>
<th>past</th>
<td><form>s VPast</form></td>
</tr>
<tr>
<th>past part.</th>
<td><form>s VPPart</form></td>
</tr>
<tr>
<th>present part.</th>
<td><form>s VPresPart</form></td>
</tr>
</table>
</template>
</inflection>
</inflection_template>

View File

@@ -1,215 +1,242 @@
<inflection_temlate> <inflection_template>
<noun> <inflection>
<h1>Substantiv</h1> <cat>N</cat>
<cat>N2</cat>
<table class="forms-table" rules="all"> <tag>s</tag>
<tr> <template>
<th colspan="2"></th> <h1>Substantiv <lin>Feat<cat/>(<lemma/>)</lin></h1>
<th>obest</th>
<th>best</th> <table class="forms-table" rules="all">
</tr> <tr>
<tr> <th colspan="2"></th>
<th rowspan="2">nom</th> <th>obest</th>
<th>sg</th> <th>best</th>
<td><form>s Sg Indef Nom</form></td> </tr>
<td><form>s Sg Def Nom</form></td> <tr>
<th rowspan="2">nom</th>
</tr> <th>sg</th>
<tr> <td><form>s Sg Indef Nom</form></td>
<th>pl</th> <td><form>s Sg Def Nom</form></td>
<td><form>s Pl Indef Nom</form></td>
<td><form>s Pl Def Nom</form></td> </tr>
</tr> <tr>
<tr> <th>pl</th>
<th rowspan="2">gen</th> <td><form>s Pl Indef Nom</form></td>
<th>sg</th> <td><form>s Pl Def Nom</form></td>
<td><form>s Sg Indef Gen</form></td> </tr>
<td><form>s Sg Def Gen</form></td> <tr>
</tr> <th rowspan="2">gen</th>
<tr> <th>sg</th>
<th>pl</th> <td><form>s Sg Indef Gen</form></td>
<td><form>s Pl Indef Gen</form></td> <td><form>s Sg Def Gen</form></td>
<td><form>s Pl Def Gen</form></td> </tr>
</tr> <tr>
</table> <th>pl</th>
</noun> <td><form>s Pl Indef Gen</form></td>
<adjective> <td><form>s Pl Def Gen</form></td>
<h1>Adjektiv</h1> </tr>
</table>
<table class="forms-table" rules="all"> </template>
<tr> </inflection>
<th colspan="5">nominativ</th> <inflection>
</tr> <cat>A</cat>
<tr> <cat>A2</cat>
<th colspan="2"></th> <tag>a</tag>
<th>posit</th> <template>
<th>kompar</th> <h1>Adjektiv</h1>
<th>superl</th>
</tr> <table class="forms-table" rules="all">
<tr> <tr>
<th rowspan="3">obest</th> <th colspan="5">nominativ</th>
<th>utr</th> </tr>
<td><form>s (AF (APosit (Strong (GSg Utr))) Nom)</form></td> <tr>
<td rowspan="5"><form>s (AF ACompar Nom)</form></td> <th colspan="2"></th>
<td rowspan="3"><form>s (AF (ASuperl SupStrong) Nom)</form></td> <th>posit</th>
</tr> <th>kompar</th>
<tr> <th>superl</th>
<th>neut</th> </tr>
<td><form>s (AF (APosit (Strong (GSg Neutr))) Nom)</form></td> <tr>
</tr> <th rowspan="3">obest</th>
<tr> <th>utr</th>
<th>pl</th> <td><form>s (AF (APosit (Strong (GSg Utr))) Nom)</form></td>
<td><form>s (AF (APosit (Strong GPl)) Nom)</form></td> <td rowspan="5"><form>s (AF ACompar Nom)</form></td>
</tr> <td rowspan="3"><form>s (AF (ASuperl SupStrong) Nom)</form></td>
<tr> </tr>
<th rowspan="2">best</th> <tr>
<th>sg</th> <th>neut</th>
<td><form>s (AF (APosit (Weak Sg)) Nom)</form></td> <td><form>s (AF (APosit (Strong (GSg Neutr))) Nom)</form></td>
<td rowspan="2"><form>s (AF (ASuperl SupWeak) Nom)</form></td> </tr>
</tr> <tr>
<tr> <th>pl</th>
<th>pl</th> <td><form>s (AF (APosit (Strong GPl)) Nom)</form></td>
<td><form>s (AF (APosit (Weak Pl)) Nom)</form></td> </tr>
</tr> <tr>
<tr> <th rowspan="2">best</th>
<th colspan="5">genitiv</th> <th>sg</th>
</tr> <td><form>s (AF (APosit (Weak Sg)) Nom)</form></td>
<tr> <td rowspan="2"><form>s (AF (ASuperl SupWeak) Nom)</form></td>
<th rowspan="3">obest</th> </tr>
<th>utr</th> <tr>
<td><form>s (AF (APosit (Strong (GSg Utr))) Gen)</form></td> <th>pl</th>
<td rowspan="5"><form>s (AF ACompar Gen)</form></td> <td><form>s (AF (APosit (Weak Pl)) Nom)</form></td>
<td rowspan="3"><form>s (AF (ASuperl SupStrong) Gen)</form></td> </tr>
</tr> <tr>
<tr> <th colspan="5">genitiv</th>
<th>neut</th> </tr>
<td><form>s (AF (APosit (Strong (GSg Neutr))) Gen)</form></td> <tr>
</tr> <th rowspan="3">obest</th>
<tr> <th>utr</th>
<th>pl</th> <td><form>s (AF (APosit (Strong (GSg Utr))) Gen)</form></td>
<td><form>s (AF (APosit (Strong GPl)) Gen)</form></td> <td rowspan="5"><form>s (AF ACompar Gen)</form></td>
</tr> <td rowspan="3"><form>s (AF (ASuperl SupStrong) Gen)</form></td>
<tr> </tr>
<th rowspan="2">best</th> <tr>
<th>sg</th> <th>neut</th>
<td><form>s (AF (APosit (Weak Sg)) Gen)</form></td> <td><form>s (AF (APosit (Strong (GSg Neutr))) Gen)</form></td>
<td rowspan="2"><form>s (AF (ASuperl SupWeak) Gen)</form></td> </tr>
</tr> <tr>
<tr> <th>pl</th>
<th>pl</th> <td><form>s (AF (APosit (Strong GPl)) Gen)</form></td>
<td><form>s (AF (APosit (Weak Pl)) Gen)</form></td> </tr>
</tr> <tr>
</table> <th rowspan="2">best</th>
</adjective> <th>sg</th>
<adverb> <td><form>s (AF (APosit (Weak Sg)) Gen)</form></td>
<h1>Adverb</h1> <td rowspan="2"><form>s (AF (ASuperl SupWeak) Gen)</form></td>
<p><form>s</form></p> </tr>
</adverb> <tr>
<prep> <th>pl</th>
<h1>Preposition</h1> <td><form>s (AF (APosit (Weak Pl)) Gen)</form></td>
<p><form>s</form></p> </tr>
</prep> </table>
<verb> </template>
<h1>Verb</h1> </inflection>
<table class="forms-table" rules="all"> <inflection>
<tr> <cat>Adv</cat>
<th></th> <tag>adv</tag>
<th>active</th> <template>
<th>passive</th> <h1>Adverb</h1>
</tr> <p><form>s</form></p>
<tr> </template>
<th>infitiv</th> </inflection>
<td><form>s (VI (VInfin Act))</form></td> <inflection>
<td><form>s (VI (VInfin Pass))</form></td> <cat>Prep</cat>
</tr> <tag>prep</tag>
<tr> <template>
<th>presens</th> <h1>Preposition</h1>
<td><form>s (VF (VPres Act))</form></td> <p><form>s</form></p>
<td><form>s (VF (VPres Pass))</form></td> </template>
</tr> </inflection>
<tr> <inflection>
<th>preteritum</th> <cat>V</cat>
<td><form>s (VF (VPret Act))</form></td> <cat>V2</cat>
<td><form>s (VF (VPret Pass))</form></td> <cat>V3</cat>
</tr> <cat>V2V</cat>
<tr> <cat>VV</cat>
<th>supinum</th> <cat>VS</cat>
<td><form>s (VI (VSupin Act))</form></td> <tag>v</tag>
<td><form>s (VI (VSupin Pass))</form></td> <template>
</tr> <h1>Verb</h1>
<tr> <table class="forms-table" rules="all">
<th>imperativ</th> <tr>
<td><form>s (VF (VImper Act))</form></td> <th></th>
<td><form>s (VF (VImper Pass))</form></td> <th>active</th>
</tr> <th>passive</th>
</table> </tr>
<tr>
<h2>Particip Presens</h2> <th>infitiv</th>
<table class="forms-table" rules="all"> <td><form>s (VI (VInfin Act))</form></td>
<tr> <td><form>s (VI (VInfin Pass))</form></td>
<th colspan="2"></th> </tr>
<th>obest</th> <tr>
<th>best</th> <th>presens</th>
</tr> <td><form>s (VF (VPres Act))</form></td>
<tr> <td><form>s (VF (VPres Pass))</form></td>
<th rowspan="2">nom</th> </tr>
<th>sg</th> <tr>
<td><form>s (VI (VPtPres Sg Indef Nom))</form></td> <th>preteritum</th>
<td><form>s (VI (VPtPres Sg Def Nom))</form></td> <td><form>s (VF (VPret Act))</form></td>
<td><form>s (VF (VPret Pass))</form></td>
</tr> </tr>
<tr> <tr>
<th>pl</th> <th>supinum</th>
<td><form>s (VI (VPtPres Pl Indef Nom))</form></td> <td><form>s (VI (VSupin Act))</form></td>
<td><form>s (VI (VPtPres Pl Def Nom))</form></td> <td><form>s (VI (VSupin Pass))</form></td>
</tr> </tr>
<tr> <tr>
<th rowspan="2">gen</th> <th>imperativ</th>
<th>sg</th> <td><form>s (VF (VImper Act))</form></td>
<td><form>s (VI (VPtPres Sg Indef Gen))</form></td> <td><form>s (VF (VImper Pass))</form></td>
<td><form>s (VI (VPtPres Sg Def Gen))</form></td> </tr>
</tr> </table>
<tr>
<th>pl</th> <h2>Particip Presens</h2>
<td><form>s (VI (VPtPres Pl Indef Gen))</form></td> <table class="forms-table" rules="all">
<td><form>s (VI (VPtPres Pl Def Gen))</form></td> <tr>
</tr> <th colspan="2"></th>
</table> <th>obest</th>
<th>best</th>
<h2>Particip Perfekt</h2> </tr>
<table class="forms-table" rules="all"> <tr>
<tr> <th rowspan="2">nom</th>
<th colspan="2"></th> <th>sg</th>
<th>nominativ</th> <td><form>s (VI (VPtPres Sg Indef Nom))</form></td>
<th>genitiv</th> <td><form>s (VI (VPtPres Sg Def Nom))</form></td>
</tr>
<tr> </tr>
<th rowspan="3">obest</th> <tr>
<th>utr</th> <th>pl</th>
<td><form>s (VI (VPtPret (Strong (GSg Utr)) Nom))</form></td> <td><form>s (VI (VPtPres Pl Indef Nom))</form></td>
<td><form>s (VI (VPtPret (Strong (GSg Utr)) Gen))</form></td> <td><form>s (VI (VPtPres Pl Def Nom))</form></td>
</tr> </tr>
<tr> <tr>
<th>neut</th> <th rowspan="2">gen</th>
<td><form>s (VI (VPtPret (Strong (GSg Neutr)) Nom))</form></td> <th>sg</th>
<td><form>s (VI (VPtPret (Strong (GSg Neutr)) Gen))</form></td> <td><form>s (VI (VPtPres Sg Indef Gen))</form></td>
</tr> <td><form>s (VI (VPtPres Sg Def Gen))</form></td>
<tr> </tr>
<th>pl</th> <tr>
<td><form>s (VI (VPtPret (Strong GPl) Nom))</form></td> <th>pl</th>
<td><form>s (VI (VPtPret (Strong GPl) Gen))</form></td> <td><form>s (VI (VPtPres Pl Indef Gen))</form></td>
</tr> <td><form>s (VI (VPtPres Pl Def Gen))</form></td>
<tr> </tr>
<th rowspan="2">best</th> </table>
<th>sg</th>
<td><form>s (VI (VPtPret (Weak Sg) Nom))</form></td> <h2>Particip Perfekt</h2>
<td><form>s (VI (VPtPret (Weak Sg) Gen))</form></td> <table class="forms-table" rules="all">
</tr> <tr>
<tr> <th colspan="2"></th>
<th>pl</th> <th>nominativ</th>
<td><form>s (VI (VPtPret (Weak Pl) Nom))</form></td> <th>genitiv</th>
<td><form>s (VI (VPtPret (Weak Pl) Gen))</form></td> </tr>
</tr> <tr>
</table> <th rowspan="3">obest</th>
</verb> <th>utr</th>
</inflection_temlate> <td><form>s (VI (VPtPret (Strong (GSg Utr)) Nom))</form></td>
<td><form>s (VI (VPtPret (Strong (GSg Utr)) Gen))</form></td>
</tr>
<tr>
<th>neut</th>
<td><form>s (VI (VPtPret (Strong (GSg Neutr)) Nom))</form></td>
<td><form>s (VI (VPtPret (Strong (GSg Neutr)) Gen))</form></td>
</tr>
<tr>
<th>pl</th>
<td><form>s (VI (VPtPret (Strong GPl) Nom))</form></td>
<td><form>s (VI (VPtPret (Strong GPl) Gen))</form></td>
</tr>
<tr>
<th rowspan="2">best</th>
<th>sg</th>
<td><form>s (VI (VPtPret (Weak Sg) Nom))</form></td>
<td><form>s (VI (VPtPret (Weak Sg) Gen))</form></td>
</tr>
<tr>
<th>pl</th>
<td><form>s (VI (VPtPret (Weak Pl) Nom))</form></td>
<td><form>s (VI (VPtPret (Weak Pl) Gen))</form></td>
</tr>
</table>
</template>
</inflection>
</inflection_template>

View File

@@ -1,14 +1,11 @@
package org.grammaticalframework.ui.android; package org.grammaticalframework.ui.android;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import android.app.Activity; import android.app.Activity;
import android.app.ListActivity; import android.app.ListActivity;
import android.content.Context; import android.content.Context;
import android.content.res.XmlResourceParser;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@@ -23,7 +20,6 @@ import android.widget.TextView;
import org.grammaticalframework.pgf.*; import org.grammaticalframework.pgf.*;
import org.grammaticalframework.ui.android.LanguageSelector.OnLanguageSelectedListener; import org.grammaticalframework.ui.android.LanguageSelector.OnLanguageSelectedListener;
import org.xmlpull.v1.XmlPullParserException;
public class LexicalEntryActivity extends ListActivity { public class LexicalEntryActivity extends ListActivity {
@@ -93,27 +89,6 @@ public class LexicalEntryActivity extends ListActivity {
} }
private void expand(View view, String lemma) { private void expand(View view, String lemma) {
String tag = null;
if (lemma.endsWith("_N") || lemma.endsWith("_N2"))
tag = "noun";
else if (lemma.endsWith("_V") || lemma.endsWith("_V2") ||
lemma.endsWith("_V3") || lemma.endsWith("_V2V") ||
lemma.endsWith("_VV") || lemma.endsWith("_VS"))
tag = "verb";
else if (lemma.endsWith("_A") || lemma.endsWith("_A2"))
tag = "adjective";
else if (lemma.endsWith("_Prep"))
tag = "prep";
else if (lemma.endsWith("_Adv"))
tag = "adverb";
if (tag == null)
return;
int res = mTranslator.getTargetLanguage().getInflectionResource();
if (res == 0)
return;
ImageView arrow = (ImageView) view.findViewById(R.id.arrow); ImageView arrow = (ImageView) view.findViewById(R.id.arrow);
arrow.setImageResource(R.drawable.close_arrow); arrow.setImageResource(R.drawable.close_arrow);
@@ -127,69 +102,8 @@ public class LexicalEntryActivity extends ListActivity {
((RelativeLayout) view).addView(inflectionView, params); ((RelativeLayout) view).addView(inflectionView, params);
} }
Expr expr = Expr.readExpr(lemma); String html = mTranslator.getInflectionTable(lemma);
Map<String,String> lins = mTranslator.tabularLinearize(expr); inflectionView.loadData(html, "text/html; charset=UTF-8", null);
XmlResourceParser parser = getResources().getXml(res);
StringBuilder builder = new StringBuilder();
builder.append("<html><head><meta charset=\"UTF-8\"/></head><body>");
try {
boolean emit = false;
boolean form = false;
int event = parser.next();
while (event != XmlResourceParser.END_DOCUMENT) {
switch (event) {
case XmlResourceParser.START_TAG:
if (tag.equals(parser.getName())) {
emit = true;
} if ("form".equals(parser.getName())) {
form = true;
} else if (emit) {
builder.append("<"+parser.getName());
int n_attrs = parser.getAttributeCount();
for (int i = 0; i < n_attrs; i++) {
builder.append(' ');
builder.append(parser.getAttributeName(i));
builder.append("=\"");
builder.append(parser.getAttributeValue(i));
builder.append("\"");
}
builder.append(">");
}
break;
case XmlResourceParser.END_TAG:
if (tag.equals(parser.getName())) {
emit = false;
} else if ("form".equals(parser.getName())) {
form = false;
} else if (emit) {
builder.append("</"+parser.getName()+">");
}
break;
case XmlResourceParser.TEXT:
if (emit) {
if (form) {
String s = lins.get(parser.getText());
if (s != null)
builder.append(s);
} else {
builder.append(parser.getText());
}
}
break;
}
event = parser.next();
}
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
} finally {
parser.close();
}
builder.append("</body>");
inflectionView.loadData(builder.toString(), "text/html; charset=UTF-8", null);
expandedView = view; expandedView = view;
} }
@@ -211,7 +125,7 @@ public class LexicalEntryActivity extends ListActivity {
TextView descView = TextView descView =
(TextView) convertView.findViewById(R.id.lexical_desc); (TextView) convertView.findViewById(R.id.lexical_desc);
String phrase = mTranslator.generateTranslationEntry(lemma); String phrase = mTranslator.generateLexiconEntry(lemma);
descView.setText(phrase); descView.setText(phrase);
convertView.setOnClickListener(new OnClickListener() { convertView.setOnClickListener(new OnClickListener() {

View File

@@ -2,6 +2,7 @@ package org.grammaticalframework.ui.android;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.XmlResourceParser;
import android.util.Log; import android.util.Log;
import org.grammaticalframework.pgf.Concr; import org.grammaticalframework.pgf.Concr;
@@ -9,6 +10,7 @@ import org.grammaticalframework.pgf.Expr;
import org.grammaticalframework.pgf.MorphoAnalysis; import org.grammaticalframework.pgf.MorphoAnalysis;
import org.grammaticalframework.pgf.PGF; import org.grammaticalframework.pgf.PGF;
import org.grammaticalframework.pgf.ParseError; import org.grammaticalframework.pgf.ParseError;
import org.xmlpull.v1.XmlPullParserException;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
@@ -38,6 +40,8 @@ public class Translator {
new Language("sv-SE", "Swedish", "ParseSwe", R.xml.inflection_sv, R.xml.qwerty), new Language("sv-SE", "Swedish", "ParseSwe", R.xml.inflection_sv, R.xml.qwerty),
}; };
private Context mContext;
private Language mSourceLanguage; private Language mSourceLanguage;
private Language mTargetLanguage; private Language mTargetLanguage;
@@ -69,9 +73,11 @@ public class Translator {
} }
public Translator(Context context) { public Translator(Context context) {
mGrammarLoader = new GrammarLoader(context); mContext = context;
mGrammarLoader = new GrammarLoader();
mGrammarLoader.start(); mGrammarLoader.start();
mSharedPref = context.getSharedPreferences( mSharedPref = context.getSharedPreferences(
context.getString(R.string.global_preferences_key), Context.MODE_PRIVATE); context.getString(R.string.global_preferences_key), Context.MODE_PRIVATE);
@@ -131,20 +137,183 @@ public class Translator {
} }
} }
public String generateTranslationEntry(String lemma) { private String getLemmaTag(String lemma) {
String cat = getGrammar().getFunctionType(lemma).getCategory();
int res = getTargetLanguage().getInflectionResource();
if (res == 0)
return "";
XmlResourceParser parser = mContext.getResources().getXml(res);
try {
int state = 0;
int event = parser.next();
String tag = null;
boolean found = false;
while (event != XmlResourceParser.END_DOCUMENT) {
switch (event) {
case XmlResourceParser.START_TAG:
if (state == 0 && "inflection".equals(parser.getName())) {
state = 1;
tag = null;
found = false;
} else if (state == 1 && "cat".equals(parser.getName())) {
state = 2;
} else if (state == 1 && "tag".equals(parser.getName())) {
state = 3;
} else if (state == 1 && "template".equals(parser.getName())) {
state = 4;
}
break;
case XmlResourceParser.END_TAG:
if (state == 1 && "inflection".equals(parser.getName())) {
state = 0;
if (found)
return tag+".";
} else if (state == 2 && "cat".equals(parser.getName())) {
state = 1;
} else if (state == 3 && "tag".equals(parser.getName())) {
state = 1;
} else if (state == 4 && "template".equals(parser.getName())) {
state = 1;
}
break;
case XmlResourceParser.TEXT:
if (state == 2) {
if (cat.equals(parser.getText())) {
found = true;
}
} else if (state == 3) {
tag = parser.getText();
}
break;
}
event = parser.next();
}
} catch (IOException e) {
Log.e(TAG, "getLemmaTag", e);
} catch (XmlPullParserException e) {
Log.e(TAG, "getLemmaTag", e);
} finally {
parser.close();
}
return "";
}
public String generateLexiconEntry(String lemma) {
Expr e = Expr.readExpr(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());
if (targetLang.hasLinearization(lemma)) if (targetLang.hasLinearization(lemma))
return sourceLang.linearize(e) + " - " + targetLang.linearize(e); return sourceLang.linearize(e) + " - " + getLemmaTag(lemma) + " " + targetLang.linearize(e);
else else
return sourceLang.linearize(e); return sourceLang.linearize(e) + " " + getLemmaTag(lemma);
} }
public Map<String,String> tabularLinearize(Expr e) { public String getInflectionTable(String lemma) {
String cat = getGrammar().getFunctionType(lemma).getCategory();
int res = getTargetLanguage().getInflectionResource();
if (res == 0)
return "";
Expr expr = Expr.readExpr(lemma);
Concr targetLang = getConcr(getTargetLanguage().getConcrete()); Concr targetLang = getConcr(getTargetLanguage().getConcrete());
return targetLang.tabularLinearize(e); Map<String,String> lins = targetLang.tabularLinearize(expr);
} XmlResourceParser parser = mContext.getResources().getXml(res);
StringBuilder builder = new StringBuilder();
builder.append("<html><head><meta charset=\"UTF-8\"/></head><body>");
try {
int state = 0;
int event = parser.next();
boolean emit = false;
boolean form = false;
boolean lin = false;
StringBuilder abstrBuilder = null;
while (event != XmlResourceParser.END_DOCUMENT) {
switch (event) {
case XmlResourceParser.START_TAG:
if (state == 0 && "inflection".equals(parser.getName())) {
state = 1;
} else if (state == 1 && "cat".equals(parser.getName())) {
state = 2;
} else if (state == 1 && "template".equals(parser.getName())) {
state = 4;
} else if (state == 4 && "form".equals(parser.getName())) {
form = true;
} else if (state == 4 && emit && "lin".equals(parser.getName())) {
lin = true;
emit = false;
abstrBuilder = new StringBuilder();
} else if (state == 4 && lin && "cat".equals(parser.getName())) {
abstrBuilder.append(cat);
} else if (state == 4 && lin && "lemma".equals(parser.getName())) {
abstrBuilder.append(lemma);
} else if (state == 4 && emit) {
builder.append("<"+parser.getName());
int n_attrs = parser.getAttributeCount();
for (int i = 0; i < n_attrs; i++) {
builder.append(' ');
builder.append(parser.getAttributeName(i));
builder.append("=\"");
builder.append(parser.getAttributeValue(i));
builder.append("\"");
}
builder.append(">");
}
break;
case XmlResourceParser.END_TAG:
if (state == 1 && "inflection".equals(parser.getName())) {
state = 0;
} else if (state == 2 && "cat".equals(parser.getName())) {
state = 1;
} else if (state == 4 && "template".equals(parser.getName())) {
state = 1;
emit = false;
} else if (state == 4 && "form".equals(parser.getName())) {
form = false;
} else if (state == 4 && lin && "lin".equals(parser.getName())) {
Expr expr2 = Expr.readExpr(abstrBuilder.toString());
builder.append(targetLang.linearize(expr2));
emit = true;
} else if (state == 4 && emit) {
builder.append("</"+parser.getName()+">");
}
break;
case XmlResourceParser.TEXT:
if (state == 2) {
if (cat.equals(parser.getText()))
emit = true;
} else if (state == 4 && emit) {
if (form) {
String s = lins.get(parser.getText());
if (s != null)
builder.append(s);
} else {
builder.append(parser.getText());
}
} else if (state == 4 && lin) {
abstrBuilder.append(parser.getText());
}
break;
}
event = parser.next();
}
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
} finally {
parser.close();
}
builder.append("</body>");
return builder.toString();
}
public List<MorphoAnalysis> lookupMorpho(String sentence) { public List<MorphoAnalysis> lookupMorpho(String sentence) {
return getConcr(getSourceLanguage().getConcrete()).lookupMorpho(sentence); return getConcr(getSourceLanguage().getConcrete()).lookupMorpho(sentence);
@@ -164,12 +333,6 @@ public class Translator {
} }
private class GrammarLoader extends Thread { private class GrammarLoader extends Thread {
private final Context mContext;
public GrammarLoader(Context context) {
mContext = context;
}
public void run() { public void run() {
InputStream in = null; InputStream in = null;