@@ -367,10 +367,7 @@ class KeyboardViewController: UIInputViewController {
367
367
/// - Parameters
368
368
/// - word: the word for which corresponding emojis should be shown for.
369
369
func getEmojiAutoSuggestions( for word: String ) {
370
- let query = " SELECT * FROM emoji_keywords WHERE word = ? "
371
- let args = [ word. lowercased ( ) ]
372
- let outputCols = [ " emoji_0 " , " emoji_1 " , " emoji_2 " ]
373
- let emojisToDisplay = queryDBRow ( query: query, outputCols: outputCols, args: args)
370
+ let emojisToDisplay = LanguageDBManager . shared. queryEmojis ( of: word. lowercased ( ) )
374
371
375
372
if !emojisToDisplay[ 0 ] . isEmpty {
376
373
emojisToDisplayArray = [ String] ( )
@@ -448,7 +445,7 @@ class KeyboardViewController: UIInputViewController {
448
445
}
449
446
450
447
// Get options for completion that start with the current prefix and are not just one letter.
451
- let completionOptions = queryAutocompletions ( word: currentPrefix)
448
+ let completionOptions = LanguageDBManager . shared . queryAutocompletions ( word: currentPrefix)
452
449
453
450
if !completionOptions[ 0 ] . isEmpty {
454
451
if completionOptions. count <= 3 {
@@ -505,20 +502,20 @@ class KeyboardViewController: UIInputViewController {
505
502
let prefix = proxy. documentContextBeforeInput? . components ( separatedBy: " " ) . secondToLast ( ) ?? " "
506
503
507
504
completionWords = [ String] ( )
508
- let query = " SELECT * FROM verbs WHERE verb = ? "
509
505
for i in 0 ..< 3 {
510
506
// Get conjugations of the preselected verbs.
511
- let args = [ verbsAfterPronounsArray [ i] ]
512
507
if let tense = pronounAutosuggestionTenses [ prefix. lowercased ( ) ] {
513
508
let outputCols = [ tense]
514
- var suggestion = queryDBRow ( query: query, outputCols: outputCols, args: args) [ 0 ]
509
+ var suggestion = LanguageDBManager . shared. queryVerb ( of: verbsAfterPronounsArray [ i] , with: outputCols) [ 0 ]
510
+
515
511
if suggestion == " " {
516
512
suggestion = verbsAfterPronounsArray [ i]
517
513
}
518
514
519
515
if suggestion == " REFLEXIVE_PRONOUN " && controllerLanguage == " Spanish " {
520
516
suggestion = getESReflexivePronoun ( pronoun: prefix. lowercased ( ) )
521
517
}
518
+
522
519
if shiftButtonState == . shift {
523
520
completionWords. append ( suggestion. capitalize ( ) )
524
521
} else if capsLockButtonState == . locked {
@@ -579,13 +576,9 @@ class KeyboardViewController: UIInputViewController {
579
576
} else {
580
577
// We have to consider these different cases as the key always has to match.
581
578
// Else, even if the lowercased prefix is present in the dictionary, if the actual prefix isn't present we won't get an output.
582
- let query = " SELECT * FROM autosuggestions WHERE word = ? "
583
- let argsLower = [ prefix. lowercased ( ) ]
584
- let argsCapitalize = [ prefix. capitalized]
585
- let outputCols = [ " suggestion_0 " , " suggestion_1 " , " suggestion_2 " ]
579
+ let suggestionsLowerCasePrefix = LanguageDBManager . shared. queryAutosuggestions ( of: prefix. lowercased ( ) )
580
+ let suggestionsCapitalizedPrefix = LanguageDBManager . shared. queryAutosuggestions ( of: prefix. capitalized)
586
581
587
- let suggestionsLowerCasePrefix = queryDBRow ( query: query, outputCols: outputCols, args: argsLower)
588
- let suggestionsCapitalizedPrefix = queryDBRow ( query: query, outputCols: outputCols, args: argsCapitalize)
589
582
if !suggestionsLowerCasePrefix[ 0 ] . isEmpty {
590
583
completionWords = [ String] ( )
591
584
for i in 0 ..< 3 {
@@ -598,12 +591,9 @@ class KeyboardViewController: UIInputViewController {
598
591
} else if capsLockButtonState == . locked {
599
592
completionWords. append ( suggestionsLowerCasePrefix [ i] . uppercased ( ) )
600
593
} else {
601
- let nounGenderQuery = " SELECT * FROM nouns WHERE noun = ? "
602
- let nounGenderArgs = [ suggestionsLowerCasePrefix [ i] ]
603
- let outputCols = [ " form " ]
604
-
605
- let nounForm = queryDBRow ( query: nounGenderQuery, outputCols: outputCols, args: nounGenderArgs) [ 0 ]
594
+ let nounForm = LanguageDBManager . shared. queryNounForm ( of: suggestionsLowerCasePrefix [ i] ) [ 0 ]
606
595
hasNounForm = !nounForm. isEmpty
596
+
607
597
if !hasNounForm {
608
598
completionWords. append ( suggestionsLowerCasePrefix [ i] . lowercased ( ) )
609
599
} else {
@@ -618,6 +608,7 @@ class KeyboardViewController: UIInputViewController {
618
608
completionWords. append ( previousWord)
619
609
continue
620
610
}
611
+
621
612
if shiftButtonState == . shift {
622
613
completionWords. append ( suggestionsCapitalizedPrefix [ i] . capitalize ( ) )
623
614
} else if capsLockButtonState == . locked {
@@ -1496,10 +1487,8 @@ class KeyboardViewController: UIInputViewController {
1496
1487
}
1497
1488
1498
1489
// Populate conjugation view buttons.
1499
- let query = " SELECT * FROM verbs WHERE verb = ? "
1500
- let args = [ verbToConjugate]
1501
1490
let outputCols = allConjugations
1502
- let conjugationsToDisplay = queryDBRow ( query : query , outputCols : outputCols, args : args )
1491
+ let conjugationsToDisplay = LanguageDBManager . shared . queryVerb ( of : verbToConjugate , with : outputCols)
1503
1492
for index in 0 ..< allConjugations. count {
1504
1493
if conjugationsToDisplay [ index] == " " {
1505
1494
// Assign the invalid message if the conjugation isn't present in the directory.
@@ -1879,46 +1868,19 @@ class KeyboardViewController: UIInputViewController {
1879
1868
// Show the name of the keyboard to the user.
1880
1869
showKeyboardLanguage = true
1881
1870
1882
- // Initialize the language database and create the autosuggestions lexicon.
1883
- languageDB = openDBQueue ( )
1884
-
1885
1871
// Add UILexicon words including unpaired first and last names from Contacts to autocompletions.
1886
- let addToAutocompleteLexiconQuery = " INSERT OR IGNORE INTO autocomplete_lexicon (word) VALUES (?) "
1887
1872
requestSupplementaryLexicon { ( userLexicon: UILexicon ? ) in
1888
1873
if let lexicon = userLexicon {
1889
1874
for item in lexicon. entries {
1890
1875
if item. documentText. count > 1 {
1891
- writeDBRow ( query : addToAutocompleteLexiconQuery , args : [ item. documentText] )
1876
+ LanguageDBManager . shared . insertAutocompleteLexion ( of : item. documentText)
1892
1877
}
1893
1878
}
1894
1879
}
1895
1880
}
1896
1881
1897
1882
// Drop non-unique values in case the lexicon has added words that were already present.
1898
- let dropNonUniqueAutosuggestionsQuery = """
1899
- DELETE FROM autocomplete_lexicon
1900
- WHERE rowid NOT IN (
1901
- SELECT
1902
- MIN(rowid)
1903
-
1904
- FROM
1905
- autocomplete_lexicon
1906
-
1907
- GROUP BY
1908
- word
1909
- )
1910
- """
1911
- do {
1912
- try languageDB. write { db in
1913
- try db. execute ( sql: dropNonUniqueAutosuggestionsQuery)
1914
- }
1915
- } catch let error as DatabaseError {
1916
- let errorMessage = error. message
1917
- let errorSQL = error. sql
1918
- print (
1919
- " An error ' \( String ( describing: errorMessage) ) ' occurred in the query: \( String ( describing: errorSQL) ) "
1920
- )
1921
- } catch { }
1883
+ LanguageDBManager . shared. deleteNonUniqueAutosuggestions ( )
1922
1884
}
1923
1885
1924
1886
setKeyboard ( )
@@ -2437,11 +2399,8 @@ class KeyboardViewController: UIInputViewController {
2437
2399
}
2438
2400
}
2439
2401
}
2440
- let prepCaseQuery = " SELECT * FROM prepositions WHERE preposition = ? "
2441
- let prepCaseArgs = [ wordToCheck. lowercased ( ) ]
2442
- let outputCols = [ " form " ]
2443
2402
2444
- let prepForm = queryDBRow ( query : prepCaseQuery , outputCols : outputCols , args : prepCaseArgs ) [ 0 ]
2403
+ let prepForm = LanguageDBManager . shared . queryPrepForm ( of : wordToCheck . lowercased ( ) ) [ 0 ]
2445
2404
hasPrepForm = !prepForm. isEmpty
2446
2405
if hasPrepForm {
2447
2406
resetCaseDeclensionState ( )
0 commit comments