forked from GitHub/gf-core
the Android app now can show Glosses from WordNet
This commit is contained in:
@@ -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 ++ "<p style=\"font-size:20px\">"++b.s++"</p>" ++ i.s2 ++ i.s3 ++ e.s} ;
|
||||
MkTag i = {s = i.t} ;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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 ++ "<p style=\"font-size:20px\">"++b.s++"</p>" ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph
|
||||
MkTag i = ss i.t ;
|
||||
|
||||
oper
|
||||
|
||||
@@ -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 ++ "<p style=\"font-size:20px\">"++b.s++"</p>" ++ i.s2 ++ paragraph e.s} ;
|
||||
MkTag i = {s=i.t} ;
|
||||
|
||||
}
|
||||
|
||||
@@ -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 ++ "<p style=\"font-size:20px\">"++b.s++"</p>" ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph
|
||||
MkTag i = ss i.t ;
|
||||
|
||||
oper
|
||||
|
||||
@@ -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 ++ "<p style=\"font-size:20px\">"++b.s++"</p>" ++ i.s2 ++ paragraph e.s) ;
|
||||
|
||||
oper
|
||||
verbExample : CatEng.Cl -> Str = \cl -> (S.mkUtt cl).s ;
|
||||
|
||||
@@ -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 ++ "<p style=\"font-size:20px\">"++b.s++"</p>" ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph
|
||||
MkTag i = ss (i.t) ;
|
||||
|
||||
{- --# notpresent
|
||||
|
||||
@@ -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 ++ "<p style=\"font-size:20px\">"++b.s++"</p>" ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph
|
||||
MkTag i = ss i.t ;
|
||||
|
||||
oper
|
||||
|
||||
@@ -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 ++ "<p style=\"font-size:20px\">"++b.s++"</p>" ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph
|
||||
MkTag i = ss i.t ;
|
||||
|
||||
oper
|
||||
|
||||
@@ -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 ++ "<p style=\"font-size:20px\">"++b.s++"</p>" ++ i.s2 ++ paragraph e.s} ;
|
||||
MkTag i = {s = i.t} ;
|
||||
|
||||
}
|
||||
|
||||
@@ -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 ++ "<p style=\"font-size:20px\">"++b.s++"</p>" ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph
|
||||
MkTag i = ss i.t ;
|
||||
|
||||
oper
|
||||
|
||||
@@ -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 ++ "<p style=\"font-size:20px\">"++b.s++"</p>" ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph
|
||||
MkTag i = ss i.t ;
|
||||
|
||||
oper
|
||||
|
||||
@@ -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 ++ "<p style=\"font-size:20px\">"++b.s++"</p>" ++ i.s2 ++ paragraph e.s} ; -- explanation appended in a new paragraph
|
||||
MkTag i = {s = i.t} ;
|
||||
|
||||
oper
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
--# -path=.:../abstract:../common
|
||||
|
||||
-- documentation of Swedish in English
|
||||
|
||||
concrete DocumentationSweEng of Documentation = CatSwe **
|
||||
DocumentationSweFunctor with (Terminology = TerminologyEng) ;
|
||||
@@ -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
|
||||
-}
|
||||
|
||||
}
|
||||
@@ -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<Language> 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 =
|
||||
"<html><head><meta charset=\"UTF-8\"/></head><body>" +
|
||||
targetLang.linearize(e) +
|
||||
"</body>";
|
||||
return html;
|
||||
} else if (def != "") {
|
||||
return "<p style=\"font-size:20px\">"+def+"</p>";
|
||||
} 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 =
|
||||
"<html><head><meta charset=\"UTF-8\"/></head><body>" +
|
||||
targetLang.linearize(e) +
|
||||
"</body>";
|
||||
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<MorphoAnalysis> lookupMorpho(String sentence) {
|
||||
|
||||
Reference in New Issue
Block a user