From d9e3cb0eeac07c7398c37c5ef21146dfebdb4c37 Mon Sep 17 00:00:00 2001 From: Andrew Tavis McAllister Date: Sun, 16 Apr 2023 12:45:05 +0200 Subject: [PATCH] #96 remove repeat nouns and keep capitalized/upper versions --- Keyboards/KeyboardsBase/LoadData.swift | 46 +++++++++++++++----------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/Keyboards/KeyboardsBase/LoadData.swift b/Keyboards/KeyboardsBase/LoadData.swift index 5d1b7485..dce6b544 100644 --- a/Keyboards/KeyboardsBase/LoadData.swift +++ b/Keyboards/KeyboardsBase/LoadData.swift @@ -157,24 +157,7 @@ func createAutocompleteLexicon() { let createLexiconQuery = """ INSERT INTO autocomplete_lexicon (word) - SELECT DISTINCT - -- Select an upper case or capitalized noun if it's available. - CASE - WHEN - UPPER(full_lexicon.word) = nouns.noun - THEN - nouns.noun - - WHEN - UPPER(SUBSTR(full_lexicon.word, 1, 1)) || SUBSTR(full_lexicon.word, 2) = nouns.noun - THEN - nouns.noun - - ELSE - full_lexicon.word - END - - FROM ( + WITH full_lexicon AS ( SELECT noun AS word FROM @@ -206,9 +189,29 @@ func createAutocompleteLexicon() { word AS word FROM emoji_keywords - ) AS full_lexicon + ) + + SELECT DISTINCT + -- Select an upper case or capitalized noun if it's available. + CASE + WHEN + UPPER(full_lexicon.word) = nouns.noun + THEN + nouns.noun + + WHEN + UPPER(SUBSTR(full_lexicon.word, 1, 1)) || SUBSTR(full_lexicon.word, 2) = nouns.noun + THEN + nouns.noun + + ELSE + full_lexicon.word + END + + FROM + full_lexicon - LEFT JOIN + JOIN nouns ON @@ -217,6 +220,9 @@ func createAutocompleteLexicon() { WHERE LENGTH(full_lexicon.word) > 1 AND full_lexicon.word NOT LIKE '%-%' + AND full_lexicon.word NOT LIKE '%/%' + AND full_lexicon.word NOT LIKE '%(%' + AND full_lexicon.word NOT LIKE '%)%' """ do { try languageDB.write { db in