1
0
forked from GitHub/gf-core

android: added (1) dg icon (2) green/yellow/red colours for translation confidence (3) App grammars as test case in Translator.java

This commit is contained in:
aarne
2014-03-10 18:04:43 +00:00
parent 96087ea21d
commit 556bfa002b
14 changed files with 77 additions and 17 deletions

View File

@@ -13,7 +13,7 @@
<application <application
android:allowBackup="true" android:allowBackup="true"
android:icon="@drawable/ic_launcher" android:icon="@drawable/dg_short"
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/AppTheme" android:name="GFTranslator"> android:theme="@style/AppTheme" android:name="GFTranslator">
<activity <activity

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@@ -2,5 +2,5 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android" <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"> android:shape="rectangle">
<corners android:radius="4dp" /> <corners android:radius="4dp" />
<solid android:color="#75CD75" /> <solid android:color="#CDCDED" />
</shape> </shape>

View File

@@ -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="#75CD75" />
</shape>

View File

@@ -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="#FFB2A5" />
</shape>

View File

@@ -2,5 +2,5 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android" <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"> android:shape="rectangle">
<corners android:radius="4dp" /> <corners android:radius="4dp" />
<solid android:color="#7575CD" /> <solid android:color="#FFFF99" />
</shape> </shape>

View 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_best_utterance_bg"
/>

View 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_chunk_utterance_bg"
/>

View File

@@ -94,9 +94,31 @@ public class ConversationView extends ScrollView {
}); });
} }
public void addSecondPersonUtterance(CharSequence text) { public CharSequence addSecondPersonUtterance(CharSequence text) {
TextView view = (TextView)
mInflater.inflate(R.layout.second_person_utterance, mContent, false); // parse by chunks, marked by *, red colour
TextView view ;
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_chunk_utterance, mContent, false) ;
}
// parse by domain grammar, marked by +, green colour
else if (text.charAt(0) == '+') {
view = (TextView)
mInflater.inflate(R.layout.second_person_best_utterance, mContent, false) ;
text = text.subSequence(2, text.length()) ;
}
// parse by resource grammar, no mark, yellow colour
else
view = (TextView)
mInflater.inflate(R.layout.second_person_utterance, mContent, false);
view.setText(text); view.setText(text);
mContent.addView(view); mContent.addView(view);
post(new Runnable() { post(new Runnable() {
@@ -104,6 +126,7 @@ public class ConversationView extends ScrollView {
fullScroll(FOCUS_DOWN); fullScroll(FOCUS_DOWN);
} }
}); });
return text ;
} }
public void updateLastUtterance(CharSequence text, Object lexicon) { public void updateLastUtterance(CharSequence text, Object lexicon) {

View File

@@ -280,8 +280,8 @@ public class MainActivity extends Activity {
private void outputText(String text) { private void outputText(String text) {
if (DBG) Log.d(TAG, "Speaking: " + text); if (DBG) Log.d(TAG, "Speaking: " + text);
mConversationView.addSecondPersonUtterance(text); CharSequence text2 = mConversationView.addSecondPersonUtterance(text);
mTts.speak(getTargetLanguageCode(), text); mTts.speak(getTargetLanguageCode(), text2.toString());
} }
private class SpeechInputListener implements ASR.Listener { private class SpeechInputListener implements ASR.Listener {

View File

@@ -29,7 +29,7 @@ public class Translator {
private static final String TAG = "Translator"; private static final String TAG = "Translator";
// /* /*
// old // old
@@ -47,22 +47,22 @@ public class Translator {
new Language("sv-SE", "Swedish", "ParseSwe", R.xml.qwerty), new Language("sv-SE", "Swedish", "ParseSwe", R.xml.qwerty),
new Language("fi-FI", "Finnish", "ParseFin", R.xml.qwerty), new Language("fi-FI", "Finnish", "ParseFin", R.xml.qwerty),
}; };
// */ */
/* // /*
// new // new
// TODO: allow changing // TODO: allow changing
private String mGrammar = "TransEngFinSwe.pgf"; private String mGrammar = "App.pgf" ;
// TODO: build dynamically? // TODO: build dynamically?
private Language[] mLanguages = { private Language[] mLanguages = {
new Language("en-US", "English", "NDTransEng", R.xml.qwerty), new Language("en-US", "English", "AppEng", R.xml.qwerty),
// new Language("cmn-Hans-CN", "Chinese", "ParseChi", R.xml.qwerty), new Language("cmn-Hans-CN", "Chinese", "AppChi", R.xml.qwerty),
new Language("sv-SE", "Swedish", "NDTransSwe", R.xml.qwerty), new Language("sv-SE", "Swedish", "AppSwe", R.xml.qwerty),
new Language("fi-FI", "Finnish", "NDTransFin", R.xml.qwerty), new Language("fi-FI", "Finnish", "AppFin", R.xml.qwerty),
}; };
*/ // */
private Context mContext; private Context mContext;
@@ -318,6 +318,7 @@ public class Translator {
} }
public List<MorphoAnalysis> lookupMorpho(String sentence) { public List<MorphoAnalysis> lookupMorpho(String sentence) {
Log.e(TAG, "lookupMorpho " + getSourceConcr());
return getSourceConcr().lookupMorpho(sentence); return getSourceConcr().lookupMorpho(sentence);
} }