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:
@@ -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