-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #300 from angrezichatterbox/feature/data-contract-…
…based-suggestion Implement Data Contract-Based Noun Suggestion with Plural and Gender Handling
- Loading branch information
Showing
23 changed files
with
652 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,48 @@ | ||
{ | ||
"numbers": { "singular": "plural" }, | ||
"genders": { | ||
"canonical": [], | ||
"feminines": [], | ||
"masculines": [], | ||
"commons": [], | ||
"neuters": [] | ||
"genders": { | ||
"canonical": ["NOT_INCLUDED"], | ||
"feminines": ["NOT_INCLUDED"], | ||
"masculines": ["NOT_INCLUDED"], | ||
"commons": ["NOT_INCLUDED"], | ||
"neuters": ["NOT_INCLUDED"] | ||
}, | ||
"conjugations": { | ||
"1": { | ||
"title": "", | ||
"1": "", | ||
"2": "", | ||
"3": "", | ||
"4": "", | ||
"5": "", | ||
"6": "" | ||
"title": "Present", | ||
"1": { "I": "simplePresent" }, | ||
"2": { "you": "simplePresent" }, | ||
"3": { "he/she/it": "simplePresentThirdPersonSingular" }, | ||
"4": { "we": "simplePresent" }, | ||
"5": { "you all": "simplePresent" }, | ||
"6": { "they": "simplePresent" } | ||
}, | ||
"2": { | ||
"title": "Past", | ||
"1": { "I": "simplePast" }, | ||
"2": { "you": "simplePast" }, | ||
"3": { "he/she/it": "simplePast" }, | ||
"4": { "we": "simplePast" }, | ||
"5": { "you all": "simplePast" }, | ||
"6": { "they": "simplePast" } | ||
}, | ||
"3": { | ||
"title": "Perfect", | ||
"1": { "I": "presentParticiple simplePast" }, | ||
"2": { "you": "presentParticiple simplePast" }, | ||
"3": { "he/she/it": "presentParticiple simplePast" }, | ||
"4": { "we": "presentParticiple simplePast" }, | ||
"5": { "you all": "presentParticiple simplePast" }, | ||
"6": { "they": "presentParticiple simplePast" } | ||
}, | ||
"4": { | ||
"title": "Past Perfect", | ||
"1": { "I": "pastParticiple simplePast" }, | ||
"2": { "you": "pastParticiple simplePast" }, | ||
"3": { "he/she/it": "pastParticiple simplePast" }, | ||
"4": { "we": "pastParticiple simplePast" }, | ||
"5": { "you all": "pastParticiple simplePast" }, | ||
"6": { "they": "pastParticiple simplePast" } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package be.scri.helpers | ||
|
||
import android.content.Context | ||
import android.util.Log | ||
import java.io.FileOutputStream | ||
|
||
class DatabaseFileManager( | ||
private val context: Context, | ||
) { | ||
fun loadDatabaseFile(language: String) { | ||
val databaseName = "${language}LanguageData.sqlite" | ||
val dbFile = context.getDatabasePath(databaseName) | ||
Log.i("ALPHA", "Loaded Database") | ||
|
||
if (!dbFile.exists()) { | ||
context.assets.open("data/$databaseName").use { inputStream -> | ||
FileOutputStream(dbFile).use { outputStream -> | ||
inputStream.copyTo(outputStream) | ||
outputStream.flush() | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package be.scri.helpers | ||
|
||
import ContractDataLoader | ||
import EmojiDataManager | ||
import GenderDataManager | ||
import PluralFormsManager | ||
import android.content.Context | ||
|
||
class DatabaseManagers( | ||
context: Context, | ||
) { | ||
val fileManager = DatabaseFileManager(context) | ||
val contractLoader = ContractDataLoader(context) | ||
val emojiManager = EmojiDataManager(context) | ||
val genderManager = GenderDataManager(context) | ||
val pluralManager = PluralFormsManager(context) | ||
} |
28 changes: 28 additions & 0 deletions
28
app/src/main/java/be/scri/helpers/KeyboardDBHelper/ContractDataLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
import android.content.Context | ||
import android.util.Log | ||
import kotlinx.serialization.json.Json | ||
import java.io.IOException | ||
|
||
class ContractDataLoader( | ||
private val context: Context, | ||
) { | ||
fun loadContract(language: String): DataContract? { | ||
val contractName = "${language.lowercase()}.json" | ||
Log.i("ALPHA", "This is the $language") | ||
|
||
return try { | ||
val json = Json { ignoreUnknownKeys = true } | ||
context.assets.open("data-contracts/$contractName").use { contractFile -> | ||
val content = contractFile.bufferedReader().readText() | ||
Log.i("ALPHA", content) | ||
json.decodeFromString<DataContract>(content).also { | ||
Log.i("MY-TAG", it.toString()) | ||
} | ||
} | ||
} catch (e: IOException) { | ||
Log.e("MY-TAG", "Error loading contract: $contractName", e) | ||
null | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
app/src/main/java/be/scri/helpers/KeyboardDBHelper/EmojiDataManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
|
||
import android.content.Context | ||
import android.database.Cursor | ||
import android.database.sqlite.SQLiteDatabase | ||
|
||
class EmojiDataManager( | ||
private val context: Context, | ||
) { | ||
fun getEmojiKeywords(language: String): HashMap<String, MutableList<String>> { | ||
val dbFile = context.getDatabasePath("${language}LanguageData.sqlite") | ||
return processEmojiKeywords(dbFile.path) | ||
} | ||
|
||
private fun processEmojiKeywords(dbPath: String): HashMap<String, MutableList<String>> { | ||
val hashMap = HashMap<String, MutableList<String>>() | ||
val db = SQLiteDatabase.openDatabase(dbPath, null, SQLiteDatabase.OPEN_READONLY) | ||
|
||
db.use { database -> | ||
database.rawQuery("SELECT * FROM emoji_keywords", null).use { cursor -> | ||
processEmojiCursor(cursor, hashMap) | ||
} | ||
} | ||
return hashMap | ||
} | ||
|
||
private fun processEmojiCursor( | ||
cursor: Cursor, | ||
hashMap: HashMap<String, MutableList<String>>, | ||
) { | ||
if (!cursor.moveToFirst()) return | ||
|
||
do { | ||
val key = cursor.getString(0) | ||
hashMap[key] = getEmojiKeyMaps(cursor) | ||
} while (cursor.moveToNext()) | ||
} | ||
|
||
private fun getEmojiKeyMaps(cursor: Cursor): MutableList<String> = | ||
MutableList(cursor.columnCount - 1) { index -> | ||
cursor.getString(index + 1) | ||
} | ||
} |
Oops, something went wrong.