the first version of the Android's morphology browser

This commit is contained in:
kr.angelov
2013-10-23 15:10:13 +00:00
parent 0882396875
commit 10fa2baa56
6 changed files with 901 additions and 34 deletions

View File

@@ -3,7 +3,7 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/icon"
android:id="@+id/arrow"
android:layout_width="30dp"
android:layout_height="30dp"
android:contentDescription="@string/open_image"
@@ -14,8 +14,14 @@
<TextView
android:id="@+id/lexical_desc"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_toRightOf="@+id/icon"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/arrow"
android:paddingLeft="10dp"
android:textSize="25sp"/>
<WebView
android:id="@+id/lexical_inflection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/lexical_desc"/>
</RelativeLayout>

View File

@@ -0,0 +1,615 @@
<inflection_temlate>
<noun>
<h1>Съществително</h1>
<table class="forms-table" rules="all">
<tr>
<th rowspan="3">ед.ч.</th>
<th>нечленувано</th>
<td><form>s (NF Sg Indef)</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s (NF Sg Def)</form></td>
</tr>
<tr>
<th>пълен член</th>
<td><form>s NFSgDefNom</form></td>
</tr>
<tr>
<th rowspan="2">мн.ч.</th>
<th>нечленувано</th>
<td><form>s (NF Pl Indef)</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s (NF Pl Def)</form></td>
</tr>
<tr>
<th colspan="2">звателна форма</th>
<td><form>s NFVocative</form></td>
</tr>
<tr>
<th colspan="2">бройна форма</th>
<td><form>s NFPlCount</form></td>
</tr>
</table>
<h1>Прилагателно</h1>
<table class="forms-table" rules="all">
<tr>
<th rowspan="7">ед.ч.</th>
<th rowspan="3">м.р.</th>
<th>нечленувано</th>
<td><form>rel (ASg Masc Indef)</form></td>
</tr>
<tr>
<th>непълен член</th>
<td><form>rel (ASg Masc Def)</form></td>
</tr>
<tr>
<th>пълен член</th>
<td><form>rel ASgMascDefNom</form></td>
</tr>
<tr>
<th rowspan="2">ж.р.</th>
<th>нечленувано</th>
<td><form>rel (ASg Fem Indef)</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>rel (ASg Fem Def)</form></td>
</tr>
<tr>
<th rowspan="2">ср.р.</th>
<th>нечленувано</th>
<td><form>rel (ASg Neut Indef)</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>rel (ASg Neut Def)</form></td>
</tr>
<tr>
<th rowspan="2" colspan="2">мн.ч.</th>
<th>нечленувано</th>
<td><form>rel (APl Indef)</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>rel (APl Def)</form></td>
</tr>
</table>
</noun>
<adjective>
<h1>Прилагателно</h1>
<table class="forms-table" rules="all">
<tr>
<th rowspan="7">ед.ч.</th>
<th rowspan="3">м.р.</th>
<th>нечленувано</th>
<td><form>s (ASg Masc Indef)</form></td>
</tr>
<tr>
<th>непълен член</th>
<td><form>s (ASg Masc Def)</form></td>
</tr>
<tr>
<th>пълен член</th>
<td><form>s ASgMascDefNom</form></td>
</tr>
<tr>
<th rowspan="2">ж.р.</th>
<th>нечленувано</th>
<td><form>s (ASg Fem Indef)</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s (ASg Fem Def)</form></td>
</tr>
<tr>
<th rowspan="2">ср.р.</th>
<th>нечленувано</th>
<td><form>s (ASg Neut Indef)</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s (ASg Neut Def)</form></td>
</tr>
<tr>
<th rowspan="2" colspan="2">мн.ч.</th>
<th>нечленувано</th>
<td><form>s (APl Indef)</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s (APl Def)</form></td>
</tr>
</table>
<h1>Наречие</h1>
<p><form>adv</form></p>
</adjective>
<adverb>
<h1>Наречие</h1>
<p><form>s</form></p>
</adverb>
<prep>
<h1>Предлог</h1>
<p><form>s</form></p>
</prep>
<verb>
<h1>Глагол от несвършен вид</h1>
<h2>Изявително наклонение</h2>
<h3>Сегашно време</h3>
<table class="forms-table" rules="all">
<tr>
<th></th>
<th>ед.ч.</th>
<th>мн.ч.</th>
</tr>
<tr>
<th>1 л.</th>
<td><form>s Imperf (VPres Sg P1)</form></td>
<td><form>s Imperf (VPres Pl P1)</form></td>
</tr>
<tr>
<th>2 л.</th>
<td><form>s Imperf (VPres Sg P2)</form></td>
<td><form>s Imperf (VPres Pl P2)</form></td>
</tr>
<tr>
<th>3 л.</th>
<td><form>s Imperf (VPres Sg P3)</form></td>
<td><form>s Imperf (VPres Pl P3)</form></td>
</tr>
</table>
<h3>Минало свършено време (аорист)</h3>
<table class="forms-table" rules="all">
<tr>
<th></th>
<th>ед.ч.</th>
<th>мн.ч.</th>
</tr>
<tr>
<th>1 л.</th>
<td><form>s Imperf (VAorist Sg P1)</form></td>
<td><form>s Imperf (VAorist Pl P1)</form></td>
</tr>
<tr>
<th>2 л.</th>
<td><form>s Imperf (VAorist Sg P2)</form></td>
<td><form>s Imperf (VAorist Pl P2)</form></td>
</tr>
<tr>
<th>3 л.</th>
<td><form>s Imperf (VAorist Sg P3)</form></td>
<td><form>s Imperf (VAorist Pl P3)</form></td>
</tr>
</table>
<h3>Минало несвършено време (имперфект)</h3>
<table class="forms-table" rules="all">
<tr>
<th></th>
<th>ед.ч.</th>
<th>мн.ч.</th>
</tr>
<tr>
<th>1 л.</th>
<td><form>s Imperf (VImperfect Sg P1)</form></td>
<td><form>s Imperf (VImperfect Pl P1)</form></td>
</tr>
<tr>
<th>2 л.</th>
<td><form>s Imperf (VImperfect Sg P2)</form></td>
<td><form>s Imperf (VImperfect Pl P2)</form></td>
</tr>
<tr>
<th>3 л.</th>
<td><form>s Imperf (VImperfect Sg P3)</form></td>
<td><form>s Imperf (VImperfect Pl P3)</form></td>
</tr>
</table>
<h2>Повелително наклонение</h2>
<table class="forms-table" rules="all">
<tr>
<th>ед.ч.</th>
<th>мн.ч.</th>
</tr>
<tr>
<td><form>s Imperf (VImperative Sg)</form></td>
<td><form>s Imperf (VImperative Pl)</form></td>
</tr>
</table>
<h2>Причастия (отглаголни прилагателни)</h2>
<h3>Минало страдателно причастие</h3>
<table class="forms-table" rules="all">
<tr>
<th rowspan="7">ед.ч.</th>
<th rowspan="3">м.р.</th>
<th>нечленувано</th>
<td><form>s Imperf (VPassive (ASg Masc Indef))</form></td>
</tr>
<tr>
<th>непълен член</th>
<td><form>s Imperf (VPassive (ASg Masc Def))</form></td>
</tr>
<tr>
<th>пълен член</th>
<td><form>s Imperf (VPassive ASgMascDefNom)</form></td>
</tr>
<tr>
<th rowspan="2">ж.р.</th>
<th>нечленувано</th>
<td><form>s Imperf (VPassive (ASg Fem Indef))</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s Imperf (VPassive (ASg Fem Def))</form></td>
</tr>
<tr>
<th rowspan="2">ср.р.</th>
<th>нечленувано</th>
<td><form>s Imperf (VPassive (ASg Neut Indef))</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s Imperf (VPassive (ASg Neut Def))</form></td>
</tr>
<tr>
<th rowspan="2" colspan="2">мн.ч.</th>
<th>нечленувано</th>
<td><form>s Imperf (VPassive (APl Indef))</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s Imperf (VPassive (APl Def))</form></td>
</tr>
</table>
<h3>Минало свършено деятелно причастие</h3>
<table class="forms-table" rules="all">
<tr>
<th rowspan="7">ед.ч.</th>
<th rowspan="3">м.р.</th>
<th>нечленувано</th>
<td><form>s Imperf (VPerfect (ASg Masc Indef))</form></td>
</tr>
<tr>
<th>непълен член</th>
<td><form>s Imperf (VPerfect (ASg Masc Def))</form></td>
</tr>
<tr>
<th>пълен член</th>
<td><form>s Imperf (VPerfect ASgMascDefNom)</form></td>
</tr>
<tr>
<th rowspan="2">ж.р.</th>
<th>нечленувано</th>
<td><form>s Imperf (VPerfect (ASg Fem Indef))</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s Imperf (VPerfect (ASg Fem Def))</form></td>
</tr>
<tr>
<th rowspan="2">ср.р.</th>
<th>нечленувано</th>
<td><form>s Imperf (VPerfect (ASg Neut Indef))</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s Imperf (VPerfect (ASg Neut Def))</form></td>
</tr>
<tr>
<th rowspan="2" colspan="2">мн.ч.</th>
<th>нечленувано</th>
<td><form>s Imperf (VPerfect (APl Indef))</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s Imperf (VPerfect (APl Def))</form></td>
</tr>
</table>
<h3>Минало несвършено деятелно причастие</h3>
<table class="forms-table" rules="all">
<tr>
<th rowspan="7">ед.ч.</th>
<th rowspan="3">м.р.</th>
<th>нечленувано</th>
<td><form>s Imperf (VPluPerfect (ASg Masc Indef))</form></td>
</tr>
<tr>
<th>непълен член</th>
<td><form>s Imperf (VPluPerfect (ASg Masc Def))</form></td>
</tr>
<tr>
<th>пълен член</th>
<td><form>s Imperf (VPluPerfect ASgMascDefNom)</form></td>
</tr>
<tr>
<th rowspan="2">ж.р.</th>
<th>нечленувано</th>
<td><form>s Imperf (VPluPerfect (ASg Fem Indef))</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s Imperf (VPluPerfect (ASg Fem Def))</form></td>
</tr>
<tr>
<th rowspan="2">ср.р.</th>
<th>нечленувано</th>
<td><form>s Imperf (VPluPerfect (ASg Neut Indef))</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s Imperf (VPluPerfect (ASg Neut Def))</form></td>
</tr>
<tr>
<th rowspan="2" colspan="2">мн.ч.</th>
<th>нечленувано</th>
<td><form>s Imperf (VPluPerfect (APl Indef))</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s Imperf (VPluPerfect (APl Def))</form></td>
</tr>
</table>
<h3>Сегашно деятелно причастие</h3>
<table class="forms-table" rules="all">
<tr>
<th rowspan="7">ед.ч.</th>
<th rowspan="3">м.р.</th>
<th>нечленувано</th>
<td><form>s Imperf (VPresPart (ASg Masc Indef))</form></td>
</tr>
<tr>
<th>непълен член</th>
<td><form>s Imperf (VPresPart (ASg Masc Def))</form></td>
</tr>
<tr>
<th>пълен член</th>
<td><form>s Imperf (VPresPart ASgMascDefNom)</form></td>
</tr>
<tr>
<th rowspan="2">ж.р.</th>
<th>нечленувано</th>
<td><form>s Imperf (VPresPart (ASg Fem Indef))</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s Imperf (VPresPart (ASg Fem Def))</form></td>
</tr>
<tr>
<th rowspan="2">ср.р.</th>
<th>нечленувано</th>
<td><form>s Imperf (VPresPart (ASg Neut Indef))</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s Imperf (VPresPart (ASg Neut Def))</form></td>
</tr>
<tr>
<th rowspan="2" colspan="2">мн.ч.</th>
<th>нечленувано</th>
<td><form>s Imperf (VPresPart (APl Indef))</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s Imperf (VPresPart (APl Def))</form></td>
</tr>
</table>
<h2>Деепричастие (отглаголно наречие)</h2>
<p><form>s Imperf VGerund</form></p>
<h1>Глагол от свършен вид</h1>
<h2>Изявително наклонение</h2>
<h3>Сегашно време</h3>
<table class="forms-table" rules="all">
<tr>
<th></th>
<th>ед.ч.</th>
<th>мн.ч.</th>
</tr>
<tr>
<th>1 л.</th>
<td><form>s Perf (VPres Sg P1)</form></td>
<td><form>s Perf (VPres Pl P1)</form></td>
</tr>
<tr>
<th>2 л.</th>
<td><form>s Perf (VPres Sg P2)</form></td>
<td><form>s Perf (VPres Pl P2)</form></td>
</tr>
<tr>
<th>3 л.</th>
<td><form>s Perf (VPres Sg P3)</form></td>
<td><form>s Perf (VPres Pl P3)</form></td>
</tr>
</table>
<h3>Минало свършено време (аорист)</h3>
<table class="forms-table" rules="all">
<tr>
<th></th>
<th>ед.ч.</th>
<th>мн.ч.</th>
</tr>
<tr>
<th>1 л.</th>
<td><form>s Perf (VAorist Sg P1)</form></td>
<td><form>s Perf (VAorist Pl P1)</form></td>
</tr>
<tr>
<th>2 л.</th>
<td><form>s Perf (VAorist Sg P2)</form></td>
<td><form>s Perf (VAorist Pl P2)</form></td>
</tr>
<tr>
<th>3 л.</th>
<td><form>s Perf (VAorist Sg P3)</form></td>
<td><form>s Perf (VAorist Pl P3)</form></td>
</tr>
</table>
<h3>Минало несвършено време (имперфект)</h3>
<table class="forms-table" rules="all">
<tr>
<th></th>
<th>ед.ч.</th>
<th>мн.ч.</th>
</tr>
<tr>
<th>1 л.</th>
<td><form>s Perf (VImperfect Sg P1)</form></td>
<td><form>s Perf (VImperfect Pl P1)</form></td>
</tr>
<tr>
<th>2 л.</th>
<td><form>s Perf (VImperfect Sg P2)</form></td>
<td><form>s Perf (VImperfect Pl P2)</form></td>
</tr>
<tr>
<th>3 л.</th>
<td><form>s Perf (VImperfect Sg P3)</form></td>
<td><form>s Perf (VImperfect Pl P3)</form></td>
</tr>
</table>
<h2>Повелително наклонение</h2>
<table class="forms-table" rules="all">
<tr>
<th>ед.ч.</th>
<th>мн.ч.</th>
</tr>
<tr>
<td><form>s Perf (VImperative Sg)</form></td>
<td><form>s Perf (VImperative Pl)</form></td>
</tr>
</table>
<h2>Причастия (отглаголни прилагателни)</h2>
<h3>Минало свършено деятелно причастие</h3>
<table class="forms-table" rules="all">
<tr>
<th rowspan="7">ед.ч.</th>
<th rowspan="3">м.р.</th>
<th>нечленувано</th>
<td><form>s Perf (VPerfect (ASg Masc Indef))</form></td>
</tr>
<tr>
<th>непълен член</th>
<td><form>s Perf (VPerfect (ASg Masc Def))</form></td>
</tr>
<tr>
<th>пълен член</th>
<td><form>s Perf (VPerfect ASgMascDefNom)</form></td>
</tr>
<tr>
<th rowspan="2">ж.р.</th>
<th>нечленувано</th>
<td><form>s Perf (VPerfect (ASg Fem Indef))</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s Perf (VPerfect (ASg Fem Def))</form></td>
</tr>
<tr>
<th rowspan="2">ср.р.</th>
<th>нечленувано</th>
<td><form>s Perf (VPerfect (ASg Neut Indef))</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s Perf (VPerfect (ASg Neut Def))</form></td>
</tr>
<tr>
<th rowspan="2" colspan="2">мн.ч.</th>
<th>нечленувано</th>
<td><form>s Perf (VPerfect (APl Indef))</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s Perf (VPerfect (APl Def))</form></td>
</tr>
</table>
<h3>Минало несвършено деятелно причастие</h3>
<table class="forms-table" rules="all">
<tr>
<th rowspan="7">ед.ч.</th>
<th rowspan="3">м.р.</th>
<th>нечленувано</th>
<td><form>s Perf (VPluPerfect (ASg Masc Indef))</form></td>
</tr>
<tr>
<th>непълен член</th>
<td><form>s Perf (VPluPerfect (ASg Masc Def))</form></td>
</tr>
<tr>
<th>пълен член</th>
<td><form>s Perf (VPluPerfect ASgMascDefNom)</form></td>
</tr>
<tr>
<th rowspan="2">ж.р.</th>
<th>нечленувано</th>
<td><form>s Perf (VPluPerfect (ASg Fem Indef))</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s Perf (VPluPerfect (ASg Fem Def))</form></td>
</tr>
<tr>
<th rowspan="2">ср.р.</th>
<th>нечленувано</th>
<td><form>s Perf (VPluPerfect (ASg Neut Indef))</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s Perf (VPluPerfect (ASg Neut Def))</form></td>
</tr>
<tr>
<th rowspan="2" colspan="2">мн.ч.</th>
<th>нечленувано</th>
<td><form>s Perf (VPluPerfect (APl Indef))</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s Perf (VPluPerfect (APl Def))</form></td>
</tr>
</table>
<h1>Отглаголно съществително</h1>
<table class="forms-table" rules="all">
<tr>
<th rowspan="2">ед.ч.</th>
<th>нечленувано</th>
<td><form>s Imperf (VNoun (NF Sg Indef))</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s Imperf (VNoun (NF Sg Def))</form></td>
</tr>
<tr>
<th rowspan="2">мн.ч.</th>
<th>нечленувано</th>
<td><form>s Imperf (VNoun (NF Pl Indef))</form></td>
</tr>
<tr>
<th>членувано</th>
<td><form>s Imperf (VNoun (NF Pl Def))</form></td>
</tr>
</table>
</verb>
</inflection_temlate>

View File

@@ -0,0 +1,84 @@
<inflection_temlate>
<noun>
<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>compar</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>

View File

@@ -8,11 +8,13 @@ public class Language implements Serializable {
private final String mLangCode;
private final String mLangName;
private final String mConcrete;
private final int mInflResource;
public Language(String langCode, String langName, String concrete) {
public Language(String langCode, String langName, String concrete, int inflResource) {
mLangCode = langCode;
mLangName = langName;
mConcrete = concrete;
mInflResource = inflResource;
}
public String getLangCode() {
@@ -22,6 +24,10 @@ public class Language implements Serializable {
public String getLangName() {
return mLangName;
}
public int getInflectionResource() {
return mInflResource;
}
String getConcrete() {
return mConcrete;

View File

@@ -1,19 +1,35 @@
package org.grammaticalframework.ui.android;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.webkit.WebView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
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 {
@@ -51,6 +67,8 @@ public class LexicalEntryActivity extends ListActivity {
mShowLanguageView.setSelectedLanguage(mTranslator.getTargetLanguage());
}
private View expandedView;
private void updateTranslations() {
@SuppressWarnings("unchecked")
List<MorphoAnalysis> list = (List<MorphoAnalysis>)
@@ -59,33 +77,167 @@ public class LexicalEntryActivity extends ListActivity {
List<String> data = new ArrayList<String>();
for (MorphoAnalysis a : list) {
Expr e = Expr.readExpr(a.getLemma());
String phrase = mTranslator.linearize(e);
if (!data.contains(phrase)) {
data.add(phrase);
if (!data.contains(a.getLemma())) {
data.add(a.getLemma());
}
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
data) {
public View getView(int position, View convertView, ViewGroup parent) {
String item = getItem(position);
LayoutInflater inflater = (LayoutInflater) getContext()
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.lexical_item, null);
}
TextView descView =
(TextView) convertView.findViewById(R.id.lexical_desc);
descView.setText(item);
return convertView;
}
};
setListAdapter(adapter);
setListAdapter(new LexicalAdapter(this, data));
expandedView = null;
}
private void collapse() {
if (expandedView == null)
return;
ImageView arrow = (ImageView) expandedView.findViewById(R.id.arrow);
arrow.setImageResource(R.drawable.open_arrow);
WebView inflectionView = (WebView) expandedView.findViewById(R.id.lexical_inflection);
((RelativeLayout) expandedView).removeView(inflectionView);
expandedView = null;
}
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);
WebView inflectionView = (WebView) view.findViewById(R.id.lexical_inflection);
if (inflectionView == null) {
inflectionView = new WebView(this);
inflectionView.setId(R.id.lexical_inflection);
RelativeLayout.LayoutParams params =
new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.BELOW, R.id.lexical_desc);
((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", null);
expandedView = view;
}
private class LexicalAdapter extends ArrayAdapter<String> {
public LexicalAdapter(Context context, List<String> data) {
super(context, android.R.layout.simple_list_item_1, data);
}
public View getView(int position, View convertView, ViewGroup parent) {
final String lemma = getItem(position);
LayoutInflater inflater = (LayoutInflater) getContext()
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.lexical_item, null);
}
TextView descView =
(TextView) convertView.findViewById(R.id.lexical_desc);
Expr e = Expr.readExpr(lemma);
String phrase = mTranslator.linearize(e);
descView.setText(phrase);
convertView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (expandedView == view)
collapse();
else if (expandedView == null)
expand(view, lemma);
else {
collapse();
expand(view, lemma);
}
}
});
return convertView;
}
}
}

View File

@@ -14,6 +14,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
public class Translator {
@@ -24,12 +25,10 @@ public class Translator {
// TODO: build dynamically?
private Language[] mLanguages = {
new Language("en-US", "English", "ParseEng"),
new Language("cmn-Hans-CN", "Chinese", "ParseChi"),
// new Language("de-DE", "German", "ParseGer"),
// new Language("es-ES", "Spanish", "ResourceDemoSpa"),
//new Language("fr-FR", "French", "ResourceDemoFre"),
// new Language("bg-BG", "Bulgarian", "ParseBul"),
new Language("en-US", "English", "ParseEng", R.xml.inflection_en),
new Language("bg-BG", "Bulgarian", "ParseBul", R.xml.inflection_bg),
//new Language("fr-FR", "French", "ParseFre", 0)
//new Language("cmn-Hans-CN", "Chinese", "ParseChi", 0)
};
private Language mSourceLanguage;
@@ -104,6 +103,11 @@ public class Translator {
return targetLang.linearize(e);
}
public Map<String,String> tabularLinearize(Expr e) {
Concr targetLang = getConcr(getTargetLanguage().getConcrete());
return targetLang.tabularLinearize(e);
}
public List<MorphoAnalysis> lookupMorpho(String sentence) {
return getConcr(getSourceLanguage().getConcrete()).lookupMorpho(sentence);
}