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 279fdb74b7
commit 105db47ee4
2 changed files with 37 additions and 15 deletions

View File

@@ -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);
}
}

View File

@@ -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;
}