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) { 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); TripleResult res = mDB.queryTriple(lemma, Expr.readExpr("gloss"), null);
if (res.hasNext()) { if (res.hasNext()) {
obj = res.getObject(); gloss = res.getObject();
} }
res.close(); res.close();
}
if (withExample) {
TripleResult res = mDB.queryTriple(lemma, Expr.readExpr("example"), null);
if (res.hasNext()) {
example = res.getObject();
}
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;
} }