Skip to content

Implement Conjugate for Swedish and Russian #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/src/main/assets/data-contracts/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
},
"conjugations": {
"1": {
"title": "Aktiv (Active Voice)",
"title": "Aktiv",
"conjugationTypes": {
"1": {
"title": "Active Forms",
"title": "Aktiv",
"conjugationForms": {
"infinitiv": "activeInfinitive",
"imperativ": "imperative",
Expand All @@ -27,10 +27,10 @@
}
},
"2": {
"title": "Passiv (Passive Voice)",
"title": "Passiv",
"conjugationTypes": {
"1": {
"title": "Passive Forms",
"title": "Passiv",
"conjugationForms": {
"infinitiv": "passiveInfinitive",
"presens": "passivePresent",
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/be/scri/helpers/KeyHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,9 @@ class KeyHandler(
val sharedPreferences = context.getSharedPreferences("keyboard_preferences", Context.MODE_PRIVATE)
val editor = sharedPreferences.edit()
var currentValue = sharedPreferences.getInt("conjugate_index", 0)

if (code == KeyboardBase.DISPLAY_LEFT) {
if (code == KeyboardBase.DISPLAY_RIGHT) {
currentValue--
} else if (code == KeyboardBase.DISPLAY_RIGHT) {
} else if (code == KeyboardBase.DISPLAY_LEFT) {
currentValue++
}

Expand Down
31 changes: 27 additions & 4 deletions app/src/main/java/be/scri/helpers/data/ConjugateDataManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class ConjugateDataManager(
if (form.isNullOrEmpty()) return ""
return fileManager.getLanguageDatabase(language)?.use { db ->
getVerbCursor(db, word, language)?.use { cursor ->
getConjugatedValueFromCursor(cursor, form)
getConjugatedValueFromCursor(cursor, form, language)
}
} ?: ""
}
Expand All @@ -99,9 +99,10 @@ class ConjugateDataManager(
private fun getConjugatedValueFromCursor(
cursor: Cursor,
form: String,
language: String,
): String =
if (form.contains("[")) {
parseComplexForm(cursor, form)
parseComplexForm(cursor, form, language)
} else {
try {
cursor.getString(cursor.getColumnIndexOrThrow(form))
Expand All @@ -123,17 +124,39 @@ class ConjugateDataManager(
private fun parseComplexForm(
cursor: Cursor,
form: String,
language: String,
): String {
val bracketRegex = Regex("""\[(.*?)]""")
val match = bracketRegex.find(form) ?: return ""

val auxiliaryWords = match.groupValues[1]
val dbColumnName = form.replace(bracketRegex, "").trim()

return try {
val verbPart = cursor.getString(cursor.getColumnIndexOrThrow(dbColumnName))
"$auxiliaryWords $verbPart".trim()
val words = auxiliaryWords.split(Regex("\\s+"))
val verbType = cursor.getString(cursor.getColumnIndexOrThrow(words.last()))
val db = fileManager.getLanguageDatabase(language = language)

val wordPart1 = words.firstOrNull()
var auxResult = ""
wordPart1?.let {
val auxCursor =
db?.rawQuery(
"SELECT $wordPart1 FROM verbs WHERE wdLexemeId = ?",
arrayOf(verbType),
)
if (auxCursor?.moveToFirst() == true) {
auxResult = auxCursor.getString(0)
}
auxCursor?.close()
}

val result = "$auxResult $verbPart".trim()
Log.d("DEBUG", "Returning: $result")
result
} catch (e: IllegalArgumentException) {
Log.e("ConjugateDataManager", "Complex form column '$dbColumnName' not found", e)
Log.e("ConjugateDataManager", "Column '$dbColumnName' not found", e)
""
}
}
Expand Down
37 changes: 26 additions & 11 deletions app/src/main/java/be/scri/services/GeneralKeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import android.text.InputType.TYPE_CLASS_NUMBER
import android.text.InputType.TYPE_CLASS_PHONE
import android.text.InputType.TYPE_MASK_CLASS
import android.text.TextUtils
import android.util.Log
import android.view.KeyEvent
import android.view.View
import android.view.inputmethod.EditorInfo
Expand Down Expand Up @@ -329,8 +330,8 @@ abstract class GeneralKeyboardIME(
pluralWords = dbManagers.pluralManager.getAllPluralForms(languageAlias, dataContract)?.toSet()
nounKeywords = dbManagers.genderManager.findGenderOfWord(languageAlias, dataContract)
caseAnnotation = dbManagers.prepositionManager.getCaseAnnotations(languageAlias)
conjugateOutput = dbManagers.conjugateDataManager.getTheConjugateLabels(languageAlias, dataContract, "describe")
conjugateLabels = dbManagers.conjugateDataManager.extractConjugateHeadings(dataContract, "describe")
conjugateOutput = dbManagers.conjugateDataManager.getTheConjugateLabels(languageAlias, dataContract, "coacha")
conjugateLabels = dbManagers.conjugateDataManager.extractConjugateHeadings(dataContract, "coacha")
keyboard = KeyboardBase(this, keyboardXml, enterKeyType)
keyboardView?.setKeyboard(keyboard!!)
}
Expand Down Expand Up @@ -746,6 +747,7 @@ abstract class GeneralKeyboardIME(
return
}

Log.i("HELLO", "The output from the languageOutput is $languageOutput")
if (language != "English") {
setUpNonEnglishConjugateKeys(languageOutput, conjugateLabels.toList(), title)
} else {
Expand All @@ -769,17 +771,30 @@ abstract class GeneralKeyboardIME(
title: String,
) {
val keyCodes =
listOf(
KeyboardBase.CODE_FPS,
KeyboardBase.CODE_FPP,
KeyboardBase.CODE_SPS,
KeyboardBase.CODE_SPP,
KeyboardBase.CODE_TPS,
KeyboardBase.CODE_TPP,
)
when (language) {
"Swedish" -> {
listOf(
KeyboardBase.CODE_TR,
KeyboardBase.CODE_TL,
KeyboardBase.CODE_BR,
KeyboardBase.CODE_BL,
)
}

else -> {
listOf(
KeyboardBase.CODE_FPS,
KeyboardBase.CODE_FPP,
KeyboardBase.CODE_SPS,
KeyboardBase.CODE_SPP,
KeyboardBase.CODE_TPS,
KeyboardBase.CODE_TPP,
)
}
}

keyCodes.forEachIndexed { index, code ->
val value = languageOutput[title]?.elementAtOrNull(index) ?: return@forEachIndexed
val value = languageOutput[title]?.elementAtOrNull(index) ?: ""
keyboardView?.setKeyLabel(value, conjugateLabel.getOrNull(index) ?: "", code)
}
}
Expand Down
Loading