summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authoraarne <aarne@chalmers.se>2014-03-18 13:22:13 +0000
committeraarne <aarne@chalmers.se>2014-03-18 13:22:13 +0000
commitcbb538e170c9a7233e2ca438db8560d60fd91609 (patch)
treec44f9791764c8356553d7ce8c60311de10646995 /src/ui
parentb4a6e047e3642322a6d0ec47fb6dec1b7bfc9501 (diff)
a darker red in translation app: dictionary lookup for each word, identity if lookup fails
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/android/res/drawable/second_person_worst_utterance_bg.xml6
-rw-r--r--src/ui/android/res/layout/second_person_worst_utterance.xml12
-rw-r--r--src/ui/android/src/org/grammaticalframework/ui/android/ConversationView.java13
-rw-r--r--src/ui/android/src/org/grammaticalframework/ui/android/Translator.java36
4 files changed, 62 insertions, 5 deletions
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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <corners android:radius="4dp" />
+ <solid android:color="#FF303e" />
+</shape> \ 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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<TextView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:layout_marginBottom="16dp"
+ android:layout_marginLeft="32dp"
+ android:layout_gravity="right"
+ android:padding="8dp"
+ android:textSize="20sp"
+ android:background="@drawable/second_person_worst_utterance_bg"
+ />
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<MorphoAnalysis> 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 ;
}
}