mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
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:
@@ -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
|
||||||
|
|||||||
BIN
src/ui/android/res/drawable-hdpi/dg_short.png
Normal file
BIN
src/ui/android/res/drawable-hdpi/dg_short.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.7 KiB |
BIN
src/ui/android/res/drawable-mdpi/dg_short.png
Normal file
BIN
src/ui/android/res/drawable-mdpi/dg_short.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.7 KiB |
BIN
src/ui/android/res/drawable-xhdpi/dg_short.png
Normal file
BIN
src/ui/android/res/drawable-xhdpi/dg_short.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.7 KiB |
BIN
src/ui/android/res/drawable-xxhdpi/dg_short.png
Normal file
BIN
src/ui/android/res/drawable-xxhdpi/dg_short.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.7 KiB |
@@ -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>
|
||||||
@@ -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>
|
||||||
@@ -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>
|
||||||
@@ -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>
|
||||||
12
src/ui/android/res/layout/second_person_best_utterance.xml
Normal file
12
src/ui/android/res/layout/second_person_best_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_best_utterance_bg"
|
||||||
|
/>
|
||||||
12
src/ui/android/res/layout/second_person_chunk_utterance.xml
Normal file
12
src/ui/android/res/layout/second_person_chunk_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_chunk_utterance_bg"
|
||||||
|
/>
|
||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user