better dictionary visualization in the Android App

This commit is contained in:
kr.angelov
2013-11-27 22:16:05 +00:00
parent 848573afdc
commit 9de4812482
13 changed files with 1337 additions and 1078 deletions

View File

@@ -154,4 +154,14 @@ lin
UttAdV adv = adv;
lincat
Feat = Str;
lin FeatN2, FeatN = \n ->
case n.g of {
AMasc Human => "(м.р.л.)" ;
AMasc NonHuman => "(м.р.)" ;
AFem => "(ж.р.)" ;
ANeut => "(ср.р.)"
} ;
}

View File

@@ -149,5 +149,9 @@ lin
PPos = {s = [] ; p = CPos} ;
PNeg = {s = [] ; p = CNeg True} ; -- contracted: don't
UncNeg = {s = [] ; p = CNeg False} ;
lincat
Feat = Str;
lin FeatN, FeatN2 = \_ -> "";
}

View File

@@ -72,4 +72,9 @@ fun CompoundCN : Num -> N -> CN -> CN ;
AdAdV : AdA -> AdV -> AdV ;
UttAdV : AdV -> Utt;
cat Feat;
fun FeatN : N -> Feat;
FeatN2 : N2 -> Feat;
}

View File

@@ -123,5 +123,13 @@ lin
lin
UncNeg = {s = [] ; p = Neg} ;
lincat
Feat = Str;
lin FeatN2, FeatN = \n ->
case n.g of {
Utr => "(utr)" ;
Neutr => "(neutr)"
} ;
}

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)));
}
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 {
GuMapItor fn;
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)));
}
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
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;
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>
<noun>
<h1>Noun</h1>
<table class="forms-table" rules="all">
<tr>
<th>s</th>
<td><form>s</form></td>
</tr>
<tr>
<th>c</th>
<td><form>c</form></td>
</tr>
</table>
</noun>
<adjective>
<h1>Adjective</h1>
<table class="forms-table" rules="all">
<tr>
<th>s</th>
<td><form>s</form></td>
</tr>
</table>
</adjective>
<adverb>
<h1>Adverb</h1>
<p><form>s</form></p>
</adverb>
<prep>
<h1>Preposition</h1>
<p><form>prepPre</form> - <form>prepPost</form></p>
</prep>
<verb>
<h1>Verb</h1>
<table class="forms-table" rules="all">
<tr>
<th>s</th>
<td><form>s</form></td>
</tr>
<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>
</verb>
</inflection_temlate>
<inflection_template>
<inflection>
<cat>N</cat>
<cat>N2</cat>
<tag>n</tag>
<template>
<h1>Noun</h1>
<table class="forms-table" rules="all">
<tr>
<th>s</th>
<td><form>s</form></td>
</tr>
<tr>
<th>c</th>
<td><form>c</form></td>
</tr>
</table>
</template>
</inflection>
<inflection>
<cat>A</cat>
<cat>A2</cat>
<tag>a</tag>
<template>
<h1>Adjective</h1>
<table class="forms-table" rules="all">
<tr>
<th>s</th>
<td><form>s</form></td>
</tr>
</table>
</template>
</inflection>
<inflection>
<cat>Adv</cat>
<tag>adv</tag>
<template>
<h1>Adverb</h1>
<p><form>s</form></p>
</template>
</inflection>
<inflection>
<cat>Prep</cat>
<tag>prep</tag>
<template>
<h1>Preposition</h1>
<p><form>prepPre</form> - <form>prepPost</form></p>
</template>
</inflection>
<inflection>
<cat>V</cat>
<cat>V2</cat>
<cat>V3</cat>
<cat>V2V</cat>
<cat>VV</cat>
<cat>VS</cat>
<tag>v</tag>
<template>
<h1>Verb</h1>
<table class="forms-table" rules="all">
<tr>
<th>s</th>
<td><form>s</form></td>
</tr>
<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>
<noun>
<h1>Noun</h1>
<inflection_template>
<inflection>
<cat>N</cat>
<cat>N2</cat>
<tag>n</tag>
<template>
<h1>Noun</h1>
<table class="forms-table" rules="all">
<tr>
<th></th>
<th>nom</th>
<th>gen</th>
</tr>
<tr>
<th>sg</th>
<td><form>s Sg Nom</form></td>
<td><form>s Sg Gen</form></td>
</tr>
<tr>
<th>pl</th>
<td><form>s Pl Nom</form></td>
<td><form>s Pl Gen</form></td>
</tr>
</table>
</noun>
<adjective>
<h1>Adjective</h1>
<table class="forms-table" rules="all">
<tr>
<th></th>
<th>nom</th>
<th>gen</th>
</tr>
<tr>
<th>posit</th>
<td><form>s (AAdj Posit Nom)</form></td>
<td><form>s (AAdj Posit Gen)</form></td>
</tr>
<tr>
<th>compar</th>
<td><form>s (AAdj Compar Nom)</form></td>
<td><form>s (AAdj Compar Gen)</form></td>
</tr>
<tr>
<th>superl</th>
<td><form>s (AAdj Superl Nom)</form></td>
<td><form>s (AAdj Superl Gen)</form></td>
</tr>
</table>
<h1>Adverb</h1>
<p><form>s AAdv</form></p>
</adjective>
<adverb>
<h1>Adverb</h1>
<p><form>s</form></p>
</adverb>
<prep>
<h1>Preposition</h1>
<p><form>s</form></p>
</prep>
<verb>
<h1>Verb</h1>
<table class="forms-table" rules="all">
<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>
</verb>
</inflection_temlate>
<table class="forms-table" rules="all">
<tr>
<th></th>
<th>nom</th>
<th>gen</th>
</tr>
<tr>
<th>sg</th>
<td><form>s Sg Nom</form></td>
<td><form>s Sg Gen</form></td>
</tr>
<tr>
<th>pl</th>
<td><form>s Pl Nom</form></td>
<td><form>s Pl Gen</form></td>
</tr>
</table>
</template>
</inflection>
<inflection>
<cat>A</cat>
<cat>A2</cat>
<tag>a</tag>
<template>
<h1>Adjective</h1>
<table class="forms-table" rules="all">
<tr>
<th></th>
<th>nom</th>
<th>gen</th>
</tr>
<tr>
<th>posit</th>
<td><form>s (AAdj Posit Nom)</form></td>
<td><form>s (AAdj Posit Gen)</form></td>
</tr>
<tr>
<th>compar</th>
<td><form>s (AAdj Compar Nom)</form></td>
<td><form>s (AAdj Compar Gen)</form></td>
</tr>
<tr>
<th>superl</th>
<td><form>s (AAdj Superl Nom)</form></td>
<td><form>s (AAdj Superl Gen)</form></td>
</tr>
</table>
<h1>Adverb</h1>
<p><form>s AAdv</form></p>
</template>
</inflection>
<inflection>
<cat>Adv</cat>
<tag>adv</tag>
<template>
<h1>Adverb</h1>
<p><form>s</form></p>
</template>
</inflection>
<inflection>
<cat>Prep</cat>
<tag>prep</tag>
<template>
<h1>Preposition</h1>
<p><form>s</form></p>
</template>
</inflection>
<inflection>
<cat>V</cat>
<cat>V2</cat>
<cat>V3</cat>
<cat>V2V</cat>
<cat>VV</cat>
<cat>VS</cat>
<tag>v</tag>
<template>
<h1>Verb</h1>
<table class="forms-table" rules="all">
<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>
<noun>
<h1>Substantiv</h1>
<table class="forms-table" rules="all">
<tr>
<th colspan="2"></th>
<th>obest</th>
<th>best</th>
</tr>
<tr>
<th rowspan="2">nom</th>
<th>sg</th>
<td><form>s Sg Indef Nom</form></td>
<td><form>s Sg Def Nom</form></td>
</tr>
<tr>
<th>pl</th>
<td><form>s Pl Indef Nom</form></td>
<td><form>s Pl Def Nom</form></td>
</tr>
<tr>
<th rowspan="2">gen</th>
<th>sg</th>
<td><form>s Sg Indef Gen</form></td>
<td><form>s Sg Def Gen</form></td>
</tr>
<tr>
<th>pl</th>
<td><form>s Pl Indef Gen</form></td>
<td><form>s Pl Def Gen</form></td>
</tr>
</table>
</noun>
<adjective>
<h1>Adjektiv</h1>
<table class="forms-table" rules="all">
<tr>
<th colspan="5">nominativ</th>
</tr>
<tr>
<th colspan="2"></th>
<th>posit</th>
<th>kompar</th>
<th>superl</th>
</tr>
<tr>
<th rowspan="3">obest</th>
<th>utr</th>
<td><form>s (AF (APosit (Strong (GSg Utr))) Nom)</form></td>
<td rowspan="5"><form>s (AF ACompar Nom)</form></td>
<td rowspan="3"><form>s (AF (ASuperl SupStrong) Nom)</form></td>
</tr>
<tr>
<th>neut</th>
<td><form>s (AF (APosit (Strong (GSg Neutr))) Nom)</form></td>
</tr>
<tr>
<th>pl</th>
<td><form>s (AF (APosit (Strong GPl)) Nom)</form></td>
</tr>
<tr>
<th rowspan="2">best</th>
<th>sg</th>
<td><form>s (AF (APosit (Weak Sg)) Nom)</form></td>
<td rowspan="2"><form>s (AF (ASuperl SupWeak) Nom)</form></td>
</tr>
<tr>
<th>pl</th>
<td><form>s (AF (APosit (Weak Pl)) Nom)</form></td>
</tr>
<tr>
<th colspan="5">genitiv</th>
</tr>
<tr>
<th rowspan="3">obest</th>
<th>utr</th>
<td><form>s (AF (APosit (Strong (GSg Utr))) Gen)</form></td>
<td rowspan="5"><form>s (AF ACompar Gen)</form></td>
<td rowspan="3"><form>s (AF (ASuperl SupStrong) Gen)</form></td>
</tr>
<tr>
<th>neut</th>
<td><form>s (AF (APosit (Strong (GSg Neutr))) Gen)</form></td>
</tr>
<tr>
<th>pl</th>
<td><form>s (AF (APosit (Strong GPl)) Gen)</form></td>
</tr>
<tr>
<th rowspan="2">best</th>
<th>sg</th>
<td><form>s (AF (APosit (Weak Sg)) Gen)</form></td>
<td rowspan="2"><form>s (AF (ASuperl SupWeak) Gen)</form></td>
</tr>
<tr>
<th>pl</th>
<td><form>s (AF (APosit (Weak Pl)) Gen)</form></td>
</tr>
</table>
</adjective>
<adverb>
<h1>Adverb</h1>
<p><form>s</form></p>
</adverb>
<prep>
<h1>Preposition</h1>
<p><form>s</form></p>
</prep>
<verb>
<h1>Verb</h1>
<table class="forms-table" rules="all">
<tr>
<th></th>
<th>active</th>
<th>passive</th>
</tr>
<tr>
<th>infitiv</th>
<td><form>s (VI (VInfin Act))</form></td>
<td><form>s (VI (VInfin Pass))</form></td>
</tr>
<tr>
<th>presens</th>
<td><form>s (VF (VPres Act))</form></td>
<td><form>s (VF (VPres Pass))</form></td>
</tr>
<tr>
<th>preteritum</th>
<td><form>s (VF (VPret Act))</form></td>
<td><form>s (VF (VPret Pass))</form></td>
</tr>
<tr>
<th>supinum</th>
<td><form>s (VI (VSupin Act))</form></td>
<td><form>s (VI (VSupin Pass))</form></td>
</tr>
<tr>
<th>imperativ</th>
<td><form>s (VF (VImper Act))</form></td>
<td><form>s (VF (VImper Pass))</form></td>
</tr>
</table>
<h2>Particip Presens</h2>
<table class="forms-table" rules="all">
<tr>
<th colspan="2"></th>
<th>obest</th>
<th>best</th>
</tr>
<tr>
<th rowspan="2">nom</th>
<th>sg</th>
<td><form>s (VI (VPtPres Sg Indef Nom))</form></td>
<td><form>s (VI (VPtPres Sg Def Nom))</form></td>
</tr>
<tr>
<th>pl</th>
<td><form>s (VI (VPtPres Pl Indef Nom))</form></td>
<td><form>s (VI (VPtPres Pl Def Nom))</form></td>
</tr>
<tr>
<th rowspan="2">gen</th>
<th>sg</th>
<td><form>s (VI (VPtPres Sg Indef Gen))</form></td>
<td><form>s (VI (VPtPres Sg Def Gen))</form></td>
</tr>
<tr>
<th>pl</th>
<td><form>s (VI (VPtPres Pl Indef Gen))</form></td>
<td><form>s (VI (VPtPres Pl Def Gen))</form></td>
</tr>
</table>
<h2>Particip Perfekt</h2>
<table class="forms-table" rules="all">
<tr>
<th colspan="2"></th>
<th>nominativ</th>
<th>genitiv</th>
</tr>
<tr>
<th rowspan="3">obest</th>
<th>utr</th>
<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>
</verb>
</inflection_temlate>
<inflection_template>
<inflection>
<cat>N</cat>
<cat>N2</cat>
<tag>s</tag>
<template>
<h1>Substantiv <lin>Feat<cat/>(<lemma/>)</lin></h1>
<table class="forms-table" rules="all">
<tr>
<th colspan="2"></th>
<th>obest</th>
<th>best</th>
</tr>
<tr>
<th rowspan="2">nom</th>
<th>sg</th>
<td><form>s Sg Indef Nom</form></td>
<td><form>s Sg Def Nom</form></td>
</tr>
<tr>
<th>pl</th>
<td><form>s Pl Indef Nom</form></td>
<td><form>s Pl Def Nom</form></td>
</tr>
<tr>
<th rowspan="2">gen</th>
<th>sg</th>
<td><form>s Sg Indef Gen</form></td>
<td><form>s Sg Def Gen</form></td>
</tr>
<tr>
<th>pl</th>
<td><form>s Pl Indef Gen</form></td>
<td><form>s Pl Def Gen</form></td>
</tr>
</table>
</template>
</inflection>
<inflection>
<cat>A</cat>
<cat>A2</cat>
<tag>a</tag>
<template>
<h1>Adjektiv</h1>
<table class="forms-table" rules="all">
<tr>
<th colspan="5">nominativ</th>
</tr>
<tr>
<th colspan="2"></th>
<th>posit</th>
<th>kompar</th>
<th>superl</th>
</tr>
<tr>
<th rowspan="3">obest</th>
<th>utr</th>
<td><form>s (AF (APosit (Strong (GSg Utr))) Nom)</form></td>
<td rowspan="5"><form>s (AF ACompar Nom)</form></td>
<td rowspan="3"><form>s (AF (ASuperl SupStrong) Nom)</form></td>
</tr>
<tr>
<th>neut</th>
<td><form>s (AF (APosit (Strong (GSg Neutr))) Nom)</form></td>
</tr>
<tr>
<th>pl</th>
<td><form>s (AF (APosit (Strong GPl)) Nom)</form></td>
</tr>
<tr>
<th rowspan="2">best</th>
<th>sg</th>
<td><form>s (AF (APosit (Weak Sg)) Nom)</form></td>
<td rowspan="2"><form>s (AF (ASuperl SupWeak) Nom)</form></td>
</tr>
<tr>
<th>pl</th>
<td><form>s (AF (APosit (Weak Pl)) Nom)</form></td>
</tr>
<tr>
<th colspan="5">genitiv</th>
</tr>
<tr>
<th rowspan="3">obest</th>
<th>utr</th>
<td><form>s (AF (APosit (Strong (GSg Utr))) Gen)</form></td>
<td rowspan="5"><form>s (AF ACompar Gen)</form></td>
<td rowspan="3"><form>s (AF (ASuperl SupStrong) Gen)</form></td>
</tr>
<tr>
<th>neut</th>
<td><form>s (AF (APosit (Strong (GSg Neutr))) Gen)</form></td>
</tr>
<tr>
<th>pl</th>
<td><form>s (AF (APosit (Strong GPl)) Gen)</form></td>
</tr>
<tr>
<th rowspan="2">best</th>
<th>sg</th>
<td><form>s (AF (APosit (Weak Sg)) Gen)</form></td>
<td rowspan="2"><form>s (AF (ASuperl SupWeak) Gen)</form></td>
</tr>
<tr>
<th>pl</th>
<td><form>s (AF (APosit (Weak Pl)) Gen)</form></td>
</tr>
</table>
</template>
</inflection>
<inflection>
<cat>Adv</cat>
<tag>adv</tag>
<template>
<h1>Adverb</h1>
<p><form>s</form></p>
</template>
</inflection>
<inflection>
<cat>Prep</cat>
<tag>prep</tag>
<template>
<h1>Preposition</h1>
<p><form>s</form></p>
</template>
</inflection>
<inflection>
<cat>V</cat>
<cat>V2</cat>
<cat>V3</cat>
<cat>V2V</cat>
<cat>VV</cat>
<cat>VS</cat>
<tag>v</tag>
<template>
<h1>Verb</h1>
<table class="forms-table" rules="all">
<tr>
<th></th>
<th>active</th>
<th>passive</th>
</tr>
<tr>
<th>infitiv</th>
<td><form>s (VI (VInfin Act))</form></td>
<td><form>s (VI (VInfin Pass))</form></td>
</tr>
<tr>
<th>presens</th>
<td><form>s (VF (VPres Act))</form></td>
<td><form>s (VF (VPres Pass))</form></td>
</tr>
<tr>
<th>preteritum</th>
<td><form>s (VF (VPret Act))</form></td>
<td><form>s (VF (VPret Pass))</form></td>
</tr>
<tr>
<th>supinum</th>
<td><form>s (VI (VSupin Act))</form></td>
<td><form>s (VI (VSupin Pass))</form></td>
</tr>
<tr>
<th>imperativ</th>
<td><form>s (VF (VImper Act))</form></td>
<td><form>s (VF (VImper Pass))</form></td>
</tr>
</table>
<h2>Particip Presens</h2>
<table class="forms-table" rules="all">
<tr>
<th colspan="2"></th>
<th>obest</th>
<th>best</th>
</tr>
<tr>
<th rowspan="2">nom</th>
<th>sg</th>
<td><form>s (VI (VPtPres Sg Indef Nom))</form></td>
<td><form>s (VI (VPtPres Sg Def Nom))</form></td>
</tr>
<tr>
<th>pl</th>
<td><form>s (VI (VPtPres Pl Indef Nom))</form></td>
<td><form>s (VI (VPtPres Pl Def Nom))</form></td>
</tr>
<tr>
<th rowspan="2">gen</th>
<th>sg</th>
<td><form>s (VI (VPtPres Sg Indef Gen))</form></td>
<td><form>s (VI (VPtPres Sg Def Gen))</form></td>
</tr>
<tr>
<th>pl</th>
<td><form>s (VI (VPtPres Pl Indef Gen))</form></td>
<td><form>s (VI (VPtPres Pl Def Gen))</form></td>
</tr>
</table>
<h2>Particip Perfekt</h2>
<table class="forms-table" rules="all">
<tr>
<th colspan="2"></th>
<th>nominativ</th>
<th>genitiv</th>
</tr>
<tr>
<th rowspan="3">obest</th>
<th>utr</th>
<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;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.res.XmlResourceParser;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@@ -23,7 +20,6 @@ import android.widget.TextView;
import org.grammaticalframework.pgf.*;
import org.grammaticalframework.ui.android.LanguageSelector.OnLanguageSelectedListener;
import org.xmlpull.v1.XmlPullParserException;
public class LexicalEntryActivity extends ListActivity {
@@ -93,27 +89,6 @@ public class LexicalEntryActivity extends ListActivity {
}
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);
arrow.setImageResource(R.drawable.close_arrow);
@@ -127,69 +102,8 @@ public class LexicalEntryActivity extends ListActivity {
((RelativeLayout) view).addView(inflectionView, params);
}
Expr expr = Expr.readExpr(lemma);
Map<String,String> lins = mTranslator.tabularLinearize(expr);
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);
String html = mTranslator.getInflectionTable(lemma);
inflectionView.loadData(html, "text/html; charset=UTF-8", null);
expandedView = view;
}
@@ -211,7 +125,7 @@ public class LexicalEntryActivity extends ListActivity {
TextView descView =
(TextView) convertView.findViewById(R.id.lexical_desc);
String phrase = mTranslator.generateTranslationEntry(lemma);
String phrase = mTranslator.generateLexiconEntry(lemma);
descView.setText(phrase);
convertView.setOnClickListener(new OnClickListener() {

View File

@@ -2,6 +2,7 @@ package org.grammaticalframework.ui.android;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.XmlResourceParser;
import android.util.Log;
import org.grammaticalframework.pgf.Concr;
@@ -9,6 +10,7 @@ import org.grammaticalframework.pgf.Expr;
import org.grammaticalframework.pgf.MorphoAnalysis;
import org.grammaticalframework.pgf.PGF;
import org.grammaticalframework.pgf.ParseError;
import org.xmlpull.v1.XmlPullParserException;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -38,6 +40,8 @@ public class Translator {
new Language("sv-SE", "Swedish", "ParseSwe", R.xml.inflection_sv, R.xml.qwerty),
};
private Context mContext;
private Language mSourceLanguage;
private Language mTargetLanguage;
@@ -69,9 +73,11 @@ public class Translator {
}
public Translator(Context context) {
mGrammarLoader = new GrammarLoader(context);
mContext = context;
mGrammarLoader = new GrammarLoader();
mGrammarLoader.start();
mSharedPref = context.getSharedPreferences(
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);
Concr sourceLang = getConcr(getSourceLanguage().getConcrete());
Concr targetLang = getConcr(getTargetLanguage().getConcrete());
if (targetLang.hasLinearization(lemma))
return sourceLang.linearize(e) + " - " + targetLang.linearize(e);
return sourceLang.linearize(e) + " - " + getLemmaTag(lemma) + " " + targetLang.linearize(e);
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());
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) {
return getConcr(getSourceLanguage().getConcrete()).lookupMorpho(sentence);
@@ -164,12 +333,6 @@ public class Translator {
}
private class GrammarLoader extends Thread {
private final Context mContext;
public GrammarLoader(Context context) {
mContext = context;
}
public void run() {
InputStream in = null;