This commit is contained in:
parent
86aa108e52
commit
cf07585361
@ -8,4 +8,5 @@ data class DictionaryEntry(
|
||||
val zhuyin: String,
|
||||
val cedictDefinitions: List<List<String>>,
|
||||
val crossStraitsDefinitions: List<CrossStraitsDefinition>,
|
||||
val moedictDefinitions: List<MoedictDefinition>,
|
||||
)
|
||||
|
@ -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,
|
||||
)
|
@ -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 {
|
||||
|
@ -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<List<String>>,
|
||||
val crossStraitsDefinitions: ObservableList<CrossStraitsDefinition>,
|
||||
val moedictDefinitions: ObservableList<MoedictDefinition>,
|
||||
)
|
||||
|
||||
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(),
|
||||
)
|
||||
|
@ -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(",", "、")}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user