forked from GitHub/gf-core
a darker red in translation app: dictionary lookup for each word, identity if lookup fails
This commit is contained in:
@@ -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>
|
||||
12
src/ui/android/res/layout/second_person_worst_utterance.xml
Normal file
12
src/ui/android/res/layout/second_person_worst_utterance.xml
Normal file
@@ -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"
|
||||
/>
|
||||
@@ -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) == '+') {
|
||||
|
||||
@@ -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 ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user