now the Documentation module contains a category Definition which is used to generate definitions and examples for words in the App.

This commit is contained in:
krasimir
2015-11-16 14:57:32 +00:00
parent fae5cba926
commit 80ccd0493d
16 changed files with 135 additions and 27 deletions

View File

@@ -5,6 +5,7 @@ abstract Documentation = Cat ** {
cat cat
Inflection ; -- inflection table Inflection ; -- inflection table
Definition ;
Document ; Document ;
Tag ; Tag ;
@@ -29,7 +30,12 @@ fun
InflectionPrep : Prep -> Inflection ; InflectionPrep : Prep -> Inflection ;
fun fun
MkDocument : String -> Inflection -> String -> Document ; NoDefinition : Definition ;
MkDefinition : String -> Definition ;
MkDefinitionEx : String -> String -> Definition ;
fun
MkDocument : Definition -> Inflection -> String -> Document ;
MkTag : Inflection -> Tag ; MkTag : Inflection -> Tag ;
} }

View File

@@ -6,6 +6,7 @@ flags coding=utf8 ;
lincat lincat
Inflection = {t : Str; s1,s2,s3 : Str} ; Inflection = {t : Str; s1,s2,s3 : Str} ;
Definition = {s : Str} ;
Document = {s : Str} ; Document = {s : Str} ;
Tag = {s : Str} ; Tag = {s : Str} ;
@@ -390,7 +391,12 @@ oper
pp : Str -> Str = \s -> "<"+s+">"; pp : Str -> Str = \s -> "<"+s+">";
lin lin
MkDocument b i e = {s = i.s1 ++ "<p style=\"font-size:20px\">"++b.s++"</p>" ++ i.s2 ++ i.s3 ++ e.s} ; NoDefinition = {s=""};
MkDefinition d = {s="<p><b>Дефиниция:</b>"++d.s++"</p>"};
MkDefinitionEx d e = {s="<p><b>Дефиниция:</b>"++d.s++"</p><p><b>Пример:</b>"++e.s++"</p>"};
lin
MkDocument d i e = {s = i.s1 ++ d.s ++ i.s2 ++ i.s3 ++ e.s} ;
MkTag i = {s = i.t} ; MkTag i = {s = i.t} ;
} }

View File

@@ -16,6 +16,7 @@ flags coding=utf8 ;
lincat lincat
Inflection = {t : Str; s1,s2 : Str} ; Inflection = {t : Str; s1,s2 : Str} ;
Definition = {s : Str} ;
Document = {s : Str} ; Document = {s : Str} ;
Tag = {s : Str} ; Tag = {s : Str} ;
@@ -132,7 +133,12 @@ lin
s2 = inflVerb v s2 = inflVerb v
} ; } ;
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 lin
NoDefinition = {s=""};
MkDefinition d = {s="<p><b>Definició:</b>"++d.s++"</p>"};
MkDefinitionEx d e = {s="<p><b>Definició:</b>"++d.s++"</p><p><b>Exemple:</b>"++e.s++"</p>"};
MkDocument d i e = ss (i.s1 ++ d.s ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph
MkTag i = ss i.t ; MkTag i = ss i.t ;
oper oper

View File

@@ -5,6 +5,7 @@ in {
lincat lincat
Inflection = {t : Str; s1,s2 : Str} ; Inflection = {t : Str; s1,s2 : Str} ;
Definition = {s : Str} ;
Document = {s : Str} ; Document = {s : Str} ;
Tag = {s : Str} ; Tag = {s : Str} ;
@@ -124,7 +125,12 @@ oper
pp : Str -> Str = \s -> "&lt;"+s+"&gt;" ; pp : Str -> Str = \s -> "&lt;"+s+"&gt;" ;
lin lin
MkDocument b i e = {s=i.s1 ++ "<p style=\"font-size:20px\">"++b.s++"</p>" ++ i.s2 ++ paragraph e.s} ; NoDefinition = {s=""};
MkDefinition d = {s="<p><b>定义:</b>"++d.s++"</p>"};
MkDefinitionEx d e = {s="<p><b>定义:</b>"++d.s++"</p><p><b>例子:</b>"++e.s++"</p>"};
lin
MkDocument d i e = {s=i.s1 ++ d.s ++ i.s2 ++ paragraph e.s} ;
MkTag i = {s=i.t} ; MkTag i = {s=i.t} ;
} }

View File

@@ -14,6 +14,7 @@ in {
lincat lincat
Inflection = {t : Str; s1,s2 : Str} ; Inflection = {t : Str; s1,s2 : Str} ;
Definition = {s : Str} ;
Document = {s : Str} ; Document = {s : Str} ;
Tag = {s : Str} ; Tag = {s : Str} ;
@@ -140,7 +141,12 @@ lin
s2 = inflVerb v s2 = inflVerb v
} ; } ;
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 lin
NoDefinition = {s=""};
MkDefinition d = {s="<p><b>Definitie:</b>"++d.s++"</p>"};
MkDefinitionEx d e = {s="<p><b>Definitie:</b>"++d.s++"</p><p><b>Voorbeeld:</b>"++e.s++"</p>"};
MkDocument d i e = ss (i.s1 ++ d.s ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph
MkTag i = ss i.t ; MkTag i = ss i.t ;
oper oper

View File

@@ -5,6 +5,7 @@ concrete DocumentationEng of Documentation = CatEng ** open
lincat lincat
Inflection = {t : Str; s1,s2 : Str} ; Inflection = {t : Str; s1,s2 : Str} ;
Definition = {s : Str} ;
Document = {s : Str} ; Document = {s : Str} ;
Tag = {s : Str} ; Tag = {s : Str} ;
@@ -178,7 +179,12 @@ oper
pp : Str -> Str = \s -> "&lt;"+s+"&gt;"; pp : Str -> Str = \s -> "&lt;"+s+"&gt;";
lin lin
MkDocument b i e = {s = i.s1 ++ paragraph b.s ++ i.s2 ++ paragraph e.s} ; NoDefinition = {s=""};
MkDefinition d = {s="<p><b>Definition:</b>"++d.s++"</p>"};
MkDefinitionEx d e = {s="<p><b>Definition:</b>"++d.s++"</p><p><b>Example:</b>"++e.s++"</p>"};
lin
MkDocument d i e = {s = i.s1 ++ d.s ++ i.s2 ++ paragraph e.s} ;
MkTag i = {s = i.t} ; MkTag i = {s = i.t} ;
} }

View File

@@ -13,6 +13,7 @@ in {
lincat lincat
Inflection = {t : Str; s1,s2 : Str} ; Inflection = {t : Str; s1,s2 : Str} ;
Definition = {s : Str} ;
Document = {s : Str} ; Document = {s : Str} ;
Tag = {s : Str} ; Tag = {s : Str} ;
@@ -263,6 +264,11 @@ oper
tr (th (heading instructive_Parameter) ++ td (nouns (NCase Sg Termin)) ++ td (nouns (NCase Pl Termin)) tr (th (heading instructive_Parameter) ++ td (nouns (NCase Sg Termin)) ++ td (nouns (NCase Pl Termin))
)) ; )) ;
lin
NoDefinition = {s=""};
MkDefinition d = {s="<p><b>Definitsioon:</b>"++d.s++"</p>"};
MkDefinitionEx d e = {s="<p><b>Definitsioon:</b>"++d.s++"</p><p><b>Eeskuju:</b>"++e.s++"</p>"};
lin 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 ++ paragraph b.s ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph
MkTag i = ss (i.t) ; MkTag i = ss (i.t) ;

View File

@@ -14,6 +14,7 @@ in {
lincat lincat
Inflection = {t : Str; s1,s2 : Str} ; Inflection = {t : Str; s1,s2 : Str} ;
Definition = {s : Str} ;
Document = {s : Str} ; Document = {s : Str} ;
Tag = {s : Str} ; Tag = {s : Str} ;
@@ -290,7 +291,12 @@ oper
) ; ) ;
lin lin
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 NoDefinition = {s=""};
MkDefinition d = {s="<p><b>Rajaus:</b>"++d.s++"</p>"};
MkDefinitionEx d e = {s="<p><b>Rajaus:</b>"++d.s++"</p><p><b>Esimerkki:</b>"++e.s++"</p>"};
lin
MkDocument d i e = ss (i.s1 ++ d.s ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph
MkTag i = ss (i.t) ; MkTag i = ss (i.t) ;
{- --# notpresent {- --# notpresent

View File

@@ -16,6 +16,7 @@ flags coding=utf8 ;
lincat lincat
Inflection = {t : Str; s1,s2 : Str} ; Inflection = {t : Str; s1,s2 : Str} ;
Definition = {s : Str} ;
Document = {s : Str} ; Document = {s : Str} ;
Tag = {s : Str} ; Tag = {s : Str} ;
@@ -132,7 +133,12 @@ lin
s2 = inflVerb v s2 = inflVerb v
} ; } ;
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 lin
NoDefinition = {s=""};
MkDefinition d = {s="<p><b>Définition:</b>"++d.s++"</p>"};
MkDefinitionEx d e = {s="<p><b>Définition:</b>"++d.s++"</p><p><b>Exemple:</b>"++e.s++"</p>"};
MkDocument d i e = ss (i.s1 ++ d.s ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph
MkTag i = ss i.t ; MkTag i = ss i.t ;
oper oper

View File

@@ -15,6 +15,7 @@ flags coding=utf8 ;
lincat lincat
Inflection = {t : Str; s1,s2 : Str} ; Inflection = {t : Str; s1,s2 : Str} ;
Definition = {s : Str} ;
Document = {s : Str} ; Document = {s : Str} ;
Tag = {s : Str} ; Tag = {s : Str} ;
@@ -144,7 +145,12 @@ lin
s2 = inflVerb v s2 = inflVerb v
} ; } ;
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 lin
NoDefinition = {s=""};
MkDefinition d = {s="<p><b>Definierung:</b>"++d.s++"</p>"};
MkDefinitionEx d e = {s="<p><b>Definierung:</b>"++d.s++"</p><p><b>Beispiel:</b>"++e.s++"</p>"};
MkDocument d i e = ss (i.s1 ++ d.s ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph
MkTag i = ss i.t ; MkTag i = ss i.t ;
oper oper

View File

@@ -6,6 +6,7 @@ in {
lincat lincat
Inflection = {t : Str; s1,s2 : Str} ; Inflection = {t : Str; s1,s2 : Str} ;
Definition = {s : Str} ;
Document = {s : Str} ; Document = {s : Str} ;
Tag = {s : Str} ; Tag = {s : Str} ;
@@ -120,7 +121,12 @@ lin
} ; } ;
lin lin
MkDocument b i e = {s = i.s1 ++ "<p style=\"font-size:20px\">"++b.s++"</p>" ++ i.s2 ++ paragraph e.s} ; NoDefinition = {s=""};
MkDefinition d = {s="<p><b>परिभाषा:</b>"++d.s++"</p>"};
MkDefinitionEx d e = {s="<p><b>परिभाषा:</b>"++d.s++"</p><p><b>नमूना:</b>"++e.s++"</p>"};
lin
MkDocument d i e = {s = i.s1 ++ d.s ++ i.s2 ++ paragraph e.s} ;
MkTag i = {s = i.t} ; MkTag i = {s = i.t} ;
} }

View File

@@ -16,6 +16,7 @@ flags coding=utf8 ;
lincat lincat
Inflection = {t : Str; s1,s2 : Str} ; Inflection = {t : Str; s1,s2 : Str} ;
Definition = {s : Str} ;
Document = {s : Str} ; Document = {s : Str} ;
Tag = {s : Str} ; Tag = {s : Str} ;
@@ -132,7 +133,13 @@ lin
s2 = inflVerb v s2 = inflVerb v
} ; } ;
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 lin
NoDefinition = {s=""};
MkDefinition d = {s="<p><b>Definizione:</b>"++d.s++"</p>"};
MkDefinitionEx d e = {s="<p><b>Definizione:</b>"++d.s++"</p><p><b>Esempio:</b>"++e.s++"</p>"};
lin
MkDocument d i e = ss (i.s1 ++ d.s ++ i.s2 ++ paragraph e.s) ; -- explanation appended in a new paragraph
MkTag i = ss i.t ; MkTag i = ss i.t ;
oper oper

View File

@@ -16,6 +16,7 @@ flags coding=utf8 ;
lincat lincat
Inflection = {t : Str; s1,s2 : Str} ; Inflection = {t : Str; s1,s2 : Str} ;
Definition = {s : Str} ;
Document = {s : Str} ; Document = {s : Str} ;
Tag = {s : Str} ; Tag = {s : Str} ;
@@ -132,6 +133,12 @@ lin
s2 = inflVerb v s2 = inflVerb v
} ; } ;
lin
NoDefinition = {s=""};
MkDefinition d = {s="<p><b>Definición:</b>"++d.s++"</p>"};
MkDefinitionEx d e = {s="<p><b>Definición:</b>"++d.s++"</p><p><b>Ejemplo:</b>"++e.s++"</p>"};
lin
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 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 ; MkTag i = ss i.t ;

View File

@@ -6,6 +6,7 @@ in {
flags coding=utf8 ; flags coding=utf8 ;
lincat lincat
Inflection = {t : Str; s1,s2 : Str} ; Inflection = {t : Str; s1,s2 : Str} ;
Definition = {s : Str} ;
Document = {s : Str} ; Document = {s : Str} ;
Tag = {s : Str} ; Tag = {s : Str} ;
@@ -178,7 +179,12 @@ lin
s2 = inflVerb v s2 = inflVerb v
} ; } ;
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 lin
NoDefinition = {s=""};
MkDefinition d = {s="<p><b>Definition:</b>"++d.s++"</p>"};
MkDefinitionEx d e = {s="<p><b>Definition:</b>"++d.s++"</p><p><b>Exempel:</b>"++e.s++"</p>"};
MkDocument d i e = {s = i.s1 ++ d.s ++ i.s2 ++ paragraph e.s} ; -- explanation appended in a new paragraph
MkTag i = {s = i.t} ; MkTag i = {s = i.t} ;
oper oper

View File

@@ -76,22 +76,39 @@ public class SemanticGraphManager implements Closeable {
} }
} }
public Expr getGloss(Expr lemma) { public Expr getDefinition(Expr lemma, boolean withExample) {
Expr obj = null; Expr gloss = null;
Expr example = null;
try { try {
createDatabaseFromAssets(); createDatabaseFromAssets();
TripleResult res = mDB.queryTriple(lemma, Expr.readExpr("gloss"), null);
if (res.hasNext()) { {
obj = res.getObject(); TripleResult res = mDB.queryTriple(lemma, Expr.readExpr("gloss"), null);
if (res.hasNext()) {
gloss = res.getObject();
}
res.close();
}
if (withExample) {
TripleResult res = mDB.queryTriple(lemma, Expr.readExpr("example"), null);
if (res.hasNext()) {
example = res.getObject();
}
res.close();
} }
res.close();
} catch (IOException e) { } catch (IOException e) {
// nothing // nothing
} catch (SGError e) { } catch (SGError e) {
// nothing // nothing
} }
return obj; if (gloss == null)
return null;
else if (example == null)
return new Expr("MkDefinition", gloss);
else
return new Expr("MkDefinitionEx", gloss, example);
} }
} }

View File

@@ -367,26 +367,31 @@ public class Translator {
} }
public String getInflectionTable(String lemma) { public String getInflectionTable(String lemma) {
Expr lemmaExpr = Expr.readExpr(lemma); boolean withExample =
Expr gloss = mSGManager.getGloss(lemmaExpr); (getSourceLanguage().getLangCode().equals("en-US") ||
Expr empty = Expr.readExpr("\"\""); getTargetLanguage().getLangCode().equals("en-US"));
Expr def =
mSGManager.getDefinition(Expr.readExpr(lemma), withExample);
Concr targetLang = getTargetConcr(); Concr targetLang = getTargetConcr();
String cat = getGrammar().getFunctionType(lemma).getCategory(); String cat = getGrammar().getFunctionType(lemma).getCategory();
if (targetLang.hasLinearization(lemma) && if (targetLang.hasLinearization(lemma) &&
targetLang.hasLinearization("Inflection"+cat)) { targetLang.hasLinearization("Inflection"+cat)) {
if (gloss == null) if (def == null)
gloss = empty; def = new Expr("NoDefinition");
Expr e = new Expr("MkDocument", gloss, Expr.readExpr("Inflection"+cat+" "+lemma), empty); Expr e = new Expr("MkDocument",
def,
Expr.readExpr("Inflection"+cat+" "+lemma),
Expr.readExpr("\"\""));
String html = String html =
"<html><head><meta charset=\"UTF-8\"/></head><body>" + "<html><head><meta charset=\"UTF-8\"/></head><body>" +
targetLang.linearize(e) + targetLang.linearize(e) +
"</body>"; "</body>";
return html; return html;
} else if (gloss != null) { } else if (def != null) {
return "<p style=\"font-size:20px\">"+targetLang.linearize(gloss)+"</p>"; return targetLang.linearize(def);
} else { } else {
return null; return null;
} }