From b22e436f8b00df2d5aecc6e5b26119cf8039ef43 Mon Sep 17 00:00:00 2001 From: Marvin Elsen Date: Mon, 11 Nov 2024 20:39:10 +0100 Subject: [PATCH] Receive tones from database --- .../marvinelsen/willow/domain/SqliteDictionary.kt | 15 ++++++++------- .../willow/domain/entities/DictionaryEntry.kt | 1 + 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/com/marvinelsen/willow/domain/SqliteDictionary.kt b/src/main/kotlin/com/marvinelsen/willow/domain/SqliteDictionary.kt index f50bbd5..c8d7b2f 100644 --- a/src/main/kotlin/com/marvinelsen/willow/domain/SqliteDictionary.kt +++ b/src/main/kotlin/com/marvinelsen/willow/domain/SqliteDictionary.kt @@ -31,21 +31,21 @@ class SqliteDictionary(private val connection: Connection) : Dictionary { .posData(SegmentPosDatas.define()) private val searchSimplifiedSql = """ - SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions + SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions, tones FROM entry WHERE simplified GLOB ? ORDER BY character_count ASC """.trimIndent() private val searchTraditionalSql = """ - SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions + SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions, tones FROM entry WHERE traditional GLOB ? ORDER BY character_count ASC """.trimIndent() private val searchPinyinSql = """ - SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions + SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions, tones FROM entry WHERE searchable_pinyin GLOB ? OR searchable_pinyin_with_tone_numbers GLOB ? @@ -54,21 +54,21 @@ class SqliteDictionary(private val connection: Connection) : Dictionary { private val searchSegmentsSql = """ WITH cte(id, segment) AS (VALUES ?) - SELECT entry.traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions + SELECT entry.traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions, tones FROM entry INNER JOIN cte ON cte.segment = entry.traditional OR cte.segment = entry.simplified ORDER BY cte.id """.trimIndent() private val findWordsBeginningSql = """ - SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions + SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions, tones FROM entry WHERE traditional GLOB ? ORDER BY character_count ASC """.trimIndent() private val findWordsContainingSql = """ - SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions + SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions, tones FROM entry WHERE traditional LIKE ? ORDER BY character_count ASC @@ -76,7 +76,7 @@ class SqliteDictionary(private val connection: Connection) : Dictionary { private val findCharactersSql = """ WITH cte(id, character, pinyin) AS (VALUES ?) - SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions + SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions, tones FROM entry INNER JOIN cte ON cte.character = entry.traditional WHERE cte.pinyin = entry.pinyin_with_tone_numbers @@ -214,6 +214,7 @@ private fun ResultSet.toDictionaryEntry() = DictionaryEntry( cedictDefinitions = Json.decodeFromString(this.getString(6)), crossStraitsDefinitions = Json.decodeFromString(this.getString(7)), moedictDefinitions = Json.decodeFromString(this.getString(8)), + tones = Json.decodeFromString(this.getString(9)), ) private fun ResultSet.toListOfDictionaryEntries() = buildList { diff --git a/src/main/kotlin/com/marvinelsen/willow/domain/entities/DictionaryEntry.kt b/src/main/kotlin/com/marvinelsen/willow/domain/entities/DictionaryEntry.kt index ad11b91..2d3619a 100644 --- a/src/main/kotlin/com/marvinelsen/willow/domain/entities/DictionaryEntry.kt +++ b/src/main/kotlin/com/marvinelsen/willow/domain/entities/DictionaryEntry.kt @@ -12,4 +12,5 @@ data class DictionaryEntry( val cedictDefinitions: List>, val crossStraitsDefinitions: List, val moedictDefinitions: List, + val tones: List, )