mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-26 03:08:55 -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) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user