Closed andrewtavis closed 1 year ago
Very simple question as well, @wkyoshida and also @SaurabhJamadagni: does my idea of versioning for all this make sense? Scribe-iOS is going to v2.2.0 as what the user is experiencing is just some new features like the emoji suggestions, etc β i.e. nothing "breaking" per say. The functionality of Scribe-Data is being totally changed though to export something different with tons of breaking changes, hence that's going to v3.0.0.
Oki doki π Soooo, querying database values πππ
Here are the functions I'm making and a simple example:
import GRDB
// get_iso_code is new and returns the two letter code for the language (ex: Deutsch -> de)
/// 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"
let dbPath = Bundle.main.path(forResource: dbName, ofType: "sqlite")! // ex: dbName = DELanguageData
let db = try! DatabaseQueue(
path: dbPath
)
return db
}
/// Returns a value from the language database given a query and arguemtns.
///
/// - Parameters
/// - query: the query to run against the language database.
/// - args: arguments to pass to the query.
/// - outputCols: the columns from which the value should come.
func queryDB(query: String, args: [String], outputCols: [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 {}
return outputValues
}
var languageDB = try! DatabaseQueue() // instantiated for assignment within CommandVariables.swift
languageDB = openDBQueue() // on firstKeyboardLoad == true within loadKeys()
// Example in another file:
let query = "SELECT * FROM emoji_keywords WHERE word = ?"
let args = ["gesicht"]
let outputCols = ["emoji_1"]
spaceBar = queryDB(query: query, args: args, outputCols: outputCols)[0]
Which then gives us π₯π₯π₯π₯:
Will do a PR soonish with the above a bit more organized π
I think that this is a good way of going about this, but feedback would be welcome :) Specifically we'll need to keep track of the index of certain columns passed within outputCols
to queryDB
to assign strings from the query results. I'd say this is an ok trade off for being able to very simply get individual values and whole rows for things like autosuggestions as well as check for if no results were returned.
Progress so far for me locally: all commands have been switched over π So Translate
, Conjugate
and Plural
are all directly from the SQLite databases, and I've actually removed the translations
and verbs
variables all together π Suggestions based on pronouns has also been switched over as that was referencing verbs
, and the emoji autosuggestions/completions are also SQLite based π±ππ
I'm going to work on switching over autosuggestions right now. A note is that the way we do autocompletions is the thing that will need to make the biggest shift, and will likely need a custom query (totally fine that it would π). We need to get rid of the autocompleteLexicon
variable completely in my opinion. As discussed in #286, the creation of this variable in the firstKeyboardLoad
step of laodKeys()
was what was slowing down the initial load step, which is now solved as this logic has been moved out of the view controller. With that being said, there still is a slowdown of the UI for Russian in particular as the user types because we have this massive array on which the autocomplete checks are being made. Switching this to SQLite will doubtless speed this all up :) :)
does my idea of versioning for all this make sense? Scribe-iOS is going to v2.2.0 as what the user is experiencing is just some new features like the emoji suggestions, etc
Hey @andrewtavis! Yeah that makes sense. With all the internal changes going on, Scribe-iOS version also seems like a big jump to me but I can see how the numbering would make sense from a user's perspective. Sounds great π
Remaining issues after the commit I'm about to do π
Alrighty then! 3be5a59 is massive π±π It also includes two bug fixes that can be seen in the commit logs for the CHAGELOG
:) There are also minor fixes throughout as this required me to go through a lot of the codebase.
What we've all been waiting for π:
queryDBRow
gets us values (we get a list that's one row of specified columns and can index it for individual values for commands/features)writeDBRow
allows us to add rows for data that didn't come through in the ETL/ELT process
Scribe
that are added in expandLanguageDataset
, specificallycreateAutocompleteLexicon
creates a single column table from the "keys"/primary keys of most of the other tables that we then query from for this featurequeryAutocompletions
gets us an ordered group of three words from the autocomplete lexiconI've been doing lots of testing and it all seems to be working great so far aside from one issue: for some reason I can't get it so that lower case versions of German nouns (that are capitalized) are not in the autocomplete lexicon... This was a problem a long time ago when we first added autocomplete/autosuggest. What I means by this is that there are two versions of most German nouns: Buch
and buch
, Auto
and auto
, etc. This is because we get lower case from the autosuggestion keys and capitalized from Wikidata. At this point in createAutocompleteLexicon I'm trying to check if the capitalized or upper case version of a word is also in the nouns, and if so to take the noun instance. I'm likely just doing a simple SQL mistake and can't see it right now π€·ββοΈ We need to get it fixed on the SQL side, but it can also be implemented another way if someone has an idea.
Most important thing: I really think that this has worked πππ We'll see, but before doing all this there was some serious lag still while using the Russian keyboard. In the initial tests since the changes it seems to be very responsive π₯ππ₯β‘οΈππ
If someone has suggestions for the nouns I'd be grateful! Glad this is coming to a close π
The above is the function for the autocomplete creation. Just to list it, this is the logic that I'm trying to put into the autocomplete lexicon:
We could also edit the drop duplicates function that's called after the UILexicon words (names from Contacts that are unordered) are added:
An idea after a nightβs sleep π΄π‘: a self join to remove the lower case versions of capitalized/upper case words might make sense.
- Filter out words that are less than three characters, numbers and hyphenated words.
- This step also needs to be looked at as the numbers aren't being removed π€
This has been fixed at this point :) Hyphenated words have been removed, and I'm actually keeping numbers as I think they help match the emoji suggestions for 10 on a clock, etc. We're selecting words that are longer than two characters for everything except emojis for this purpose. We can change it later based on live testing π
af553b4 and d9e3cb0 fixed the last glaring issues in all this π I'm going to test a bit after lunch, then will close and move on to #284 π We can do minor patches to fix any issues that come up, but now everything seems to be working fine :)
d9e3cb0 solution wasn't what we wanted, but 91b4791 fixes it :) As expected it was something pretty standard. Now what's happening in the selection step of the autocomplete lexicon query is we're joining on the nouns
table as before, but now we're doing it twice β once when the lexicon word is the same as the noun when it's upper case and once when it's the same as the noun when it's capitalized. From there we do the same CASE WHEN
checks we were doing before on the corresponding columns from nouns
to only select upper case and capitalized versions if they exist π
With 6add031 we removed the JSON data π I've been playing around with it all and it seems to be ok. Sent along some commits today as well that fixed some minor bugs with the emoji implementations, but nothing major π
I think we're good to go! Closing this and switching over to #284!
Thanks all for your support and ideas on all this! Major milestone for Scribe finished π Here's hoping it'll work once we get it onto devices π€
Hey @andrewtavis, sorry coming to this a bit late. I wish there was a way to star an issue because I am pretty sure I am going to be coming back here a lot. Loving the process documentation. I hate I was no help but thank you so much for all the changes! This is going to be awesome!! π
Thereβs a little bit left for this to be pushed later on today, @SaurabhJamadagni, but Iβll send it along soon. Thereβs so much new data (as mentioned on Matrix π) that I actually needed to do further optimizations to what we had before π Will send it along with #284 later :)
A final note on this issue is that the Russian keyboard's translation feature β the original issue that lead to all this β is now functional in v2.2.0 on device ππ
Terms
Behavior
Thereβs currently a bug with v1.1.0 where the Russian keyboard will not translate words. The keyboard switches to English as it should, and words can be typed, but then on pressing return the keyboard crashes without anything being inserted.
Device type
iPhone 7
iOS version
iOS 15.1