mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-09 04:59:31 -06:00
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) ;
|
||||
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
|
||||
else if (text.charAt(0) == '*') {
|
||||
view = (TextView)
|
||||
mInflater.inflate(R.layout.second_person_chunk_utterance, mContent, false) ;
|
||||
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
|
||||
else if (text.charAt(0) == '+') {
|
||||
view = (TextView)
|
||||
|
||||
@@ -267,19 +267,30 @@ public class Translator {
|
||||
|
||||
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) {
|
||||
if (targetLang.hasLinearization(ana.getLemma())) {
|
||||
output = targetLang.linearize(Expr.readExpr(ana.getLemma())) ;
|
||||
break ;
|
||||
List<MorphoAnalysis> morphos = lookupMorpho(input) ; // lookup morphological analyses
|
||||
|
||||
morphos.addAll(lookupMorpho(lowerinput)) ; // including the analyses of the lower-cased word
|
||||
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user