Commit 5a6acdc0 by Arturo Montejo Ráez

Merge branch 'develop' of http://scm.ujaen.es/softuno/pictogram into develop

parents b09c68a3 409b1325
Showing with 146 additions and 8 deletions
......@@ -13,7 +13,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="1.7" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
......@@ -14,29 +14,28 @@ android {
versionCode 1
versionName "1.0"
signingConfig signingConfigs.release_config
resValue "string", "db_name", "PCB.db"
resValue "string", "core_vocabulary", "core_vocabulary"
resValue "integer", "rows", "5"
resValue "integer", "columns", "10"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
resValue "string", "server", "https://pre.yottacode.com"
resValue "string", "db_name", "PCB.db"
resValue "bool", "force_db_create", "false"
resValue "bool", "ssl_connect", "false"
resValue "bool", "force_img_download", "false"
resValue "integer", "netservice_timing", "20"
resValue "integer", "rows", "5"
resValue "integer", "columns", "10"
}
debug {
resValue "string", "db_name", "PCB.db"
resValue "string", "server", "https://dev.yottacode.com"
resValue "bool", "force_db_create", "false"
resValue "bool", "ssl_connect", "false"
resValue "bool", "force_img_download", "false"
resValue "integer", "netservice_timing", "20"
resValue "integer", "rows", "5"
resValue "integer", "columns", "10"
}
}
productFlavors {
......
package com.yottacode.pictogram.grammar;
import android.util.Log;
import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.tools.PCBcontext;
import org.grammaticalframework.pgf.Concr;
import org.grammaticalframework.pgf.PGF;
import org.grammaticalframework.pgf.ParseError;
import org.grammaticalframework.pgf.TokenProb;
import java.io.IOException;
import java.io.InputStream;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.Vector;
/**
* Created by Fernando on 01/06/2016.
*/
public class SemanticGrammar {
private PGF pgf;
Concr language;
String current_msg;
Hashtable<String,Integer> exp_cat; //for a given expression, which is the category. It's required for predictive grammar
public SemanticGrammar(String grammar, String language) {
System.loadLibrary("jpgf");
this.exp_cat = new Hashtable<>(Vocabulary.DEFAULT_VOCABULARY_SIZE);
try {
InputStream in = null;
in = PCBcontext.getContext().getAssets().open(grammar);
Log.i(this.getClass().getCanonicalName(), "Trying to open " + grammar);
this.language = this.pgf.getLanguages().get(language);
this.pgf = PGF.readPGF(in);
this.current_msg="";
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* It adds a new expresion with a given cat
*/
public void add_translation(String translation, int cat) {
this.exp_cat.put(translation,cat);
}
/**
* It returns the category for a given expression. It is required to implement the semantic grammar
* @param translation
* @return
*/
public int get_expr_cat(String translation) {
return this.exp_cat.get(translation);
}
public LinkedList<Picto> startSentence() {
this.current_msg="";
return PCBcontext.getVocabulary().pictos.get(Picto.NO_CATEGORY);
}
public LinkedList<Picto> next_categories(String expression) {
LinkedList<Picto> next_cats;
this.current_msg += expression + " ";
try {
Iterable<TokenProb> next_tokens = language.complete(pgf.getStartCat(), this.current_msg, "");
if (!next_tokens.iterator().hasNext())
next_cats = startSentence();
else {
next_cats = new LinkedList<>();
java.util.LinkedList<Picto> categories = PCBcontext.getVocabulary().pictos.get(Picto.NO_CATEGORY);
for (TokenProb tk : next_tokens) {
String translation = tk.getToken();
int cat = get_expr_cat(tk.getToken());
Log.i(this.getClass().getSimpleName(), "Next: " + translation + ". Cat: " + cat);
if (!next_cats.contains(cat)) {
next_cats.add(categories.get(cat));
}
}
}
} catch (ParseError parseError) {
Log.e(this.getClass().getCanonicalName(), "Error parsing " + this.current_msg + ". Error:" + parseError.getMessage() + " (token " + parseError.getToken() + ")");
next_cats = startSentence();
}
return next_cats;
}
}
package com.yottacode.pictogrammar;
import java.io.Serializable;
public class Language implements Serializable {
private static final long serialVersionUID = 1L;
private final String mLangCode;
private final String mLangName;
private final String mConcrete;
public Language(String langCode, String langName, String concrete) {
mLangCode = langCode;
mLangName = langName;
mConcrete = concrete;
}
public String getLangCode() {
return mLangCode;
}
public String getLangName() {
return mLangName;
}
String getConcrete() {
return mConcrete;
}
@Override
public String toString() {
return getLangName();
}
@Override
public boolean equals(Object o) {
Language other = (Language) o;
return mLangCode.equals(other.mLangCode);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment