Add moedict definitions
Some checks failed
Pull Request / build (pull_request) Failing after 2m47s

This commit is contained in:
Marvin Elsen 2024-10-09 23:17:48 +02:00
parent 86aa108e52
commit cf07585361
Signed by: marvinelsen
GPG Key ID: 820672408CC318C2
5 changed files with 79 additions and 8 deletions

View File

@ -8,4 +8,5 @@ data class DictionaryEntry(
val zhuyin: String, val zhuyin: String,
val cedictDefinitions: List<List<String>>, val cedictDefinitions: List<List<String>>,
val crossStraitsDefinitions: List<CrossStraitsDefinition>, val crossStraitsDefinitions: List<CrossStraitsDefinition>,
val moedictDefinitions: List<MoedictDefinition>,
) )

View File

@ -0,0 +1,15 @@
package com.marvinelsen.willow.domain
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class MoedictDefinition(
@SerialName("def") val definition: String,
@SerialName("example") val examples: List<String> = emptyList(),
@SerialName("quote") val quotes: List<String> = emptyList(),
val type: String? = null,
@SerialName("link") val links: List<String> = emptyList(),
val synonyms: String? = null,
val antonyms: String? = null,
)

View File

@ -27,7 +27,7 @@ class SqliteDictionary(private val connection: Connection) : Dictionary {
private val searchSimplifiedPreparedStatement: PreparedStatement by lazy { private val searchSimplifiedPreparedStatement: PreparedStatement by lazy {
connection.prepareStatement( connection.prepareStatement(
""" """
SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions
FROM entry FROM entry
WHERE simplified GLOB ? WHERE simplified GLOB ?
ORDER BY character_count ASC ORDER BY character_count ASC
@ -38,7 +38,7 @@ class SqliteDictionary(private val connection: Connection) : Dictionary {
private val searchTraditionalPreparedStatement: PreparedStatement by lazy { private val searchTraditionalPreparedStatement: PreparedStatement by lazy {
connection.prepareStatement( connection.prepareStatement(
""" """
SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions
FROM entry FROM entry
WHERE traditional GLOB ? WHERE traditional GLOB ?
ORDER BY character_count ASC ORDER BY character_count ASC
@ -49,7 +49,7 @@ class SqliteDictionary(private val connection: Connection) : Dictionary {
private val searchPinyinPreparedStatement: PreparedStatement by lazy { private val searchPinyinPreparedStatement: PreparedStatement by lazy {
connection.prepareStatement( connection.prepareStatement(
""" """
SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions
FROM entry FROM entry
WHERE searchable_pinyin GLOB ? WHERE searchable_pinyin GLOB ?
OR searchable_pinyin_with_tone_numbers GLOB ? OR searchable_pinyin_with_tone_numbers GLOB ?
@ -60,7 +60,7 @@ class SqliteDictionary(private val connection: Connection) : Dictionary {
private val searchSegments = """ private val searchSegments = """
WITH cte(id, segment) AS (VALUES ?) WITH cte(id, segment) AS (VALUES ?)
SELECT entry.traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions SELECT entry.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.segment = entry.traditional OR cte.segment = entry.simplified ON cte.segment = entry.traditional OR cte.segment = entry.simplified
ORDER BY cte.id ORDER BY cte.id
@ -69,7 +69,7 @@ class SqliteDictionary(private val connection: Connection) : Dictionary {
private val findWordsContaining: PreparedStatement by lazy { private val findWordsContaining: PreparedStatement by lazy {
connection.prepareStatement( connection.prepareStatement(
""" """
SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions
FROM entry FROM entry
WHERE traditional LIKE ? WHERE traditional LIKE ?
ORDER BY character_count ASC ORDER BY character_count ASC
@ -79,7 +79,7 @@ class SqliteDictionary(private val connection: Connection) : Dictionary {
private val findCharacters = """ private val findCharacters = """
WITH cte(id, character) AS (VALUES ?) WITH cte(id, character) AS (VALUES ?)
SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_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
ORDER BY cte.id ORDER BY cte.id
@ -169,6 +169,7 @@ private fun ResultSet.toDictionaryEntry() = DictionaryEntry(
zhuyin = this.getString(5), zhuyin = this.getString(5),
cedictDefinitions = Json.decodeFromString(this.getString(6)), cedictDefinitions = Json.decodeFromString(this.getString(6)),
crossStraitsDefinitions = Json.decodeFromString(this.getString(7)), crossStraitsDefinitions = Json.decodeFromString(this.getString(7)),
moedictDefinitions = Json.decodeFromString(this.getString(8)),
) )
private fun ResultSet.toListOfDictionaryEntries() = buildList { private fun ResultSet.toListOfDictionaryEntries() = buildList {

View File

@ -2,6 +2,7 @@ package com.marvinelsen.willow.ui
import com.marvinelsen.willow.domain.CrossStraitsDefinition import com.marvinelsen.willow.domain.CrossStraitsDefinition
import com.marvinelsen.willow.domain.DictionaryEntry import com.marvinelsen.willow.domain.DictionaryEntry
import com.marvinelsen.willow.domain.MoedictDefinition
import javafx.beans.property.SimpleStringProperty import javafx.beans.property.SimpleStringProperty
import javafx.beans.property.StringProperty import javafx.beans.property.StringProperty
import javafx.collections.FXCollections import javafx.collections.FXCollections
@ -15,6 +16,7 @@ data class DictionaryEntryFx(
val zhuyinProperty: StringProperty, val zhuyinProperty: StringProperty,
val cedictDefinitions: ObservableList<List<String>>, val cedictDefinitions: ObservableList<List<String>>,
val crossStraitsDefinitions: ObservableList<CrossStraitsDefinition>, val crossStraitsDefinitions: ObservableList<CrossStraitsDefinition>,
val moedictDefinitions: ObservableList<MoedictDefinition>,
) )
fun DictionaryEntry.toFx() = DictionaryEntryFx( fun DictionaryEntry.toFx() = DictionaryEntryFx(
@ -24,7 +26,8 @@ fun DictionaryEntry.toFx() = DictionaryEntryFx(
pinyinWithToneNumbersProperty = SimpleStringProperty(this.pinyinWithToneNumbers), pinyinWithToneNumbersProperty = SimpleStringProperty(this.pinyinWithToneNumbers),
zhuyinProperty = SimpleStringProperty(this.zhuyin), zhuyinProperty = SimpleStringProperty(this.zhuyin),
cedictDefinitions = FXCollections.observableList(this.cedictDefinitions), cedictDefinitions = FXCollections.observableList(this.cedictDefinitions),
crossStraitsDefinitions = FXCollections.observableList(this.crossStraitsDefinitions) crossStraitsDefinitions = FXCollections.observableList(this.crossStraitsDefinitions),
moedictDefinitions = FXCollections.observableList(this.moedictDefinitions),
) )
fun DictionaryEntryFx.toDomain() = DictionaryEntry( fun DictionaryEntryFx.toDomain() = DictionaryEntry(
@ -34,5 +37,6 @@ fun DictionaryEntryFx.toDomain() = DictionaryEntry(
pinyinWithToneNumbers = this.pinyinWithToneNumbersProperty.value, pinyinWithToneNumbers = this.pinyinWithToneNumbersProperty.value,
zhuyin = this.zhuyinProperty.value, zhuyin = this.zhuyinProperty.value,
cedictDefinitions = this.cedictDefinitions.toList(), cedictDefinitions = this.cedictDefinitions.toList(),
crossStraitsDefinitions = this.crossStraitsDefinitions.toList() crossStraitsDefinitions = this.crossStraitsDefinitions.toList(),
moedictDefinitions = this.moedictDefinitions.toList(),
) )

View File

@ -230,6 +230,56 @@ class DetailsController(private val model: Model, private val config: Config) {
} }
} }
} }
if (newEntry.moedictDefinitions.isNotEmpty()) {
div(classes = "moe-definition") {
h1 {
+"MOE"
}
newEntry.moedictDefinitions.groupBy {
it.type ?: ""
}.entries.forEach { (type, definitions) ->
if (type != "") {
span(classes = "type") {
+type
}
}
ol {
definitions.forEach { definition ->
li {
span(classes = "definition") {
+definition.definition
}
definition.examples.forEach { example ->
span(classes = "example") {
+example
}
}
definition.quotes.forEach { quote ->
span(classes = "quote") {
+quote
}
}
definition.synonyms?.let {
span(classes = "synonyms") {
+"似:${it.replace(",", "、")}"
}
}
definition.antonyms?.let {
span(classes = "antonyms") {
+"反:${it.replace(",", "、")}"
}
}
}
}
}
}
}
}
} }
} }
) )