Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
yotta
/
pictogram
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
60
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d87d1ca8
authored
May 19, 2016
by
Fernando Martínez Santiago
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
working on GF integration (ii)
parent
63444b40
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
142 deletions
android/Pictogram/app/build.gradle
android/Pictogram/app/src/fernandoFlavor/java/com/yottacode/pictogrammar/Language.java
android/Pictogram/app/src/fernandoFlavor/java/com/yottacode/pictogrammar/Translate.java
android/Pictogram/app/src/fernandoFlavor/res/xml/qwerty.xml
android/Pictogram/app/build.gradle
View file @
d87d1ca8
...
...
@@ -38,15 +38,13 @@ android {
resValue
"integer"
,
"rows"
,
"5"
resValue
"integer"
,
"columns"
,
"10"
}
}
productFlavors
{
F
ernandoFlavor
{
f
ernandoFlavor
{
resValue
"string"
,
"server"
,
"https://pre.yottacode.com"
applicationId
"com.yottacode.pictogrammar"
dependencies
{
compile
fileTree
(
dir:
'libs'
,
include:
[
'*.jar'
])
}
}
ArturoFlavor
{
resValue
"string"
,
"server"
,
"https://192.168.1.37:1337"
}
...
...
@@ -58,15 +56,19 @@ android {
resValue
"string"
,
"server"
,
"http://192.168.1.37:1337"
}
}
}
dependencies
{
compile
fileTree
(
dir:
'libs'
,
include:
[
'*.jar'
]
)
compile
fileTree
(
include:
[
'*.jar'
],
dir:
'libs'
)
compile
'com.google.android.gms:play-services:6.5.87'
compile
'com.android.support:appcompat-v7:21.0.3'
compile
'com.github.nkzawa:socket.io-client:0.5.0'
compile
'com.koushikdutta.async:androidasync:2.+'
compile
'com.android.support:support-v4:21.0.+'
compile
'com.koushikdutta.ion:ion:2.+'
//required for upload images
compile
'com.koushikdutta.ion:ion:2.+'
//required for upload images
fernandoFlavorCompile
files
(
'src/fernandoFlavor/libs/jpgf.jar'
)
fernandoFlavorCompile
fileTree
(
dir:
'libs'
)
}
android/Pictogram/app/src/fernandoFlavor/java/com/yottacode/pictogrammar/Language.java
View file @
d87d1ca8
...
...
@@ -8,27 +8,16 @@ public class Language implements Serializable {
private
final
String
mLangCode
;
private
final
String
mLangName
;
private
final
String
mConcrete
;
private
final
int
mKeyboardPage1Resource
;
private
final
int
mKeyboardPage2Resource
;
public
Language
(
String
langCode
,
String
langName
,
String
concrete
,
int
keyboardResourc
e
)
{
public
Language
(
String
langCode
,
String
langName
,
String
concret
e
)
{
mLangCode
=
langCode
;
mLangName
=
langName
;
mConcrete
=
concrete
;
mKeyboardPage1Resource
=
keyboardResource
;
mKeyboardPage2Resource
=
keyboardResource
;
}
public
Language
(
String
langCode
,
String
langName
,
String
concrete
,
int
keyboardPage1Resource
,
int
keyboardPage2Resource
)
{
mLangCode
=
langCode
;
mLangName
=
langName
;
mConcrete
=
concrete
;
mKeyboardPage1Resource
=
keyboardPage1Resource
;
mKeyboardPage2Resource
=
keyboardPage2Resource
;
}
public
String
getLangCode
()
{
return
mLangCode
;
}
...
...
@@ -37,13 +26,6 @@ public class Language implements Serializable {
return
mLangName
;
}
public
int
getKeyboardPage1Resource
()
{
return
mKeyboardPage1Resource
;
}
public
int
getKeyboardPage2Resource
()
{
return
mKeyboardPage2Resource
;
}
String
getConcrete
()
{
return
mConcrete
;
...
...
android/Pictogram/app/src/fernandoFlavor/java/com/yottacode/pictogrammar/Translate.java
View file @
d87d1ca8
...
...
@@ -16,9 +16,11 @@ package com.yottacode.pictogrammar;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.Map
;
import
org.grammaticalframework.sg.*
;
import
org.grammaticalframework.sg.SG
;
import
org.grammaticalframework.pgf.*
;
import
com.yottacode.pictogram.tts.TTSHelper
;
...
...
@@ -34,14 +36,11 @@ public class Translate extends Activity
private
ConcrLoader
mSourceLoader
;
private
ConcrLoader
mTargetLoader
;
private
ConcrLoader
mOtherLoader
;
private
String
mGrammar
=
"
supo
.pgf"
;
private
String
mGrammar
=
"
SUpO
.pgf"
;
// String constant for logs
private
final
String
TAG
=
this
.
getClass
().
getSimpleName
();
// Or .getCanonicalName()
// String constan for token
private
final
String
TOKEN
=
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJvZmZpY2UiOnsiaWQiOjM4MywibmFtZSI6IkNvbXVuaWNhY2nDs24gQXVtZW50YXRpdmEgSkHDqW4gKENBSkEpIiwiYWRkcmVzcyI6IlBhcmFqZSBMYXMgTGFndW5pbGxhcywgRWQgQTMsIHByaW1lcmEgcGxhdGEsIDIzMDcxLiBKYcOpbiIsImVtYWlsIjoiZG9mZXJAdWphZW4uZXMiLCJwaG9uZTEiOiIrMzQgOTUzIDIxIDI4IDg4IiwicGhvbmUyIjpudWxsLCJsYW5nIjoiZXMtZXMiLCJjb3VudHJ5IjoiRVMiLCJhZG1pbiI6MjMsImNvbnRhY3RQZXJzb24iOiJGZXJuYW5kbyBNYXJ0w61uZXogU2FudGlhZ28iLCJtYXhTdHVkZW50cyI6MiwiY3VycmVudFN0dWRlbnRzIjowfSwiaWQiOjIzLCJuYW1lIjoiRmVybmFuZG8iLCJzdXJuYW1lIjoiTWFydMOtbmV6IFNhbnRpYWdvIiwiZ2VuZGVyIjoiTSIsInBpYyI6Imh0dHA6Ly93d3dkaS51amFlbi5lcy9zaXRlcy9kZWZhdWx0L2ZpbGVzL3lvLmpwZz8xNDQ4MDE5MzU2IiwiYWRkcmVzcyI6bnVsbCwiY291bnRyeSI6bnVsbCwiZW1haWwiOiJkb2ZlckB1amFlbi5lcyIsInBob25lIjoiKzM0OTUzMjEyODg4IiwibGFuZyI6ImVzLWVzIiwiYWN0aXZlIjp0cnVlLCJ0dHNFbmdpbmUiOm51bGwsImlzU3VwQWRtaW4iOnRydWUsImlhdCI6MTQ1Mjg4NjE1NSwiZXhwIjoxNDUyODkzMzU1fQ.dmxKE4qH1DqBM7BYakgwD0L6y1437_2Ba3T7rHnOIcE"
;
/** Called when the activity is first created. */
...
...
@@ -53,8 +52,9 @@ public class Translate extends Activity
mGrammarLoader
=
new
GrammarLoader
();
mGrammarLoader
.
start
();
Language
prefSourceLang
=
new
Language
(
"es-ES"
,
"Spanish"
,
"AppSpa"
,
R
.
xml
.
qwerty
);
Language
prefTargetLang
=
new
Language
(
"en-US"
,
"English"
,
"AppEng"
,
R
.
xml
.
qwerty
);
Language
prefSourceLang
=
new
Language
(
"es-ES"
,
"Spanish"
,
"SUpO-ES"
);
Language
prefTargetLang
=
new
Language
(
"en-US"
,
"English"
,
"SUpO-EN"
);
mSourceLoader
=
new
ConcrLoader
(
prefSourceLang
);
mSourceLoader
.
start
();
...
...
@@ -114,37 +114,7 @@ public class Translate extends Activity
}
/**
* This class is used to load the PGF file asychronously.
* It display a blocking progress dialog while doing so.
*/
private
class
LoadPGFTask
extends
AsyncTask
<
Void
,
Void
,
PGF
>
{
private
ProgressDialog
progress
;
protected
void
onPreExecute
()
{
// Display loading popup
this
.
progress
=
ProgressDialog
.
show
(
Translate
.
this
,
"Translate"
,
"Loading grammar, please wait"
,
true
);
}
protected
PGF
doInBackground
(
Void
...
a
)
{
int
pgf_res
=
R
.
raw
.
supo
;
InputStream
is
=
getResources
().
openRawResource
(
pgf_res
);
try
{
PGF
pgf
=
(
PGF
)
null
;
//PGFBuilder.fromInputStream(is, new String[] {"SUpO_EN","SUpO_ES"});
return
pgf
;
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
protected
void
onPostExecute
(
PGF
result
)
{
mPGF
=
result
;
if
(
this
.
progress
!=
null
)
this
.
progress
.
dismiss
();
// Remove loading popup
}
}
/**
* This class is used to parse a sentence asychronously.
...
...
@@ -188,12 +158,52 @@ public class Translate extends Activity
InputStream
in
=
null
;
try
{
System
.
loadLibrary
(
"jpgf"
);
for
(
String
lo:
getAssets
().
list
(
"."
))
Log
.
i
(
this
.
getClass
().
getSimpleName
(),
"LOCALES:"
+
lo
);
in
=
getAssets
().
open
(
mGrammar
);
Log
.
d
(
TAG
,
"Trying to open "
+
mGrammar
);
Log
.
i
(
TAG
,
"Trying to open "
+
mGrammar
);
long
t1
=
System
.
currentTimeMillis
();
mPGF
=
PGF
.
readPGF
(
in
);
long
t2
=
System
.
currentTimeMillis
();
Log
.
d
(
TAG
,
mGrammar
+
" loaded ("
+(
t2
-
t1
)+
" ms)"
);
Log
.
i
(
TAG
,
mGrammar
+
" loaded ("
+
(
t2
-
t1
)
+
" ms)"
);
// Type typ = mPGF.getFunctionType("Bulgarian");
// System.out.println(typ.getCategory());
System
.
out
.
println
(
mPGF
.
getAbstractName
());
for
(
Map
.
Entry
<
String
,
Concr
>
entry
:
mPGF
.
getLanguages
().
entrySet
())
{
Log
.
i
(
this
.
getClass
().
getSimpleName
(),
entry
.
getKey
()
+
" Language: "
+
entry
.
getValue
().
getName
());
}
Concr
eng
=
mPGF
.
getLanguages
().
get
(
"SUpO_EN"
);
InputStream
is_es
=
in
=
getAssets
().
open
(
"SUpO_ES.gfo"
);
eng
.
unload
();
eng
.
load
(
is_es
);
try
{
int
i
=
0
;
for
(
ExprProb
ep
:
eng
.
parse
(
mPGF
.
getStartCat
(),
"I want chips"
))
{
if
(
i
++>
5
)
break
;
Log
.
i
(
this
.
getClass
().
getSimpleName
(),
"["
+
ep
.
getProb
()
+
"] "
+
ep
.
getExpr
());
}
i
=
0
;
for
(
TokenProb
tk
:
eng
.
complete
(
mPGF
.
getStartCat
(),
""
,
"I want"
))
{
if
(
i
++>
5
)
break
;
Log
.
i
(
this
.
getClass
().
getSimpleName
(),
"Next: "
+
tk
.
getToken
()
+
". Prob. "
+
tk
.
getProb
());
}
}
catch
(
ParseError
e
)
{
Log
.
i
(
this
.
getClass
().
getSimpleName
(),
"Parsing failed at token \""
+
e
.
getToken
()+
"\""
);
}
}
catch
(
FileNotFoundException
e
)
{
Log
.
e
(
TAG
,
"File not found"
,
e
);
}
catch
(
IOException
e
)
{
...
...
@@ -237,7 +247,7 @@ public class Translate extends Activity
InputStream
in
=
null
;
try
{
String
name
=
mLanguage
.
getConcrete
()
+
".pgf_c"
;
String
name
=
mLanguage
.
getConcrete
();
in
=
getAssets
().
open
(
name
);
Log
.
d
(
TAG
,
"Trying to load "
+
name
);
long
t1
=
System
.
currentTimeMillis
();
...
...
android/Pictogram/app/src/fernandoFlavor/res/xml/qwerty.xml
deleted
100644 → 0
View file @
63444b40
<?xml version="1.0" encoding="utf-8"?>
<Keyboard
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:keyWidth=
"10%p"
android:horizontalGap=
"0px"
android:verticalGap=
"0px"
android:keyHeight=
"@dimen/key_height"
>
<Row>
<Key
android:codes=
"113"
android:keyLabel=
"q"
android:keyEdgeFlags=
"left"
/>
<Key
android:codes=
"119"
android:keyLabel=
"w"
/>
<Key
android:codes=
"101"
android:keyLabel=
"e"
android:popupKeyboard=
"@xml/popup_keyboard"
android:popupCharacters=
"èéêěëę"
/>
<Key
android:codes=
"114"
android:keyLabel=
"r"
/>
<Key
android:codes=
"116"
android:keyLabel=
"t"
/>
<Key
android:codes=
"121"
android:keyLabel=
"y"
android:popupKeyboard=
"@xml/popup_keyboard"
android:popupCharacters=
"ỳýÿ"
/>
<Key
android:codes=
"117"
android:keyLabel=
"u"
android:popupKeyboard=
"@xml/popup_keyboard"
android:popupCharacters=
"ùúûǔūü"
/>
<Key
android:codes=
"105"
android:keyLabel=
"i"
android:popupKeyboard=
"@xml/popup_keyboard"
android:popupCharacters=
"ìíîǐï"
/>
<Key
android:codes=
"111"
android:keyLabel=
"o"
android:popupKeyboard=
"@xml/popup_keyboard"
android:popupCharacters=
"òóôõöǫœø"
/>
<Key
android:codes=
"112"
android:keyLabel=
"p"
android:keyEdgeFlags=
"right"
/>
</Row>
<Row>
<Key
android:codes=
"97"
android:keyLabel=
"a"
android:horizontalGap=
"5%p"
android:keyEdgeFlags=
"left"
android:popupKeyboard=
"@xml/popup_keyboard"
android:popupCharacters=
"àáâǎãäåæ"
/>
<Key
android:codes=
"115"
android:keyLabel=
"s"
android:popupKeyboard=
"@xml/popup_keyboard"
android:popupCharacters=
"ŝšß"
/>
<Key
android:codes=
"100"
android:keyLabel=
"d"
android:popupKeyboard=
"@xml/popup_keyboard"
android:popupCharacters=
"đ"
/>
<Key
android:codes=
"102"
android:keyLabel=
"f"
/>
<Key
android:codes=
"103"
android:keyLabel=
"g"
android:popupKeyboard=
"@xml/popup_keyboard"
android:popupCharacters=
"ǵ"
/>
<Key
android:codes=
"104"
android:keyLabel=
"h"
/>
<Key
android:codes=
"106"
android:keyLabel=
"j"
android:popupKeyboard=
"@xml/popup_keyboard"
android:popupCharacters=
"ǰ"
/>
<Key
android:codes=
"107"
android:keyLabel=
"k"
android:popupKeyboard=
"@xml/popup_keyboard"
android:popupCharacters=
"ḱ"
/>
<Key
android:codes=
"108"
android:keyLabel=
"l"
android:keyEdgeFlags=
"right"
/>
</Row>
<Row>
<Key
android:codes=
"-1"
android:keyIcon=
"@drawable/sym_keyboard_shift"
android:keyWidth=
"15%p"
android:isModifier=
"true"
android:isSticky=
"true"
android:keyEdgeFlags=
"left"
/>
<Key
android:codes=
"122"
android:keyLabel=
"z"
android:popupKeyboard=
"@xml/popup_keyboard"
android:popupCharacters=
"ẑž"
/>
<Key
android:codes=
"120"
android:keyLabel=
"x"
/>
<Key
android:codes=
"99"
android:keyLabel=
"c"
android:popupKeyboard=
"@xml/popup_keyboard"
android:popupCharacters=
"ćč"
/>
<Key
android:codes=
"118"
android:keyLabel=
"v"
/>
<Key
android:codes=
"98"
android:keyLabel=
"b"
/>
<Key
android:codes=
"110"
android:keyLabel=
"n"
android:popupKeyboard=
"@xml/popup_keyboard"
android:popupCharacters=
"ńñ"
/>
<Key
android:codes=
"109"
android:keyLabel=
"m"
/>
<Key
android:codes=
"-5"
android:keyIcon=
"@drawable/sym_keyboard_delete"
android:keyWidth=
"15%p"
android:keyEdgeFlags=
"right"
android:isRepeatable=
"true"
/>
</Row>
<Row
android:rowEdgeFlags=
"bottom"
android:keyboardMode=
"@string/normalKeyboardMode"
>
<Key
android:codes=
"-100"
android:keyLabel=
"Sr"
android:keyWidth=
"13%p"
android:keyEdgeFlags=
"left"
/>
<Key
android:codes=
"-200"
android:keyLabel=
"Tr"
android:keyWidth=
"13%p"
/>
<Key
android:codes=
"-2"
android:keyLabel=
"123"
android:keyWidth=
"13%p"
/>
<Key
android:codes=
"32"
android:keyIcon=
"@drawable/sym_keyboard_space"
android:keyWidth=
"29%p"
android:isRepeatable=
"true"
/>
<Key
android:codes=
"46"
android:keyLabel=
"."
android:popupKeyboard=
"@xml/popup_keyboard"
android:popupCharacters=
","
android:keyWidth=
"14%p"
/>
<Key
android:codes=
"10"
android:keyIcon=
"@drawable/sym_keyboard_return"
android:keyWidth=
"19%p"
android:keyEdgeFlags=
"right"
/>
</Row>
<Row
android:rowEdgeFlags=
"bottom"
android:keyboardMode=
"@string/internalKeyboardMode"
>
<Key
android:codes=
"-2"
android:keyLabel=
"123"
android:keyWidth=
"15%p"
android:horizontalGap=
"10%p"
android:keyEdgeFlags=
"left"
/>
<Key
android:codes=
"32"
android:keyIcon=
"@drawable/sym_keyboard_space"
android:keyWidth=
"30%p"
android:isRepeatable=
"true"
/>
<Key
android:codes=
"46"
android:keyLabel=
"."
android:popupKeyboard=
"@xml/popup_keyboard"
android:popupCharacters=
","
android:keyWidth=
"15%p"
/>
<Key
android:codes=
"10"
android:keyIcon=
"@drawable/sym_keyboard_return"
android:keyWidth=
"20%p"
android:keyEdgeFlags=
"right"
/>
</Row>
</Keyboard>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment