forked from GitHub/gf-core
use chunking before morpho lookup in backup parsing ; show results with unknown linearizations in darkest red
This commit is contained in:
@@ -104,17 +104,20 @@ public class ConversationView extends ScrollView {
|
|||||||
mInflater.inflate(R.layout.second_person_worst_utterance, mContent, false) ;
|
mInflater.inflate(R.layout.second_person_worst_utterance, mContent, false) ;
|
||||||
text = text.subSequence(2, text.length()) ;
|
text = text.subSequence(2, text.length()) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parse error or unknown translations (in []) present, darkest red colour
|
||||||
|
else if (text.toString().contains("parse error:") || text.toString().contains("[")) {
|
||||||
|
view = (TextView)
|
||||||
|
mInflater.inflate(R.layout.second_person_worst_utterance, mContent, false) ;
|
||||||
|
}
|
||||||
|
|
||||||
// parse by chunks, marked by *, red colour
|
// parse by chunks, marked by *, red colour
|
||||||
else if (text.charAt(0) == '*') {
|
else if (text.charAt(0) == '*') {
|
||||||
view = (TextView)
|
view = (TextView)
|
||||||
mInflater.inflate(R.layout.second_person_chunk_utterance, mContent, false) ;
|
mInflater.inflate(R.layout.second_person_chunk_utterance, mContent, false) ;
|
||||||
text = text.subSequence(2, text.length()) ;
|
text = text.subSequence(2, text.length()) ;
|
||||||
}
|
}
|
||||||
// parse error or unknown translations (in []) present, red colour
|
|
||||||
else if (text.toString().contains("parse error:") || text.toString().contains("[")) {
|
|
||||||
view = (TextView)
|
|
||||||
mInflater.inflate(R.layout.second_person_worst_utterance, mContent, false) ;
|
|
||||||
}
|
|
||||||
// parse by domain grammar, marked by +, green colour
|
// parse by domain grammar, marked by +, green colour
|
||||||
else if (text.charAt(0) == '+') {
|
else if (text.charAt(0) == '+') {
|
||||||
view = (TextView)
|
view = (TextView)
|
||||||
|
|||||||
@@ -267,19 +267,30 @@ public class Translator {
|
|||||||
|
|
||||||
public String translateWord(String input) {
|
public String translateWord(String input) {
|
||||||
|
|
||||||
List<MorphoAnalysis> morphos = lookupMorpho(input) ;
|
String output = "[" + input + "]" ; // if all else fails, return the word itself in brackets
|
||||||
|
Concr sourceLang = getSourceConcr() ;
|
||||||
|
Concr targetLang = getTargetConcr() ;
|
||||||
|
|
||||||
String output = "[" + input + "]" ;
|
String lowerinput = input.toLowerCase() ; // also consider lower-cased versions of the word
|
||||||
|
|
||||||
Concr targetLang = getTargetConcr();
|
try {
|
||||||
|
Expr expr = sourceLang.parseBest("Chunk", input) ; // try parse as chunk
|
||||||
|
output = targetLang.linearize(expr);
|
||||||
|
return output ;
|
||||||
|
} catch (ParseError e) { // if this fails
|
||||||
|
|
||||||
for (MorphoAnalysis ana : morphos) {
|
List<MorphoAnalysis> morphos = lookupMorpho(input) ; // lookup morphological analyses
|
||||||
if (targetLang.hasLinearization(ana.getLemma())) {
|
|
||||||
output = targetLang.linearize(Expr.readExpr(ana.getLemma())) ;
|
morphos.addAll(lookupMorpho(lowerinput)) ; // including the analyses of the lower-cased word
|
||||||
break ;
|
|
||||||
|
for (MorphoAnalysis ana : morphos) {
|
||||||
|
if (targetLang.hasLinearization(ana.getLemma())) { // check that the word has linearization in target
|
||||||
|
output = targetLang.linearize(Expr.readExpr(ana.getLemma())) ;
|
||||||
|
break ; // if yes, don't search any more
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return output ;
|
return output ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String parseByLookup(String input) {
|
public String parseByLookup(String input) {
|
||||||
|
|||||||
Reference in New Issue
Block a user