From f716974e89ee9868e7f46731cce1097acb5febae Mon Sep 17 00:00:00 2001 From: krasimir Date: Wed, 1 Jul 2015 09:44:56 +0000 Subject: [PATCH] the Android app now can show Glosses from WordNet --- lib/src/bulgarian/DocumentationBul.gf | 3 +- lib/src/catalan/DocumentationCatFunctor.gf | 2 +- lib/src/chinese/DocumentationChi.gf | 2 +- lib/src/dutch/DocumentationDutFunctor.gf | 2 +- lib/src/english/DocumentationEngFunctor.gf | 2 +- lib/src/finnish/DocumentationFinFunctor.gf | 2 +- lib/src/french/DocumentationFreFunctor.gf | 2 +- lib/src/german/DocumentationGerFunctor.gf | 2 +- lib/src/hindi/DocumentationHin.gf | 2 +- lib/src/italian/DocumentationItaFunctor.gf | 2 +- lib/src/spanish/DocumentationSpaFunctor.gf | 2 +- lib/src/swedish/DocumentationSwe.gf | 2 +- lib/src/swedish/DocumentationSweEng.gf | 6 - lib/src/swedish/DocumentationSweFunctor.gf | 131 ------------------ .../ui/android/Translator.java | 62 +++++++-- 15 files changed, 65 insertions(+), 159 deletions(-) delete mode 100644 lib/src/swedish/DocumentationSweEng.gf delete mode 100644 lib/src/swedish/DocumentationSweFunctor.gf diff --git a/lib/src/bulgarian/DocumentationBul.gf b/lib/src/bulgarian/DocumentationBul.gf index a2c3a3806..a3bcaabfa 100644 --- a/lib/src/bulgarian/DocumentationBul.gf +++ b/lib/src/bulgarian/DocumentationBul.gf @@ -390,8 +390,7 @@ oper pp : Str -> Str = \s -> "<"+s+">"; lin - MkDocument b i e = {s = i.s1 ++ b.s ++ i.s2 ++ i.s3 ++ e.s} ; + MkDocument b i e = {s = i.s1 ++ "

"++b.s++"

" ++ i.s2 ++ i.s3 ++ e.s} ; MkTag i = {s = i.t} ; } - diff --git a/lib/src/catalan/DocumentationCatFunctor.gf b/lib/src/catalan/DocumentationCatFunctor.gf index a42e45be5..1e9dca2b6 100644 --- a/lib/src/catalan/DocumentationCatFunctor.gf +++ b/lib/src/catalan/DocumentationCatFunctor.gf @@ -132,7 +132,7 @@ lin s2 = inflVerb v } ; - MkDocument b i e = ss (i.s1 ++ paragraph b.s ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph + MkDocument b i e = ss (i.s1 ++ "

"++b.s++"

" ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph MkTag i = ss i.t ; oper diff --git a/lib/src/chinese/DocumentationChi.gf b/lib/src/chinese/DocumentationChi.gf index 9d4beef9f..216f3af10 100644 --- a/lib/src/chinese/DocumentationChi.gf +++ b/lib/src/chinese/DocumentationChi.gf @@ -124,7 +124,7 @@ oper pp : Str -> Str = \s -> "<"+s+">" ; lin - MkDocument b i e = {s=i.s1 ++ paragraph b.s ++ i.s2 ++ paragraph e.s} ; + MkDocument b i e = {s=i.s1 ++ "

"++b.s++"

" ++ i.s2 ++ paragraph e.s} ; MkTag i = {s=i.t} ; } diff --git a/lib/src/dutch/DocumentationDutFunctor.gf b/lib/src/dutch/DocumentationDutFunctor.gf index caae5dbd1..9cda67211 100644 --- a/lib/src/dutch/DocumentationDutFunctor.gf +++ b/lib/src/dutch/DocumentationDutFunctor.gf @@ -140,7 +140,7 @@ lin s2 = inflVerb v } ; - MkDocument b i e = ss (i.s1 ++ paragraph b.s ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph + MkDocument b i e = ss (i.s1 ++ "

"++b.s++"

" ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph MkTag i = ss i.t ; oper diff --git a/lib/src/english/DocumentationEngFunctor.gf b/lib/src/english/DocumentationEngFunctor.gf index 1849eed2c..d1be94b34 100644 --- a/lib/src/english/DocumentationEngFunctor.gf +++ b/lib/src/english/DocumentationEngFunctor.gf @@ -61,7 +61,7 @@ lin --- InflectionVV v = inflectionVerb (verbExample (S.mkCl S.she_NP (lin VV v) (S.mkVP (L.sleep_V)))) (lin V v) ; - MkDocument b i e = ss (i.s1 ++ paragraph b.s ++ i.s2 ++ paragraph e.s) ; + MkDocument b i e = ss (i.s1 ++ "

"++b.s++"

" ++ i.s2 ++ paragraph e.s) ; oper verbExample : CatEng.Cl -> Str = \cl -> (S.mkUtt cl).s ; diff --git a/lib/src/finnish/DocumentationFinFunctor.gf b/lib/src/finnish/DocumentationFinFunctor.gf index cdceaba53..78902ec81 100644 --- a/lib/src/finnish/DocumentationFinFunctor.gf +++ b/lib/src/finnish/DocumentationFinFunctor.gf @@ -290,7 +290,7 @@ oper ) ; lin - MkDocument b i e = ss (i.s1 ++ paragraph b.s ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph + MkDocument b i e = ss (i.s1 ++ "

"++b.s++"

" ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph MkTag i = ss (i.t) ; {- --# notpresent diff --git a/lib/src/french/DocumentationFreFunctor.gf b/lib/src/french/DocumentationFreFunctor.gf index 0d7282a63..08e1c2cd2 100644 --- a/lib/src/french/DocumentationFreFunctor.gf +++ b/lib/src/french/DocumentationFreFunctor.gf @@ -132,7 +132,7 @@ lin s2 = inflVerb v } ; - MkDocument b i e = ss (i.s1 ++ paragraph b.s ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph + MkDocument b i e = ss (i.s1 ++ "

"++b.s++"

" ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph MkTag i = ss i.t ; oper diff --git a/lib/src/german/DocumentationGerFunctor.gf b/lib/src/german/DocumentationGerFunctor.gf index 834b4ca67..2d58b4258 100644 --- a/lib/src/german/DocumentationGerFunctor.gf +++ b/lib/src/german/DocumentationGerFunctor.gf @@ -144,7 +144,7 @@ lin s2 = inflVerb v } ; - MkDocument b i e = ss (i.s1 ++ paragraph b.s ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph + MkDocument b i e = ss (i.s1 ++ "

"++b.s++"

" ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph MkTag i = ss i.t ; oper diff --git a/lib/src/hindi/DocumentationHin.gf b/lib/src/hindi/DocumentationHin.gf index a2724b93a..abd0ad44b 100644 --- a/lib/src/hindi/DocumentationHin.gf +++ b/lib/src/hindi/DocumentationHin.gf @@ -120,7 +120,7 @@ lin } ; lin - MkDocument b i e = {s = i.s1 ++ paragraph b.s ++ i.s2 ++ paragraph e.s} ; + MkDocument b i e = {s = i.s1 ++ "

"++b.s++"

" ++ i.s2 ++ paragraph e.s} ; MkTag i = {s = i.t} ; } diff --git a/lib/src/italian/DocumentationItaFunctor.gf b/lib/src/italian/DocumentationItaFunctor.gf index 5eeb2372b..07f664efd 100644 --- a/lib/src/italian/DocumentationItaFunctor.gf +++ b/lib/src/italian/DocumentationItaFunctor.gf @@ -132,7 +132,7 @@ lin s2 = inflVerb v } ; - MkDocument b i e = ss (i.s1 ++ paragraph b.s ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph + MkDocument b i e = ss (i.s1 ++ "

"++b.s++"

" ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph MkTag i = ss i.t ; oper diff --git a/lib/src/spanish/DocumentationSpaFunctor.gf b/lib/src/spanish/DocumentationSpaFunctor.gf index 59f2bc9a6..04d17bb79 100644 --- a/lib/src/spanish/DocumentationSpaFunctor.gf +++ b/lib/src/spanish/DocumentationSpaFunctor.gf @@ -132,7 +132,7 @@ lin s2 = inflVerb v } ; - MkDocument b i e = ss (i.s1 ++ paragraph b.s ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph + MkDocument b i e = ss (i.s1 ++ "

"++b.s++"

" ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph MkTag i = ss i.t ; oper diff --git a/lib/src/swedish/DocumentationSwe.gf b/lib/src/swedish/DocumentationSwe.gf index ca95c028a..3f531a8b0 100644 --- a/lib/src/swedish/DocumentationSwe.gf +++ b/lib/src/swedish/DocumentationSwe.gf @@ -178,7 +178,7 @@ lin s2 = inflVerb v } ; - MkDocument b i e = {s = i.s1 ++ paragraph b.s ++ i.s2 ++ paragraph e.s} ; -- explanation appended in a new paragraph + MkDocument b i e = {s = i.s1 ++ "

"++b.s++"

" ++ i.s2 ++ paragraph e.s} ; -- explanation appended in a new paragraph MkTag i = {s = i.t} ; oper diff --git a/lib/src/swedish/DocumentationSweEng.gf b/lib/src/swedish/DocumentationSweEng.gf deleted file mode 100644 index 010607509..000000000 --- a/lib/src/swedish/DocumentationSweEng.gf +++ /dev/null @@ -1,6 +0,0 @@ ---# -path=.:../abstract:../common - --- documentation of Swedish in English - -concrete DocumentationSweEng of Documentation = CatSwe ** - DocumentationSweFunctor with (Terminology = TerminologyEng) ; diff --git a/lib/src/swedish/DocumentationSweFunctor.gf b/lib/src/swedish/DocumentationSweFunctor.gf deleted file mode 100644 index a1f16a3d4..000000000 --- a/lib/src/swedish/DocumentationSweFunctor.gf +++ /dev/null @@ -1,131 +0,0 @@ ---# -path=.:../abstract:../common - --- generic documentation: varying the Terminology interface gives documentation of Swe in different languages - -incomplete concrete DocumentationSweFunctor of Documentation = CatSwe ** open - Terminology, -- as interface - ResSwe, - CommonScand, - ParadigmsSwe, - (G = GrammarSwe), - (S = SyntaxSwe), - (L = LexiconSwe), - Prelude, - HTML -in { - - -lincat - Inflection = {s : Str} ; - Document = {s : Str} ; - -{- --} --# notpresent - - -oper - tdf : Str -> Str = \s -> td (intag "i" s) ; - heading : N -> Str = \n -> (nounHeading n).s ; - - nounGender : CatSwe.N -> Parameter = \n -> case n.g of { - Utr => uter_Parameter ; - Neutr => neuter_Parameter - } ; - -lin - InflectionN noun = { - s = heading1 (heading noun_Category) ++ - paragraph (intag "b" (heading (gender_ParameterType)) ++ ":" ++ heading (nounGender noun) ++ ";" ++ - intag "i" (S.mkUtt (S.mkNP S.a_Det noun)).s) ++ - frameTable ( - tr (intagAttr "th" "colspan=2" "" ++ th (heading singular_Parameter) ++ th (heading plural_Parameter) ) ++ - tr (intagAttr "th" "rowspan=2" (heading nominative_Parameter) ++ - th (heading indefinite_Parameter) ++ tdf (noun.s ! Sg ! Indef ! Nom) ++ tdf (noun.s ! Pl ! Indef ! Nom)) ++ - tr (th (heading definite_Parameter) ++ tdf (noun.s ! Sg ! Def ! Nom) ++ tdf (noun.s ! Pl ! Def ! Nom)) ++ - tr (intagAttr "th" "rowspan=2" (heading genitive_Parameter) ++ - th (heading indefinite_Parameter) ++ tdf (noun.s ! Sg ! Indef ! Gen) ++ tdf (noun.s ! Pl ! Indef ! Gen)) ++ - tr (th (heading definite_Parameter) ++ tdf (noun.s ! Sg ! Def ! Gen) ++ tdf (noun.s ! Pl ! Def ! Gen)) - ) - } ; - - InflectionA adj = - let - gforms : Case -> Str = \c -> - tdf (adj.s ! (AF (APosit (Strong (GSg Utr))) c)) ++ - tdf (adj.s ! (AF (APosit (Strong (GSg Neutr))) c)) ++ - tdf (adj.s ! (AF (APosit (Strong GPl)) c)) ++ - tdf (adj.s ! (AF (APosit (Weak Sg)) c)) ; - in - { - s = heading1 (nounHeading adjective_Category).s ++ - frameTable ( - tr (intagAttr "th" "colspan=2" [] ++ - th (heading uter_Parameter) ++ th (heading neuter_Parameter) ++ - th (heading plural_Parameter) ++ th (heading definite_Parameter)) ++ - tr (intagAttr "th" "rowspan=2" (heading positive_Parameter) ++ - th (heading nominative_Parameter) ++ gforms Nom) ++ - tr ( th (heading genitive_Parameter) ++ gforms Gen) ++ - tr (intagAttr "th" "rowspan=2" (heading comparative_Parameter) ++ - th (heading nominative_Parameter) ++ intagAttr "td" "colspan=4" (intag "i" (adj.s ! AF ACompar Nom))) ++ - tr ( th (heading genitive_Parameter) ++ intagAttr "td" "colspan=4" (intag "i" (adj.s ! AF ACompar Gen))) ++ - tr (intagAttr "th" "rowspan=2" (heading superlative_Parameter) ++ - th (heading nominative_Parameter) ++ - intagAttr "td" "colspan=3" (intag "i" (adj.s ! AF (ASuperl SupStrong) Nom)) ++ - tdf (adj.s ! AF (ASuperl SupWeak) Nom)) ++ - tr ( th (heading genitive_Parameter) ++ - intagAttr "td" "colspan=3" (intag "i" (adj.s ! AF (ASuperl SupStrong) Gen)) ++ - tdf (adj.s ! AF (ASuperl SupWeak) Gen)) - ) - - } ; - - InflectionV v = inflectionVerb (verbExample (S.mkCl S.she_NP (lin V v))) v ; - InflectionV2 v = inflectionVerb (verbExample (S.mkCl S.she_NP (lin V2 v) S.something_NP)) (lin V v) ; - InflectionVV v = inflectionVerb (verbExample (S.mkCl S.she_NP (lin VV v) (S.mkVP (L.sleep_V)))) (lin V v) ; - InflectionV2V v = inflectionVerb (verbExample (S.mkCl S.she_NP (lin V2V v) S.we_NP (S.mkVP (L.sleep_V)))) (lin V v) ; - - InflectionPrep p = { - s = heading1 (heading preposition_Category) ++ - paragraph (intag "b" (heading exampleGr_N ++ ":") ++ intag "i" (S.mkAdv (lin Prep p) (S.mkNP S.a_Det L.computer_N)).s) - } ; - - MkDocument b i e = ss (paragraph e.s ++ i.s ++ paragraph e.s) ; -- explanation appended in a new paragraph - -oper - verbExample : Cl -> Str = \cl -> - (S.mkUtt cl).s - ++ ";" ++ (S.mkUtt (S.mkS S.anteriorAnt cl)).s --# notpresent - ; - - inflectionVerb : Str -> CatSwe.V -> {s : Str} = \ex,verb -> - let - vfin : VForm -> Str = \f -> - verb.s ! f ; - gforms : Voice -> Str = \v -> - tdf (vfin (VI (VInfin v))) - ++ tdf (vfin (VF (VPres v))) - ++ tdf (vfin (VF (VPret v))) --# notpresent - ++ tdf (vfin (VI (VSupin v))) --# notpresent - ++ tdf (vfin (VF (VImper v))) - ; - in { - s = - heading1 (heading verb_Category) ++ - paragraph (intag "b" (heading exampleGr_N ++ ":") ++ intag "i" ex) ++ - paragraph (frameTable ( - tr (th "" ++ th (heading infinitive_Parameter) ++ th (heading present_Parameter) ++ - th (heading past_Parameter) ++ th (heading supine_Parameter) ++ th (heading imperative_Parameter)) ++ - tr (th (heading active_Parameter) ++ gforms Act) ++ - tr (th (heading passive_Parameter) ++ gforms Pass) - )) ++ - paragraph ( - frameTable ( - tr (th (heading present_Parameter ++ heading participle_Parameter) ++ tdf (verb.s ! (VI (VPtPres Sg Indef Nom)))) ++ - tr (th (heading perfect_Parameter ++ heading participle_Parameter) ++ tdf (verb.s ! (VI (VPtPret (Strong (GSg Utr)) Nom)))) - )) - } ; - -{- --# notpresent --} - -} diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/Translator.java b/src/ui/android/src/org/grammaticalframework/ui/android/Translator.java index 88271c941..f5eba7bb0 100644 --- a/src/ui/android/src/org/grammaticalframework/ui/android/Translator.java +++ b/src/ui/android/src/org/grammaticalframework/ui/android/Translator.java @@ -5,6 +5,8 @@ import android.content.SharedPreferences; import android.util.Log; import android.util.Pair; import android.view.inputmethod.CompletionInfo; +import android.database.sqlite.SQLiteDatabase; +import android.database.Cursor; import org.grammaticalframework.pgf.*; import java.io.*; @@ -45,6 +47,7 @@ public class Translator { private ConcrLoader mSourceLoader; private ConcrLoader mTargetLoader; private ConcrLoader mOtherLoader; + private DBManager mDBManager; private static final String SOURCE_LANG_KEY = "source_lang"; private static final String TARGET_LANG_KEY = "target_lang"; @@ -94,6 +97,8 @@ public class Translator { } mOtherLoader = null; + + mDBManager = new DBManager(context); } public List getAvailableLanguages() { @@ -360,22 +365,61 @@ public class Translator { } public String getInflectionTable(String lemma) { + SQLiteDatabase db = mDBManager.getReadableDatabase(); + Cursor crs = db.rawQuery("select def from defs where fun=?1", new String[] { lemma }); + String def = ""; + if (crs.moveToNext()) { + def = escapeHtml(crs.getString(0)); + } + crs.close(); + Concr targetLang = getTargetConcr(); String cat = getGrammar().getFunctionType(lemma).getCategory(); - if (!targetLang.hasLinearization(lemma)) + if (targetLang.hasLinearization(lemma) && + targetLang.hasLinearization("Inflection"+cat)) { + Expr e = Expr.readExpr("MkDocument \""+def+"\" (Inflection"+cat+" "+lemma+") \"\""); + String html = + "" + + targetLang.linearize(e) + + ""; + return html; + } else if (def != "") { + return "

"+def+"

"; + } else { return null; + } + } + + private static String escapeHtml(CharSequence text) { + StringBuilder out = new StringBuilder(); - if (!targetLang.hasLinearization("Inflection"+cat)) - return null; + for (int i = 0; i < text.length(); i++) { + char c = text.charAt(i); - Expr e = Expr.readExpr("MkDocument \"\" (Inflection"+cat+" "+lemma+") \"\""); - String html = - "" + - targetLang.linearize(e) + - ""; + if (c == '<') { + out.append("<"); + } else if (c == '>') { + out.append(">"); + } else if (c == '&') { + out.append("&"); + } else if (c == '"') { + out.append("""); + } else if (c > 0x7E || c < ' ') { + out.append("&#").append((int) c).append(";"); + } else if (c == ' ') { + while (i + 1 < text.length() && text.charAt(i + 1) == ' ') { + out.append(" "); + i++; + } - return html; + out.append(' '); + } else { + out.append(c); + } + } + + return out.toString(); } public List lookupMorpho(String sentence) {