From cbb538e170c9a7233e2ca438db8560d60fd91609 Mon Sep 17 00:00:00 2001 From: aarne Date: Tue, 18 Mar 2014 13:22:13 +0000 Subject: [PATCH] a darker red in translation app: dictionary lookup for each word, identity if lookup fails --- .../second_person_worst_utterance_bg.xml | 6 ++++ .../layout/second_person_worst_utterance.xml | 12 +++++++ .../ui/android/ConversationView.java | 13 +++++-- .../ui/android/Translator.java | 36 +++++++++++++++++-- 4 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 src/ui/android/res/drawable/second_person_worst_utterance_bg.xml create mode 100644 src/ui/android/res/layout/second_person_worst_utterance.xml diff --git a/src/ui/android/res/drawable/second_person_worst_utterance_bg.xml b/src/ui/android/res/drawable/second_person_worst_utterance_bg.xml new file mode 100644 index 000000000..f4effe3bc --- /dev/null +++ b/src/ui/android/res/drawable/second_person_worst_utterance_bg.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/src/ui/android/res/layout/second_person_worst_utterance.xml b/src/ui/android/res/layout/second_person_worst_utterance.xml new file mode 100644 index 000000000..12d33a24d --- /dev/null +++ b/src/ui/android/res/layout/second_person_worst_utterance.xml @@ -0,0 +1,12 @@ + + diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/ConversationView.java b/src/ui/android/src/org/grammaticalframework/ui/android/ConversationView.java index 96bcbabb9..2e848ef9d 100644 --- a/src/ui/android/src/org/grammaticalframework/ui/android/ConversationView.java +++ b/src/ui/android/src/org/grammaticalframework/ui/android/ConversationView.java @@ -96,9 +96,16 @@ public class ConversationView extends ScrollView { public CharSequence addSecondPersonUtterance(CharSequence text) { - // parse by chunks, marked by *, red colour TextView view ; - if (text.charAt(0) == '*') { + + // parse by words, marked by %, darkest red colour + if (text.charAt(0) == '%') { + view = (TextView) + mInflater.inflate(R.layout.second_person_worst_utterance, mContent, false) ; + text = text.subSequence(2, text.length()) ; + } + // 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()) ; @@ -106,7 +113,7 @@ public class ConversationView extends ScrollView { // 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_chunk_utterance, mContent, false) ; + mInflater.inflate(R.layout.second_person_worst_utterance, mContent, false) ; } // parse by domain grammar, marked by +, green colour else if (text.charAt(0) == '+') { diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/Translator.java b/src/ui/android/src/org/grammaticalframework/ui/android/Translator.java index 5e4a5a7cb..f540371f6 100644 --- a/src/ui/android/src/org/grammaticalframework/ui/android/Translator.java +++ b/src/ui/android/src/org/grammaticalframework/ui/android/Translator.java @@ -264,6 +264,36 @@ public class Translator { } return out; } + + public String translateWord(String input) { + + List morphos = lookupMorpho(input) ; + + String output = "[" + input + "]" ; + + Concr targetLang = getTargetConcr(); + + for (MorphoAnalysis ana : morphos) { + if (targetLang.hasLinearization(ana.getLemma())) { + output = targetLang.linearize(Expr.readExpr(ana.getLemma())) ; + break ; + } + } + return output ; + } + + public String parseByLookup(String input) { + String[] words = input.split(" ") ; + + String output = "%" ; + + for (String w : words) { + output = output + " " + translateWord(w) ; + } + + return output ; + } + /** * Takes a lot of time. Must not be called on the main thread. */ @@ -280,8 +310,10 @@ public class Translator { String output = targetLang.linearize(expr); return output; } catch (ParseError e) { - Log.e(TAG, "Parse error: " + e); //lookupMorpho - return "parse error: " + e.getMessage(); + // Log.e(TAG, "Parse error: " + e); //lookupMorpho + // return "parse error: " + e.getMessage(); + String output = parseByLookup(input) ; + return output ; } }