mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-09 04:59:31 -06:00
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:
@@ -5,6 +5,7 @@ abstract Documentation = Cat ** {
|
||||
|
||||
cat
|
||||
Inflection ; -- inflection table
|
||||
Definition ;
|
||||
Document ;
|
||||
Tag ;
|
||||
|
||||
@@ -29,7 +30,12 @@ fun
|
||||
InflectionPrep : Prep -> Inflection ;
|
||||
|
||||
fun
|
||||
MkDocument : String -> Inflection -> String -> Document ;
|
||||
NoDefinition : Definition ;
|
||||
MkDefinition : String -> Definition ;
|
||||
MkDefinitionEx : String -> String -> Definition ;
|
||||
|
||||
fun
|
||||
MkDocument : Definition -> Inflection -> String -> Document ;
|
||||
MkTag : Inflection -> Tag ;
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ flags coding=utf8 ;
|
||||
|
||||
lincat
|
||||
Inflection = {t : Str; s1,s2,s3 : Str} ;
|
||||
Definition = {s : Str} ;
|
||||
Document = {s : Str} ;
|
||||
Tag = {s : Str} ;
|
||||
|
||||
@@ -390,7 +391,12 @@ oper
|
||||
pp : Str -> Str = \s -> "<"+s+">";
|
||||
|
||||
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} ;
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ flags coding=utf8 ;
|
||||
|
||||
lincat
|
||||
Inflection = {t : Str; s1,s2 : Str} ;
|
||||
Definition = {s : Str} ;
|
||||
Document = {s : Str} ;
|
||||
Tag = {s : Str} ;
|
||||
|
||||
@@ -132,7 +133,12 @@ lin
|
||||
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 ;
|
||||
|
||||
oper
|
||||
|
||||
@@ -5,6 +5,7 @@ in {
|
||||
|
||||
lincat
|
||||
Inflection = {t : Str; s1,s2 : Str} ;
|
||||
Definition = {s : Str} ;
|
||||
Document = {s : Str} ;
|
||||
Tag = {s : Str} ;
|
||||
|
||||
@@ -124,7 +125,12 @@ oper
|
||||
pp : Str -> Str = \s -> "<"+s+">" ;
|
||||
|
||||
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} ;
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ in {
|
||||
|
||||
lincat
|
||||
Inflection = {t : Str; s1,s2 : Str} ;
|
||||
Definition = {s : Str} ;
|
||||
Document = {s : Str} ;
|
||||
Tag = {s : Str} ;
|
||||
|
||||
@@ -140,7 +141,12 @@ lin
|
||||
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 ;
|
||||
|
||||
oper
|
||||
|
||||
@@ -5,6 +5,7 @@ concrete DocumentationEng of Documentation = CatEng ** open
|
||||
|
||||
lincat
|
||||
Inflection = {t : Str; s1,s2 : Str} ;
|
||||
Definition = {s : Str} ;
|
||||
Document = {s : Str} ;
|
||||
Tag = {s : Str} ;
|
||||
|
||||
@@ -178,7 +179,12 @@ oper
|
||||
pp : Str -> Str = \s -> "<"+s+">";
|
||||
|
||||
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} ;
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ in {
|
||||
|
||||
lincat
|
||||
Inflection = {t : Str; s1,s2 : Str} ;
|
||||
Definition = {s : Str} ;
|
||||
Document = {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))
|
||||
)) ;
|
||||
|
||||
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
|
||||
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) ;
|
||||
|
||||
@@ -14,6 +14,7 @@ in {
|
||||
|
||||
lincat
|
||||
Inflection = {t : Str; s1,s2 : Str} ;
|
||||
Definition = {s : Str} ;
|
||||
Document = {s : Str} ;
|
||||
Tag = {s : Str} ;
|
||||
|
||||
@@ -290,7 +291,12 @@ oper
|
||||
) ;
|
||||
|
||||
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) ;
|
||||
|
||||
{- --# notpresent
|
||||
|
||||
@@ -16,6 +16,7 @@ flags coding=utf8 ;
|
||||
|
||||
lincat
|
||||
Inflection = {t : Str; s1,s2 : Str} ;
|
||||
Definition = {s : Str} ;
|
||||
Document = {s : Str} ;
|
||||
Tag = {s : Str} ;
|
||||
|
||||
@@ -132,7 +133,12 @@ lin
|
||||
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 ;
|
||||
|
||||
oper
|
||||
|
||||
@@ -15,6 +15,7 @@ flags coding=utf8 ;
|
||||
|
||||
lincat
|
||||
Inflection = {t : Str; s1,s2 : Str} ;
|
||||
Definition = {s : Str} ;
|
||||
Document = {s : Str} ;
|
||||
Tag = {s : Str} ;
|
||||
|
||||
@@ -144,7 +145,12 @@ lin
|
||||
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 ;
|
||||
|
||||
oper
|
||||
|
||||
@@ -6,6 +6,7 @@ in {
|
||||
|
||||
lincat
|
||||
Inflection = {t : Str; s1,s2 : Str} ;
|
||||
Definition = {s : Str} ;
|
||||
Document = {s : Str} ;
|
||||
Tag = {s : Str} ;
|
||||
|
||||
@@ -120,7 +121,12 @@ 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} ;
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ flags coding=utf8 ;
|
||||
|
||||
lincat
|
||||
Inflection = {t : Str; s1,s2 : Str} ;
|
||||
Definition = {s : Str} ;
|
||||
Document = {s : Str} ;
|
||||
Tag = {s : Str} ;
|
||||
|
||||
@@ -132,7 +133,13 @@ lin
|
||||
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 ;
|
||||
|
||||
oper
|
||||
|
||||
@@ -16,6 +16,7 @@ flags coding=utf8 ;
|
||||
|
||||
lincat
|
||||
Inflection = {t : Str; s1,s2 : Str} ;
|
||||
Definition = {s : Str} ;
|
||||
Document = {s : Str} ;
|
||||
Tag = {s : Str} ;
|
||||
|
||||
@@ -132,6 +133,12 @@ lin
|
||||
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
|
||||
MkTag i = ss i.t ;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ in {
|
||||
flags coding=utf8 ;
|
||||
lincat
|
||||
Inflection = {t : Str; s1,s2 : Str} ;
|
||||
Definition = {s : Str} ;
|
||||
Document = {s : Str} ;
|
||||
Tag = {s : Str} ;
|
||||
|
||||
@@ -178,7 +179,12 @@ lin
|
||||
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} ;
|
||||
|
||||
oper
|
||||
|
||||
@@ -76,22 +76,39 @@ public class SemanticGraphManager implements Closeable {
|
||||
}
|
||||
}
|
||||
|
||||
public Expr getGloss(Expr lemma) {
|
||||
Expr obj = null;
|
||||
public Expr getDefinition(Expr lemma, boolean withExample) {
|
||||
Expr gloss = null;
|
||||
Expr example = null;
|
||||
|
||||
try {
|
||||
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) {
|
||||
// nothing
|
||||
} catch (SGError e) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
return obj;
|
||||
if (gloss == null)
|
||||
return null;
|
||||
else if (example == null)
|
||||
return new Expr("MkDefinition", gloss);
|
||||
else
|
||||
return new Expr("MkDefinitionEx", gloss, example);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,26 +367,31 @@ public class Translator {
|
||||
}
|
||||
|
||||
public String getInflectionTable(String lemma) {
|
||||
Expr lemmaExpr = Expr.readExpr(lemma);
|
||||
Expr gloss = mSGManager.getGloss(lemmaExpr);
|
||||
Expr empty = Expr.readExpr("\"\"");
|
||||
boolean withExample =
|
||||
(getSourceLanguage().getLangCode().equals("en-US") ||
|
||||
getTargetLanguage().getLangCode().equals("en-US"));
|
||||
Expr def =
|
||||
mSGManager.getDefinition(Expr.readExpr(lemma), withExample);
|
||||
|
||||
Concr targetLang = getTargetConcr();
|
||||
String cat = getGrammar().getFunctionType(lemma).getCategory();
|
||||
|
||||
if (targetLang.hasLinearization(lemma) &&
|
||||
targetLang.hasLinearization("Inflection"+cat)) {
|
||||
if (gloss == null)
|
||||
gloss = empty;
|
||||
if (def == null)
|
||||
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 =
|
||||
"<html><head><meta charset=\"UTF-8\"/></head><body>" +
|
||||
targetLang.linearize(e) +
|
||||
"</body>";
|
||||
return html;
|
||||
} else if (gloss != null) {
|
||||
return "<p style=\"font-size:20px\">"+targetLang.linearize(gloss)+"</p>";
|
||||
} else if (def != null) {
|
||||
return targetLang.linearize(def);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user