diff --git a/src/main/kotlin/com/marvinelsen/willow/domain/DictionaryEntry.kt b/src/main/kotlin/com/marvinelsen/willow/domain/DictionaryEntry.kt index d6ff31d..b0da205 100644 --- a/src/main/kotlin/com/marvinelsen/willow/domain/DictionaryEntry.kt +++ b/src/main/kotlin/com/marvinelsen/willow/domain/DictionaryEntry.kt @@ -8,4 +8,5 @@ data class DictionaryEntry( val zhuyin: String, val cedictDefinitions: List>, val crossStraitsDefinitions: List, + val moedictDefinitions: List, ) diff --git a/src/main/kotlin/com/marvinelsen/willow/domain/MoedictDefinition.kt b/src/main/kotlin/com/marvinelsen/willow/domain/MoedictDefinition.kt new file mode 100644 index 0000000..bd9442b --- /dev/null +++ b/src/main/kotlin/com/marvinelsen/willow/domain/MoedictDefinition.kt @@ -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 = emptyList(), + @SerialName("quote") val quotes: List = emptyList(), + val type: String? = null, + @SerialName("link") val links: List = emptyList(), + val synonyms: String? = null, + val antonyms: String? = null, +) diff --git a/src/main/kotlin/com/marvinelsen/willow/domain/SqliteDictionary.kt b/src/main/kotlin/com/marvinelsen/willow/domain/SqliteDictionary.kt index b1e0201..33cb18e 100644 --- a/src/main/kotlin/com/marvinelsen/willow/domain/SqliteDictionary.kt +++ b/src/main/kotlin/com/marvinelsen/willow/domain/SqliteDictionary.kt @@ -27,7 +27,7 @@ class SqliteDictionary(private val connection: Connection) : Dictionary { private val searchSimplifiedPreparedStatement: PreparedStatement by lazy { 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 WHERE simplified GLOB ? ORDER BY character_count ASC @@ -38,7 +38,7 @@ class SqliteDictionary(private val connection: Connection) : Dictionary { private val searchTraditionalPreparedStatement: PreparedStatement by lazy { 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 WHERE traditional GLOB ? ORDER BY character_count ASC @@ -49,7 +49,7 @@ class SqliteDictionary(private val connection: Connection) : Dictionary { private val searchPinyinPreparedStatement: PreparedStatement by lazy { 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 WHERE searchable_pinyin GLOB ? OR searchable_pinyin_with_tone_numbers GLOB ? @@ -60,7 +60,7 @@ class SqliteDictionary(private val connection: Connection) : Dictionary { private val searchSegments = """ 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 ON cte.segment = entry.traditional OR cte.segment = entry.simplified ORDER BY cte.id @@ -69,7 +69,7 @@ class SqliteDictionary(private val connection: Connection) : Dictionary { private val findWordsContaining: PreparedStatement by lazy { 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 WHERE traditional LIKE ? ORDER BY character_count ASC @@ -79,7 +79,7 @@ class SqliteDictionary(private val connection: Connection) : Dictionary { private val findCharacters = """ 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 ON cte.character = entry.traditional OR cte.character = entry.simplified ORDER BY cte.id @@ -169,6 +169,7 @@ private fun ResultSet.toDictionaryEntry() = DictionaryEntry( zhuyin = this.getString(5), cedictDefinitions = Json.decodeFromString(this.getString(6)), crossStraitsDefinitions = Json.decodeFromString(this.getString(7)), + moedictDefinitions = Json.decodeFromString(this.getString(8)), ) private fun ResultSet.toListOfDictionaryEntries() = buildList { diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/DictionaryEntryFx.kt b/src/main/kotlin/com/marvinelsen/willow/ui/DictionaryEntryFx.kt index b63512e..196f636 100644 --- a/src/main/kotlin/com/marvinelsen/willow/ui/DictionaryEntryFx.kt +++ b/src/main/kotlin/com/marvinelsen/willow/ui/DictionaryEntryFx.kt @@ -2,6 +2,7 @@ package com.marvinelsen.willow.ui import com.marvinelsen.willow.domain.CrossStraitsDefinition import com.marvinelsen.willow.domain.DictionaryEntry +import com.marvinelsen.willow.domain.MoedictDefinition import javafx.beans.property.SimpleStringProperty import javafx.beans.property.StringProperty import javafx.collections.FXCollections @@ -15,6 +16,7 @@ data class DictionaryEntryFx( val zhuyinProperty: StringProperty, val cedictDefinitions: ObservableList>, val crossStraitsDefinitions: ObservableList, + val moedictDefinitions: ObservableList, ) fun DictionaryEntry.toFx() = DictionaryEntryFx( @@ -24,7 +26,8 @@ fun DictionaryEntry.toFx() = DictionaryEntryFx( pinyinWithToneNumbersProperty = SimpleStringProperty(this.pinyinWithToneNumbers), zhuyinProperty = SimpleStringProperty(this.zhuyin), cedictDefinitions = FXCollections.observableList(this.cedictDefinitions), - crossStraitsDefinitions = FXCollections.observableList(this.crossStraitsDefinitions) + crossStraitsDefinitions = FXCollections.observableList(this.crossStraitsDefinitions), + moedictDefinitions = FXCollections.observableList(this.moedictDefinitions), ) fun DictionaryEntryFx.toDomain() = DictionaryEntry( @@ -34,5 +37,6 @@ fun DictionaryEntryFx.toDomain() = DictionaryEntry( pinyinWithToneNumbers = this.pinyinWithToneNumbersProperty.value, zhuyin = this.zhuyinProperty.value, cedictDefinitions = this.cedictDefinitions.toList(), - crossStraitsDefinitions = this.crossStraitsDefinitions.toList() + crossStraitsDefinitions = this.crossStraitsDefinitions.toList(), + moedictDefinitions = this.moedictDefinitions.toList(), ) diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt index 28a0b9f..e36d673 100644 --- a/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt +++ b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt @@ -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(",", "、")}" + } + } + } + } + } + } + } + } } } )