Improve find characters query to only show characters with the same pronunciation
Some checks failed
Pull Request / build (pull_request) Failing after 2m42s
Some checks failed
Pull Request / build (pull_request) Failing after 2m42s
This commit is contained in:
parent
af3a291536
commit
ea1973a3cf
@ -78,10 +78,11 @@ class SqliteDictionary(private val connection: Connection) : Dictionary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val findCharacters = """
|
private val findCharacters = """
|
||||||
WITH cte(id, character) AS (VALUES ?)
|
WITH cte(id, character, syllable) 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
|
||||||
FROM entry INNER JOIN cte
|
FROM entry INNER JOIN cte
|
||||||
ON cte.character = entry.traditional OR cte.character = entry.simplified
|
ON cte.character = entry.traditional OR cte.character = entry.simplified
|
||||||
|
WHERE cte.syllable = entry.pinyin_with_tone_numbers
|
||||||
ORDER BY cte.id
|
ORDER BY cte.id
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
|
|
||||||
@ -105,13 +106,24 @@ class SqliteDictionary(private val connection: Connection) : Dictionary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun findCharacters(entry: DictionaryEntry): List<DictionaryEntry> {
|
override fun findCharacters(entry: DictionaryEntry): List<DictionaryEntry> {
|
||||||
val characterList = entry.traditional
|
val pinyinSyllablesWithToneNumbers = entry.pinyinWithToneNumbers
|
||||||
|
.lowercase()
|
||||||
|
.split(" ")
|
||||||
|
.filter { it.isNotBlank() }
|
||||||
|
|
||||||
|
val characters = entry.traditional
|
||||||
.split("")
|
.split("")
|
||||||
.filter { it.isNotBlank() }
|
.filter { it.isNotBlank() }
|
||||||
.mapIndexed { index, s -> "($index, '$s')" }
|
.filter { it != "," }
|
||||||
|
.filter { it != "·" }
|
||||||
|
|
||||||
|
val charactersWithSyllables = characters.zip(pinyinSyllablesWithToneNumbers)
|
||||||
|
|
||||||
|
val queryInput = charactersWithSyllables
|
||||||
|
.mapIndexed { index, s -> "($index, '${s.first}', '${s.second}')" }
|
||||||
.joinToString(",")
|
.joinToString(",")
|
||||||
|
|
||||||
val query = findCharacters.replace("?", characterList)
|
val query = findCharacters.replace("?", queryInput)
|
||||||
|
|
||||||
val resultSet: ResultSet = connection.createStatement().executeQuery(query)
|
val resultSet: ResultSet = connection.createStatement().executeQuery(query)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user