From 28db383f0956ef3150769755b077f37131b4110d Mon Sep 17 00:00:00 2001 From: Andrew Tavis McAllister Date: Thu, 4 Apr 2024 00:26:46 +0200 Subject: [PATCH] #378 reimplement db manager class across keyboard functionalities --- .../KeyboardViewController.swift | 69 ++---- .../KeyboardsBase/LanguageDBManager.swift | 199 ++++++++++++------ Keyboards/KeyboardsBase/LoadData.swift | 158 -------------- .../ScribeFunctionality/Annotate.swift | 16 +- .../ScribeFunctionality/Conjugate.swift | 20 +- .../ScribeFunctionality/Plural.swift | 5 +- .../ScribeFunctionality/Translate.swift | 6 +- Scribe.xcodeproj/project.pbxproj | 26 --- 8 files changed, 166 insertions(+), 333 deletions(-) delete mode 100644 Keyboards/KeyboardsBase/LoadData.swift diff --git a/Keyboards/KeyboardsBase/KeyboardViewController.swift b/Keyboards/KeyboardsBase/KeyboardViewController.swift index 72dad3fb..6f5e4c87 100644 --- a/Keyboards/KeyboardsBase/KeyboardViewController.swift +++ b/Keyboards/KeyboardsBase/KeyboardViewController.swift @@ -367,10 +367,7 @@ class KeyboardViewController: UIInputViewController { /// - Parameters /// - word: the word for which corresponding emojis should be shown for. func getEmojiAutoSuggestions(for word: String) { - let query = "SELECT * FROM emoji_keywords WHERE word = ?" - let args = [word.lowercased()] - let outputCols = ["emoji_0", "emoji_1", "emoji_2"] - let emojisToDisplay = queryDBRow(query: query, outputCols: outputCols, args: args) + let emojisToDisplay = LanguageDBManager.shared.queryEmojis(of: word.lowercased()) if !emojisToDisplay[0].isEmpty { emojisToDisplayArray = [String]() @@ -448,7 +445,7 @@ class KeyboardViewController: UIInputViewController { } // Get options for completion that start with the current prefix and are not just one letter. - let completionOptions = queryAutocompletions(word: currentPrefix) + let completionOptions = LanguageDBManager.shared.queryAutocompletions(word: currentPrefix) if !completionOptions[0].isEmpty { if completionOptions.count <= 3 { @@ -505,13 +502,12 @@ class KeyboardViewController: UIInputViewController { let prefix = proxy.documentContextBeforeInput?.components(separatedBy: " ").secondToLast() ?? "" completionWords = [String]() - let query = "SELECT * FROM verbs WHERE verb = ?" for i in 0 ..< 3 { // Get conjugations of the preselected verbs. - let args = [verbsAfterPronounsArray[i]] if let tense = pronounAutosuggestionTenses[prefix.lowercased()] { let outputCols = [tense] - var suggestion = queryDBRow(query: query, outputCols: outputCols, args: args)[0] + var suggestion = LanguageDBManager.shared.queryVerb(of: verbsAfterPronounsArray[i], with: outputCols)[0] + if suggestion == "" { suggestion = verbsAfterPronounsArray[i] } @@ -519,6 +515,7 @@ class KeyboardViewController: UIInputViewController { if suggestion == "REFLEXIVE_PRONOUN" && controllerLanguage == "Spanish" { suggestion = getESReflexivePronoun(pronoun: prefix.lowercased()) } + if shiftButtonState == .shift { completionWords.append(suggestion.capitalize()) } else if capsLockButtonState == .locked { @@ -579,13 +576,9 @@ class KeyboardViewController: UIInputViewController { } else { // We have to consider these different cases as the key always has to match. // Else, even if the lowercased prefix is present in the dictionary, if the actual prefix isn't present we won't get an output. - let query = "SELECT * FROM autosuggestions WHERE word = ?" - let argsLower = [prefix.lowercased()] - let argsCapitalize = [prefix.capitalized] - let outputCols = ["suggestion_0", "suggestion_1", "suggestion_2"] + let suggestionsLowerCasePrefix = LanguageDBManager.shared.queryAutosuggestions(of: prefix.lowercased()) + let suggestionsCapitalizedPrefix = LanguageDBManager.shared.queryAutosuggestions(of: prefix.capitalized) - let suggestionsLowerCasePrefix = queryDBRow(query: query, outputCols: outputCols, args: argsLower) - let suggestionsCapitalizedPrefix = queryDBRow(query: query, outputCols: outputCols, args: argsCapitalize) if !suggestionsLowerCasePrefix[0].isEmpty { completionWords = [String]() for i in 0 ..< 3 { @@ -598,12 +591,9 @@ class KeyboardViewController: UIInputViewController { } else if capsLockButtonState == .locked { completionWords.append(suggestionsLowerCasePrefix[i].uppercased()) } else { - let nounGenderQuery = "SELECT * FROM nouns WHERE noun = ?" - let nounGenderArgs = [suggestionsLowerCasePrefix[i]] - let outputCols = ["form"] - - let nounForm = queryDBRow(query: nounGenderQuery, outputCols: outputCols, args: nounGenderArgs)[0] + let nounForm = LanguageDBManager.shared.queryNounForm(of: suggestionsLowerCasePrefix[i])[0] hasNounForm = !nounForm.isEmpty + if !hasNounForm { completionWords.append(suggestionsLowerCasePrefix[i].lowercased()) } else { @@ -618,6 +608,7 @@ class KeyboardViewController: UIInputViewController { completionWords.append(previousWord) continue } + if shiftButtonState == .shift { completionWords.append(suggestionsCapitalizedPrefix[i].capitalize()) } else if capsLockButtonState == .locked { @@ -1496,10 +1487,8 @@ class KeyboardViewController: UIInputViewController { } // Populate conjugation view buttons. - let query = "SELECT * FROM verbs WHERE verb = ?" - let args = [verbToConjugate] let outputCols = allConjugations - let conjugationsToDisplay = queryDBRow(query: query, outputCols: outputCols, args: args) + let conjugationsToDisplay = LanguageDBManager.shared.queryVerb(of: verbToConjugate, with: outputCols) for index in 0 ..< allConjugations.count { if conjugationsToDisplay[index] == "" { // Assign the invalid message if the conjugation isn't present in the directory. @@ -1879,46 +1868,19 @@ class KeyboardViewController: UIInputViewController { // Show the name of the keyboard to the user. showKeyboardLanguage = true - // Initialize the language database and create the autosuggestions lexicon. - languageDB = openDBQueue() - // Add UILexicon words including unpaired first and last names from Contacts to autocompletions. - let addToAutocompleteLexiconQuery = "INSERT OR IGNORE INTO autocomplete_lexicon (word) VALUES (?)" requestSupplementaryLexicon { (userLexicon: UILexicon?) in if let lexicon = userLexicon { for item in lexicon.entries { if item.documentText.count > 1 { - writeDBRow(query: addToAutocompleteLexiconQuery, args: [item.documentText]) + LanguageDBManager.shared.insertAutocompleteLexion(of: item.documentText) } } } } // Drop non-unique values in case the lexicon has added words that were already present. - let dropNonUniqueAutosuggestionsQuery = """ - DELETE FROM autocomplete_lexicon - WHERE rowid NOT IN ( - SELECT - MIN(rowid) - - FROM - autocomplete_lexicon - - GROUP BY - word - ) - """ - do { - try languageDB.write { db in - try db.execute(sql: dropNonUniqueAutosuggestionsQuery) - } - } catch let error as DatabaseError { - let errorMessage = error.message - let errorSQL = error.sql - print( - "An error '\(String(describing: errorMessage))' occurred in the query: \(String(describing: errorSQL))" - ) - } catch {} + LanguageDBManager.shared.deleteNonUniqueAutosuggestions() } setKeyboard() @@ -2437,11 +2399,8 @@ class KeyboardViewController: UIInputViewController { } } } - let prepCaseQuery = "SELECT * FROM prepositions WHERE preposition = ?" - let prepCaseArgs = [wordToCheck.lowercased()] - let outputCols = ["form"] - let prepForm = queryDBRow(query: prepCaseQuery, outputCols: outputCols, args: prepCaseArgs)[0] + let prepForm = LanguageDBManager.shared.queryPrepForm(of: wordToCheck.lowercased())[0] hasPrepForm = !prepForm.isEmpty if hasPrepForm { resetCaseDeclensionState() diff --git a/Keyboards/KeyboardsBase/LanguageDBManager.swift b/Keyboards/KeyboardsBase/LanguageDBManager.swift index 556a42e6..dbd76fe8 100644 --- a/Keyboards/KeyboardsBase/LanguageDBManager.swift +++ b/Keyboards/KeyboardsBase/LanguageDBManager.swift @@ -80,7 +80,7 @@ class LanguageDBManager { return outputValues } - /// Returns rows from the language database given a query and arguments + /// Returns rows from the language database given a query and arguments. /// /// - Parameters: /// - query: the query to run against the language database. @@ -132,7 +132,7 @@ class LanguageDBManager { } catch {} } - /// Deletes rows from the language database given a query and arguments + /// Deletes rows from the language database given a query and arguments. /// /// - Parameters: /// - query: the query to run against the language database. @@ -159,22 +159,38 @@ class LanguageDBManager { // MARK: - Database operations extension LanguageDBManager { - /// Query the translation of word in `translations` - func queryTranslation(of word: String) -> [String] { - let query = "SELECT * FROM translations WHERE word = ?" - let outputCols = ["translation"] - let args = [word.lowercased()] + /// Delete non-unique values in case the lexicon has added words that were already present. + func deleteNonUniqueAutosuggestions() { + let query = """ + DELETE FROM + autocomplete_lexicon - return queryDBRow(query: query, outputCols: outputCols, args: StatementArguments(args)) + WHERE rowid NOT IN ( + SELECT + MIN(rowid) + + FROM + autocomplete_lexicon + + GROUP BY + word + ) + """ + + deleteDBRow(query: query) } - /// Query the suggestion of word in `autosuggestions` - func queryAutosuggestions(of word: String) -> [String] { - let query = "SELECT * FROM autosuggestions WHERE word = ?" - let args = [word.lowercased()] - let outputCols = ["suggestion_0", "suggestion_1", "suggestion_2"] + /// Add words to autocompletions. + func insertAutocompleteLexion(of word: String) { + let query = """ + INSERT OR IGNORE INTO + autocomplete_lexicon (word) - return queryDBRow(query: query, outputCols: outputCols, args: StatementArguments(args)) + VALUES (?) + """ + let args = [word] + + writeDBRow(query: query, args: StatementArguments(args)) } /// Returns the next three words in the `autocomplete_lexicon` that follow a given word. @@ -204,86 +220,149 @@ extension LanguageDBManager { return queryDBRows(query: autocompletionsQuery, outputCols: outputCols, args: StatementArguments(args)) } - /// Query the plural form of word in `nouns` - func queryNounPlural(of word: String) -> [String] { - let query = "SELECT * FROM nouns WHERE noun = ?" - let outputCols = ["plural"] - let args = [word.lowercased()] + /// Query the suggestion of word in `autosuggestions`. + func queryAutosuggestions(of word: String) -> [String] { + let query = """ + SELECT + * + + FROM + autosuggestions + + WHERE + word = ? + """ + let args = [word] + let outputCols = ["suggestion_0", "suggestion_1", "suggestion_2"] return queryDBRow(query: query, outputCols: outputCols, args: StatementArguments(args)) } - /// Query the noun form of word in `nonuns` - func queryNounForm(of word: String) -> [String] { - let query = "SELECT * FROM nouns WHERE noun = ?" - let outputCols = ["form"] - let args = [word.lowercased()] + /// Query emojis of word in `emoji_keywords`. + func queryEmojis(of word: String) -> [String] { + let query = """ + SELECT + * + + FROM + emoji_keywords + + WHERE + word = ? + """ + let outputCols = ["emoji_0", "emoji_1", "emoji_2"] + let args = [word] return queryDBRow(query: query, outputCols: outputCols, args: StatementArguments(args)) } - /// Query the verb form of word in `verbs` - func queryVerb(of word: String) -> [String] { - let query = "SELECT * FROM verbs WHERE verb = ?" - let outputCols = ["verb"] - let args = [word.lowercased()] + /// Query the noun form of word in `nonuns`. + func queryNounForm(of word: String) -> [String] { + let query = """ + SELECT + * + + FROM + nouns + + WHERE + noun = ? + """ + let outputCols = ["form"] + let args = [word] return queryDBRow(query: query, outputCols: outputCols, args: StatementArguments(args)) } - /// Query specific form of word in `verbs` - /// - /// - Parameters: - /// - outputCols: Specific form want to output - func queryVerb(of word: String, with outputCols: [String]) -> [String] { - let query = "SELECT * FROM verbs WHERE verb = ?" - let args = [word.lowercased()] + /// Query the plural form of word in `nouns`. + func queryNounPlural(of word: String) -> [String] { + let query = """ + SELECT + * + + FROM + nouns + + WHERE + noun = ? + """ + let outputCols = ["plural"] + let args = [word] return queryDBRow(query: query, outputCols: outputCols, args: StatementArguments(args)) } - /// Query preposition form of word in `prepositions` + /// Query preposition form of word in `prepositions`. func queryPrepForm(of word: String) -> [String] { - let query = "SELECT * FROM prepositions WHERE preposition = ?" + let query = """ + SELECT + * + + FROM + prepositions + + WHERE + preposition = ? + """ let outputCols = ["form"] - let args = [word.lowercased()] + let args = [word] return queryDBRow(query: query, outputCols: outputCols, args: StatementArguments(args)) } - /// Query emojis of word in `emoji_keywords` - func queryEmojis(of word: String) -> [String] { - let query = "SELECT * FROM emoji_keywords WHERE word = ?" - let outputCols = ["emoji_0", "emoji_1", "emoji_2"] - let args = [word.lowercased()] + /// Query the translation of word in `translations`. + func queryTranslation(of word: String) -> [String] { + let query = """ + SELECT + * + + FROM + translations + + WHERE + word = ? + """ + let outputCols = ["translation"] + let args = [word] return queryDBRow(query: query, outputCols: outputCols, args: StatementArguments(args)) } - /// Add words to autocompletions. - func insertAutocompleteLexion(of word: String) { - let query = "INSERT OR IGNORE INTO autocomplete_lexicon (word) VALUES (?)" + /// Query the verb form of word in `verbs`. + func queryVerb(of word: String) -> [String] { + let query = """ + SELECT + * + + FROM + verbs + + WHERE + verb = ? + """ + let outputCols = ["verb"] let args = [word] - writeDBRow(query: query, args: StatementArguments(args)) + return queryDBRow(query: query, outputCols: outputCols, args: StatementArguments(args)) } - /// Delete non-unique values in case the lexicon has added words that were already present. - func deleteNonUniqueAutosuggestions() { + /// Query specific form of word in `verbs`. + /// + /// - Parameters: + /// - outputCols: Specific form want to output + func queryVerb(of word: String, with outputCols: [String]) -> [String] { let query = """ - DELETE FROM autocomplete_lexicon - WHERE rowid NOT IN ( - SELECT - MIN(rowid) + SELECT + * - FROM - autocomplete_lexicon + FROM + verbs - GROUP BY - word - ) + WHERE + verb = ? """ + let args = [word] - deleteDBRow(query: query) + return queryDBRow(query: query, outputCols: outputCols, args: StatementArguments(args)) } } diff --git a/Keyboards/KeyboardsBase/LoadData.swift b/Keyboards/KeyboardsBase/LoadData.swift deleted file mode 100644 index 539f8d4b..00000000 --- a/Keyboards/KeyboardsBase/LoadData.swift +++ /dev/null @@ -1,158 +0,0 @@ -/** - * Function for loading in data to the keyboards. - * - * Copyright (C) 2023 Scribe - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -import Foundation -import GRDB -import SwiftyJSON - -/// Loads a JSON file that contains grammatical information into a dictionary. -/// -/// - Parameters -/// - filename: the name of the JSON file to be loaded. -func loadJSON(filename fileName: String) -> JSON? { - guard let url = Bundle.main.url(forResource: fileName, withExtension: "json"), - let data = try? Data(contentsOf: url), - let jsonData = try? JSON(data: data) - else { - return nil - } - return jsonData -} - -/// Makes a connection to the language database given the value for controllerLanguage. -func openDBQueue() -> DatabaseQueue { - let dbName = "\(String(describing: get_iso_code(keyboardLanguage: controllerLanguage).uppercased()))LanguageData" - guard let dbPath = Bundle.main.path(forResource: dbName, ofType: "sqlite") else { - fatalError("Failed to locate database file.") - } - do { - let dbQueue = try DatabaseQueue(path: dbPath) - return dbQueue - } catch { - fatalError("Failed to initialize DatabaseQueue: \(error)") - } -} - -// Variable to be replaced with the result of openDBQueue. -var languageDB = try! DatabaseQueue() - -/// Returns a row from the language database given a query and arguments. -/// -/// - Parameters -/// - query: the query to run against the language database. -/// - outputCols: the columns from which the values should come. -/// - args: arguments to pass to `query`. -func queryDBRow(query: String, outputCols: [String], args: [String]) -> [String] { - var outputValues = [String]() - do { - try languageDB.read { db in - if let row = try Row.fetchOne(db, sql: query, arguments: StatementArguments(args)) { - for col in outputCols { - outputValues.append(row[col]) - } - } - } - } catch let error as DatabaseError { - let errorMessage = error.message - let errorSQL = error.sql - let errorArguments = error.arguments - print( - "An error '\(String(describing: errorMessage))' occurred in the query: \(String(describing: errorSQL)) (\(String(describing: errorArguments)))" - ) - } catch {} - - if outputValues == [String]() { - // Append an empty string so that we can check for it and trigger commandState = .invalid. - outputValues.append("") - } - - return outputValues -} - -/// Writes a row of a language database table given a query and arguments. -/// -/// - Parameters -/// - query: the query to run against the language database. -/// - args: arguments to pass to `query`. -func writeDBRow(query: String, args: StatementArguments) { - do { - try languageDB.write { db in - try db.execute( - sql: query, - arguments: args - ) - } - } catch let error as DatabaseError { - let errorMessage = error.message - let errorSQL = error.sql - let errorArguments = error.arguments - print( - "An error '\(String(describing: errorMessage))' occurred in the query: \(String(describing: errorSQL)) (\(String(describing: errorArguments)))" - ) - } catch {} -} - -/// Returns the next three words in the `autocomplete_lexicon` that follow a given word. -/// -/// - Parameters -/// - word: the word that autosuggestions should be returned for. -func queryAutocompletions(word: String) -> [String] { - var autocompletions = [String]() - - let autocompletionsQuery = """ - SELECT - word - - FROM - autocomplete_lexicon - - WHERE - LOWER(word) LIKE ? - - ORDER BY - word COLLATE NOCASE ASC - - LIMIT - 3 - """ - let patterns = ["\(word.lowercased())%"] - - do { - let rows = try languageDB.read { db in - try Row.fetchAll(db, sql: autocompletionsQuery, arguments: StatementArguments(patterns)) - } - for r in rows { - autocompletions.append(r["word"]) - } - } catch let error as DatabaseError { - let errorMessage = error.message - let errorSQL = error.sql - let errorArguments = error.arguments - print( - "An error '\(String(describing: errorMessage))' occurred in the query: \(String(describing: errorSQL)) (\(String(describing: errorArguments)))" - ) - } catch {} - - if autocompletions == [String]() { - // Append an empty string so that we can check for it and trigger nothing being shown. - autocompletions.append("") - } - - return autocompletions -} diff --git a/Keyboards/KeyboardsBase/ScribeFunctionality/Annotate.swift b/Keyboards/KeyboardsBase/ScribeFunctionality/Annotate.swift index 6d1e2c12..064a6fc8 100644 --- a/Keyboards/KeyboardsBase/ScribeFunctionality/Annotate.swift +++ b/Keyboards/KeyboardsBase/ScribeFunctionality/Annotate.swift @@ -51,14 +51,8 @@ let prepAnnotationConversionDict = [ /// - wordToAnnotate: the word that an annotation should be created for. /// - KVC: the keyboard view controller. func wordAnnotation(wordToAnnotate: String, KVC: KeyboardViewController) { - let nounGenderQuery = "SELECT * FROM nouns WHERE noun = ?" - let prepCaseQuery = "SELECT * FROM prepositions WHERE preposition = ?" - let nounGenderArgs = [wordToAnnotate] - let prepCaseArgs = [wordToAnnotate.lowercased()] - let outputCols = ["form"] - - let nounForm = queryDBRow(query: nounGenderQuery, outputCols: outputCols, args: nounGenderArgs)[0] - prepAnnotationForm = queryDBRow(query: prepCaseQuery, outputCols: outputCols, args: prepCaseArgs)[0] + let nounForm = LanguageDBManager.shared.queryNounForm(of: wordToAnnotate)[0] + prepAnnotationForm = LanguageDBManager.shared.queryPrepForm(of: wordToAnnotate.lowercased())[0] hasNounForm = !nounForm.isEmpty hasPrepForm = !prepAnnotationForm.isEmpty @@ -270,11 +264,7 @@ func typedWordAnnotation(KVC: KeyboardViewController) { /// - index: the auto action key index that the annotation should be set for. /// - KVC: the keyboard view controller. func autoActionAnnotation(autoActionWord: String, index: Int, KVC: KeyboardViewController) { - let nounGenderQuery = "SELECT * FROM nouns WHERE noun = ?" - let nounGenderArgs = [autoActionWord] - let outputCols = ["form"] - - let nounForm = queryDBRow(query: nounGenderQuery, outputCols: outputCols, args: nounGenderArgs)[0] + let nounForm = LanguageDBManager.shared.queryNounForm(of: autoActionWord)[0] hasNounForm = !nounForm.isEmpty diff --git a/Keyboards/KeyboardsBase/ScribeFunctionality/Conjugate.swift b/Keyboards/KeyboardsBase/ScribeFunctionality/Conjugate.swift index 4c3badd2..f1e6782b 100644 --- a/Keyboards/KeyboardsBase/ScribeFunctionality/Conjugate.swift +++ b/Keyboards/KeyboardsBase/ScribeFunctionality/Conjugate.swift @@ -212,10 +212,7 @@ func triggerVerbConjugation(commandBar: UILabel) -> Bool { inputWordIsCapitalized = firstLetter.isUppercase verbToConjugate = verbToConjugate.lowercased() - let query = "SELECT * FROM verbs WHERE verb = ?" - let args = [verbToConjugate] - let outputCols = ["verb"] - let verbInTable = queryDBRow(query: query, outputCols: outputCols, args: args)[0] + let verbInTable = LanguageDBManager.shared.queryVerb(of: verbToConjugate)[0] return verbToConjugate == verbInTable } @@ -226,20 +223,20 @@ func triggerVerbConjugation(commandBar: UILabel) -> Bool { /// - keyPressed: the button pressed as sender. /// - requestedForm: the form that is triggered by the given key. func returnConjugation(keyPressed: UIButton, requestedForm: String) { + let outputCols = [requestedForm] + if commandState == .selectCaseDeclension { returnDeclension(keyPressed: keyPressed) return } + let wordPressed = keyPressed.titleLabel?.text ?? "" // Don't change proxy if they select a conjugation that's missing. if wordPressed == invalidCommandMsg { proxy.insertText("") } else if formsDisplayDimensions == .view3x2 { - let query = "SELECT * FROM verbs WHERE verb = ?" - let args = [verbToConjugate] - let outputCols = [requestedForm] - wordToReturn = queryDBRow(query: query, outputCols: outputCols, args: args)[0] + wordToReturn = LanguageDBManager.shared.queryVerb(of: verbToConjugate, with: outputCols)[0] potentialWordsToReturn = wordToReturn.components(separatedBy: " ") if inputWordIsCapitalized { @@ -253,10 +250,7 @@ func returnConjugation(keyPressed: UIButton, requestedForm: String) { proxy.insertText(wordToReturn + " ") } } else if formsDisplayDimensions == .view2x2 { - let query = "SELECT * FROM verbs WHERE verb = ?" - let args = [verbToConjugate] - let outputCols = [requestedForm] - wordToReturn = queryDBRow(query: query, outputCols: outputCols, args: args)[0] + wordToReturn = LanguageDBManager.shared.queryVerb(of: verbToConjugate, with: outputCols)[0] potentialWordsToReturn = wordToReturn.components(separatedBy: " ") if inputWordIsCapitalized { @@ -265,11 +259,13 @@ func returnConjugation(keyPressed: UIButton, requestedForm: String) { proxy.insertText(wordToReturn + " ") } } + if controllerLanguage == "German" { if potentialWordsToReturn.count == 2 { proxy.adjustTextPosition(byCharacterOffset: (potentialWordsToReturn[1].count) * -1) } } + autoActionState = .suggest commandState = .idle conjViewShiftButtonsState = .bothInactive diff --git a/Keyboards/KeyboardsBase/ScribeFunctionality/Plural.swift b/Keyboards/KeyboardsBase/ScribeFunctionality/Plural.swift index ef7b6e13..121a22ec 100644 --- a/Keyboards/KeyboardsBase/ScribeFunctionality/Plural.swift +++ b/Keyboards/KeyboardsBase/ScribeFunctionality/Plural.swift @@ -46,10 +46,7 @@ func queryPlural(commandBar: UILabel) { noun = noun.lowercased() } - let query = "SELECT * FROM nouns WHERE noun = ?" - let args = [noun] - let outputCols = ["plural"] - wordToReturn = queryDBRow(query: query, outputCols: outputCols, args: args)[0] + wordToReturn = LanguageDBManager.shared.queryNounPlural(of: noun)[0] guard !wordToReturn.isEmpty else { commandState = .invalid diff --git a/Keyboards/KeyboardsBase/ScribeFunctionality/Translate.swift b/Keyboards/KeyboardsBase/ScribeFunctionality/Translate.swift index 547f13b1..1e03c987 100644 --- a/Keyboards/KeyboardsBase/ScribeFunctionality/Translate.swift +++ b/Keyboards/KeyboardsBase/ScribeFunctionality/Translate.swift @@ -40,12 +40,8 @@ func queryTranslation(commandBar: UILabel) { // Check to see if the input was uppercase to return an uppercase conjugation. inputWordIsCapitalized = wordToTranslate.substring(toIdx: 1).isUppercase - wordToTranslate = wordToTranslate.lowercased() - let query = "SELECT * FROM translations WHERE word = ?" - let args = [wordToTranslate] - let outputCols = ["translation"] - wordToReturn = queryDBRow(query: query, outputCols: outputCols, args: args)[0] + wordToReturn = LanguageDBManager.shared.queryTranslation(of: wordToTranslate.lowercased())[0] guard !wordToReturn.isEmpty else { commandState = .invalid diff --git a/Scribe.xcodeproj/project.pbxproj b/Scribe.xcodeproj/project.pbxproj index fbb2a84c..3d56477c 100644 --- a/Scribe.xcodeproj/project.pbxproj +++ b/Scribe.xcodeproj/project.pbxproj @@ -383,18 +383,6 @@ D190B2582742525C00705659 /* Keyboard.xib in Resources */ = {isa = PBXBuildFile; fileRef = D1C0ACD92719E0AA001E11C3 /* Keyboard.xib */; }; D190B26827426ACD00705659 /* KeyboardViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D190B2592742565500705659 /* KeyboardViewController.swift */; }; D190B26927426ACD00705659 /* KeyboardViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D190B2592742565500705659 /* KeyboardViewController.swift */; }; - D19569E12BBCCAD700D025D7 /* LoadData.swift in Sources */ = {isa = PBXBuildFile; fileRef = D19569E02BBCCAD700D025D7 /* LoadData.swift */; }; - D19569E22BBCCAD700D025D7 /* LoadData.swift in Sources */ = {isa = PBXBuildFile; fileRef = D19569E02BBCCAD700D025D7 /* LoadData.swift */; }; - D19569E32BBCCAD700D025D7 /* LoadData.swift in Sources */ = {isa = PBXBuildFile; fileRef = D19569E02BBCCAD700D025D7 /* LoadData.swift */; }; - D19569E42BBCCAD700D025D7 /* LoadData.swift in Sources */ = {isa = PBXBuildFile; fileRef = D19569E02BBCCAD700D025D7 /* LoadData.swift */; }; - D19569E52BBCCAD700D025D7 /* LoadData.swift in Sources */ = {isa = PBXBuildFile; fileRef = D19569E02BBCCAD700D025D7 /* LoadData.swift */; }; - D19569E62BBCCAD700D025D7 /* LoadData.swift in Sources */ = {isa = PBXBuildFile; fileRef = D19569E02BBCCAD700D025D7 /* LoadData.swift */; }; - D19569E72BBCCAD700D025D7 /* LoadData.swift in Sources */ = {isa = PBXBuildFile; fileRef = D19569E02BBCCAD700D025D7 /* LoadData.swift */; }; - D19569E82BBCCAD700D025D7 /* LoadData.swift in Sources */ = {isa = PBXBuildFile; fileRef = D19569E02BBCCAD700D025D7 /* LoadData.swift */; }; - D19569E92BBCCAD700D025D7 /* LoadData.swift in Sources */ = {isa = PBXBuildFile; fileRef = D19569E02BBCCAD700D025D7 /* LoadData.swift */; }; - D19569EA2BBCCAD700D025D7 /* LoadData.swift in Sources */ = {isa = PBXBuildFile; fileRef = D19569E02BBCCAD700D025D7 /* LoadData.swift */; }; - D19569EB2BBCCAD700D025D7 /* LoadData.swift in Sources */ = {isa = PBXBuildFile; fileRef = D19569E02BBCCAD700D025D7 /* LoadData.swift */; }; - D19569EC2BBCCAD700D025D7 /* LoadData.swift in Sources */ = {isa = PBXBuildFile; fileRef = D19569E02BBCCAD700D025D7 /* LoadData.swift */; }; D196B360279A051000228F3F /* ENPrivacyPolicy.swift in Sources */ = {isa = PBXBuildFile; fileRef = D196B35F279A051000228F3F /* ENPrivacyPolicy.swift */; }; D1A2DCB127AD37BD0057A10D /* ENAppText.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1A2DCB027AD37BD0057A10D /* ENAppText.swift */; }; D1A2DCB427AD3EB50057A10D /* AppUISymbols.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1A2DCB327AD3EB50057A10D /* AppUISymbols.swift */; }; @@ -948,7 +936,6 @@ D190B2592742565500705659 /* KeyboardViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardViewController.swift; sourceTree = ""; }; D190B28F27426F4900705659 /* LICENSE.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE.txt; sourceTree = SOURCE_ROOT; }; D190B29027426F4900705659 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = SOURCE_ROOT; }; - D19569E02BBCCAD700D025D7 /* LoadData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoadData.swift; sourceTree = ""; }; D196B35F279A051000228F3F /* ENPrivacyPolicy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ENPrivacyPolicy.swift; sourceTree = ""; }; D1A2DCB027AD37BD0057A10D /* ENAppText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ENAppText.swift; sourceTree = ""; }; D1A2DCB327AD3EB50057A10D /* AppUISymbols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppUISymbols.swift; sourceTree = ""; }; @@ -1376,7 +1363,6 @@ D171942E27AEDE110038660B /* KeyboardKeys.swift */, D190B2592742565500705659 /* KeyboardViewController.swift */, D190B24D2741B61000705659 /* LanguageDBManager.swift */, - D19569E02BBCCAD700D025D7 /* LoadData.swift */, D16DD3A429E78A1500FB9022 /* Utilities.swift */, D1C0ACD92719E0AA001E11C3 /* Keyboard.xib */, ); @@ -2036,7 +2022,6 @@ D17193F827AECC930038660B /* FRCommandVariables.swift in Sources */, D171945827AF237C0038660B /* ScribeKey.swift in Sources */, 1406B78C2A3209CF001DF45B /* AppExtensions.swift in Sources */, - D19569E12BBCCAD700D025D7 /* LoadData.swift in Sources */, D1B81D4A27BBBA200085FE5E /* ITCommandVariables.swift in Sources */, D180EC0328FDFABF0018E29B /* FR-AZERTYInterfaceVariables.swift in Sources */, D1CDED7B2A859FBF00098546 /* ENInterfaceVariables.swift in Sources */, @@ -2108,7 +2093,6 @@ 38BD214F22D592CA00C6795D /* DEKeyboardViewController.swift in Sources */, D171943A27AEF0560038660B /* KeyboardStyling.swift in Sources */, CE1378C628F5D7AC00E1CBC2 /* ScribeColor.swift in Sources */, - D19569E52BBCCAD700D025D7 /* LoadData.swift in Sources */, 30453972293B9E04003AE55B /* ToolTipViewTheme.swift in Sources */, 3045395B293B911C003AE55B /* AppTextStyling.swift in Sources */, D1B81D5527BBBA360085FE5E /* ITInterfaceVariables.swift in Sources */, @@ -2170,7 +2154,6 @@ D171942127AECD170038660B /* SVCommandVariables.swift in Sources */, D171943927AEF0560038660B /* KeyboardStyling.swift in Sources */, CE1378C528F5D7AC00E1CBC2 /* ScribeColor.swift in Sources */, - D19569E42BBCCAD700D025D7 /* LoadData.swift in Sources */, 30453970293B9DFF003AE55B /* ToolTipViewTheme.swift in Sources */, 30453959293B911B003AE55B /* AppTextStyling.swift in Sources */, D1B81D5427BBBA360085FE5E /* ITInterfaceVariables.swift in Sources */, @@ -2232,7 +2215,6 @@ D171942327AECD170038660B /* SVCommandVariables.swift in Sources */, D171943B27AEF0560038660B /* KeyboardStyling.swift in Sources */, CE1378C828F5D7AC00E1CBC2 /* ScribeColor.swift in Sources */, - D19569E92BBCCAD700D025D7 /* LoadData.swift in Sources */, 30453974293B9E05003AE55B /* ToolTipViewTheme.swift in Sources */, 3045395D293B911D003AE55B /* AppTextStyling.swift in Sources */, D1B81D5727BBBA360085FE5E /* ITInterfaceVariables.swift in Sources */, @@ -2294,7 +2276,6 @@ D171942527AECD170038660B /* SVCommandVariables.swift in Sources */, D171943D27AEF0560038660B /* KeyboardStyling.swift in Sources */, CE1378CA28F5D7AC00E1CBC2 /* ScribeColor.swift in Sources */, - D19569EB2BBCCAD700D025D7 /* LoadData.swift in Sources */, 30453976293B9E06003AE55B /* ToolTipViewTheme.swift in Sources */, 3045395F293B911E003AE55B /* AppTextStyling.swift in Sources */, D1B81D5927BBBA360085FE5E /* ITInterfaceVariables.swift in Sources */, @@ -2356,7 +2337,6 @@ D171942427AECD170038660B /* SVCommandVariables.swift in Sources */, D171943C27AEF0560038660B /* KeyboardStyling.swift in Sources */, CE1378C928F5D7AC00E1CBC2 /* ScribeColor.swift in Sources */, - D19569EA2BBCCAD700D025D7 /* LoadData.swift in Sources */, 30453975293B9E06003AE55B /* ToolTipViewTheme.swift in Sources */, 3045395E293B911E003AE55B /* AppTextStyling.swift in Sources */, D1B81D5827BBBA360085FE5E /* ITInterfaceVariables.swift in Sources */, @@ -2418,7 +2398,6 @@ D171942627AECD170038660B /* SVCommandVariables.swift in Sources */, D171943E27AEF0560038660B /* KeyboardStyling.swift in Sources */, CE1378CB28F5D7AC00E1CBC2 /* ScribeColor.swift in Sources */, - D19569EC2BBCCAD700D025D7 /* LoadData.swift in Sources */, 30453977293B9E06003AE55B /* ToolTipViewTheme.swift in Sources */, 30453960293B911F003AE55B /* AppTextStyling.swift in Sources */, D1B81D5A27BBBA360085FE5E /* ITInterfaceVariables.swift in Sources */, @@ -2480,7 +2459,6 @@ D1AB5B2829C757A100CCB0C1 /* ESInterfaceVariables.swift in Sources */, D1AB5B2929C757A100CCB0C1 /* SVInterfaceVariables.swift in Sources */, D1AB5B2A29C757A100CCB0C1 /* ScribeColor.swift in Sources */, - D19569E82BBCCAD700D025D7 /* LoadData.swift in Sources */, D1AB5B2B29C757A100CCB0C1 /* ToolTipViewTheme.swift in Sources */, D1AB5B2C29C757A100CCB0C1 /* AppTextStyling.swift in Sources */, D1AB5B2D29C757A100CCB0C1 /* ITInterfaceVariables.swift in Sources */, @@ -2542,7 +2520,6 @@ D1AFDF0629CA66D00033BF27 /* ESInterfaceVariables.swift in Sources */, D1AFDF0729CA66D00033BF27 /* SVInterfaceVariables.swift in Sources */, D1AFDF0829CA66D00033BF27 /* ScribeColor.swift in Sources */, - D19569E32BBCCAD700D025D7 /* LoadData.swift in Sources */, D1AFDF0929CA66D00033BF27 /* ToolTipViewTheme.swift in Sources */, D1AFDF0A29CA66D00033BF27 /* AppTextStyling.swift in Sources */, D1AFDF0B29CA66D00033BF27 /* ITInterfaceVariables.swift in Sources */, @@ -2604,7 +2581,6 @@ D1AFDF8329CA66F40033BF27 /* ESInterfaceVariables.swift in Sources */, D1AFDF8429CA66F40033BF27 /* SVInterfaceVariables.swift in Sources */, D1AFDF8529CA66F40033BF27 /* ScribeColor.swift in Sources */, - D19569E22BBCCAD700D025D7 /* LoadData.swift in Sources */, D1AFDF8629CA66F40033BF27 /* ToolTipViewTheme.swift in Sources */, D1AFDF8729CA66F40033BF27 /* AppTextStyling.swift in Sources */, D1AFDF8829CA66F40033BF27 /* ITInterfaceVariables.swift in Sources */, @@ -2666,7 +2642,6 @@ D1AFDFD929CA6E900033BF27 /* ESInterfaceVariables.swift in Sources */, D1AFDFDA29CA6E900033BF27 /* SVInterfaceVariables.swift in Sources */, D1AFDFDB29CA6E900033BF27 /* ScribeColor.swift in Sources */, - D19569E62BBCCAD700D025D7 /* LoadData.swift in Sources */, D1AFDFDC29CA6E900033BF27 /* ToolTipViewTheme.swift in Sources */, D1AFDFDD29CA6E900033BF27 /* AppTextStyling.swift in Sources */, D1AFDFDE29CA6E900033BF27 /* ITInterfaceVariables.swift in Sources */, @@ -2728,7 +2703,6 @@ D1B81D3327BBB6AD0085FE5E /* ESInterfaceVariables.swift in Sources */, D1B81D3527BBB6B50085FE5E /* SVInterfaceVariables.swift in Sources */, CE1378C728F5D7AC00E1CBC2 /* ScribeColor.swift in Sources */, - D19569E72BBCCAD700D025D7 /* LoadData.swift in Sources */, 30453973293B9E05003AE55B /* ToolTipViewTheme.swift in Sources */, 3045395C293B911D003AE55B /* AppTextStyling.swift in Sources */, D1B81D5627BBBA360085FE5E /* ITInterfaceVariables.swift in Sources */,