Implement find characters query

This commit is contained in:
Marvin Elsen 2024-09-21 18:03:58 +02:00
parent cfaff6c6b9
commit a88b4d409d
Signed by: marvinelsen
GPG Key ID: 820672408CC318C2
2 changed files with 22 additions and 1 deletions

View File

@ -20,9 +20,15 @@ fun main() {
val (shangWords, time3) = measureTimedValue {
sqliteDictionary.findWordsContaining(shang)
}
val (characters, time4) = measureTimedValue {
val searchi = sqliteDictionary.search("師範大學", SearchMode.TRADITIONAL).first()
sqliteDictionary.findCharacters(searchi)
}
println(searchResults)
println(shangWords)
println(characters)
println(time)
println(time2)
println(time3)
println(time4)
}

View File

@ -53,6 +53,12 @@ class SqliteDictionary(private val connection: Connection) : Dictionary {
)
}
private val findCharacters = """
SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, definitions
FROM cedict
WHERE traditional IN (?)
""".trimIndent()
override fun search(query: String, searchMode: SearchMode) = when (searchMode) {
SearchMode.PINYIN -> searchPinyin(query)
SearchMode.SIMPLIFIED -> searchSimplified(query)
@ -73,7 +79,16 @@ class SqliteDictionary(private val connection: Connection) : Dictionary {
}
override fun findCharacters(entry: DictionaryEntry): List<DictionaryEntry> {
return emptyList()
val characterList = entry.traditional
.split("")
.filter { it.isNotBlank() }
.joinToString(",") { "'$it'" }
val query = findCharacters.replace("?", characterList)
val resultSet: ResultSet = connection.createStatement().executeQuery(query)
return resultSet.toListOfDictionaryEntries()
}
private fun searchSimplified(query: String): List<DictionaryEntry> {