Store tones for each entry

This commit is contained in:
Marvin Elsen 2024-10-14 18:55:13 +02:00
parent 9f60c4c9b2
commit 849bdb8c1a
Signed by: marvinelsen
GPG Key ID: 820672408CC318C2

View File

@ -42,6 +42,7 @@ fun main() {
cross_straits_definitions JSON NOT NULL, cross_straits_definitions JSON NOT NULL,
moe_definitions JSON NOT NULL, moe_definitions JSON NOT NULL,
character_count INTEGER NOT NULL, character_count INTEGER NOT NULL,
tones JSON NOT NULL,
CONSTRAINT character_count_gte CHECK(character_count > 0) CONSTRAINT character_count_gte CHECK(character_count > 0)
); );
""".trimIndent() """.trimIndent()
@ -62,7 +63,7 @@ fun main() {
val insertStatement = val insertStatement =
connection.prepareStatement( connection.prepareStatement(
"INSERT OR IGNORE INTO entry(traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, searchable_pinyin, searchable_pinyin_with_tone_numbers, cedict_definitions, cross_straits_definitions, moe_definitions, character_count) VALUES(?,?,?,?,?,?,?,?,?,?,?)" "INSERT OR IGNORE INTO entry(traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, searchable_pinyin, searchable_pinyin_with_tone_numbers, cedict_definitions, cross_straits_definitions, moe_definitions, character_count, tones) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)"
) )
cedictEntries.groupBy { cedictEntries.groupBy {
"${it.traditional}${it.pinyinSyllables.joinToString( "${it.traditional}${it.pinyinSyllables.joinToString(
@ -135,6 +136,13 @@ fun main() {
) )
) )
insertStatement.setInt(11, entry.traditional.length) insertStatement.setInt(11, entry.traditional.length)
insertStatement.setString(
12,
Json.encodeToString(
ListSerializer(Int.serializer()),
entry.pinyinSyllables.map { it.tone.toInt() }
)
)
} catch (_: Exception) { } catch (_: Exception) {
// no-op // no-op
} }
@ -156,7 +164,7 @@ fun main() {
private fun createCrossStraitsEntries(connection: Connection) { private fun createCrossStraitsEntries(connection: Connection) {
val insertStatement = val insertStatement =
connection.prepareStatement( connection.prepareStatement(
"INSERT OR IGNORE INTO entry(traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, searchable_pinyin, searchable_pinyin_with_tone_numbers, cedict_definitions, cross_straits_definitions, moe_definitions, character_count) VALUES(?,?,?,?,?,?,?,?,?,?,?)" "INSERT OR IGNORE INTO entry(traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, searchable_pinyin, searchable_pinyin_with_tone_numbers, cedict_definitions, cross_straits_definitions, moe_definitions, character_count, tones) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)"
) )
val updateStatement = connection.prepareStatement( val updateStatement = connection.prepareStatement(
@ -238,6 +246,13 @@ private fun createCrossStraitsEntries(connection: Connection) {
) )
) )
insertStatement.setInt(11, entry.traditional.length) insertStatement.setInt(11, entry.traditional.length)
insertStatement.setString(
12,
Json.encodeToString(
ListSerializer(Int.serializer()),
pronunciation.map { it.tone.toInt() }
)
)
} catch (_: Exception) { } catch (_: Exception) {
// no-op // no-op
} }
@ -256,7 +271,7 @@ private fun createCrossStraitsEntries(connection: Connection) {
private fun createMoedictEntries(connection: Connection) { private fun createMoedictEntries(connection: Connection) {
val insertStatement = val insertStatement =
connection.prepareStatement( connection.prepareStatement(
"INSERT OR IGNORE INTO entry(traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, searchable_pinyin, searchable_pinyin_with_tone_numbers, cedict_definitions, cross_straits_definitions, moe_definitions, character_count) VALUES(?,?,?,?,?,?,?,?,?,?,?)" "INSERT OR IGNORE INTO entry(traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, searchable_pinyin, searchable_pinyin_with_tone_numbers, cedict_definitions, cross_straits_definitions, moe_definitions, character_count, tones) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)"
) )
val updateStatement = connection.prepareStatement( val updateStatement = connection.prepareStatement(
@ -356,6 +371,13 @@ private fun createMoedictEntries(connection: Connection) {
) )
) )
insertStatement.setInt(11, traditional.length) insertStatement.setInt(11, traditional.length)
insertStatement.setString(
12,
Json.encodeToString(
ListSerializer(Int.serializer()),
pronunciation.map { it.tone.toInt() }
)
)
} catch (_: Exception) { } catch (_: Exception) {
// no-op // no-op
} }