-
Notifications
You must be signed in to change notification settings - Fork 12
/
JMnedictJsonElement.kt
61 lines (53 loc) · 1.75 KB
/
JMnedictJsonElement.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package org.edrdg.jmdict.simplified.conversion.jmnedict
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.edrdg.jmdict.simplified.conversion.CommonJsonElement
import org.edrdg.jmdict.simplified.conversion.OutputDictionaryEntry
sealed class JMnedictJsonElement : CommonJsonElement() {
@Serializable
data class Word(
val id: String,
val kanji: List<Kanji>,
val kana: List<Kana>,
val translation: List<Translation>,
) : OutputDictionaryEntry<Word> {
override val allLanguages: Set<String>
get() = translation
.flatMap { translation -> translation.translation.map { it.lang } }
.toSet()
override fun onlyWithLanguages(languages: Set<String>): Word =
copy(
translation = translation.map { t ->
t.copy(
translation = t.translation.filter {
languages.contains(it.lang) || languages.contains("all")
}
)
}.filter { it.translation.isNotEmpty() }
)
override fun toJsonString() = Json.encodeToString(this)
}
@Serializable
data class Kanji(
val text: String,
val tags: List<Tag>,
)
@Serializable
data class Kana(
val text: String,
val tags: List<Tag>,
val appliesToKanji: List<String>,
)
@Serializable
data class Translation(
val type: List<Tag>,
val related: List<Xref>,
val translation: List<TranslationText>,
)
@Serializable
data class TranslationText(
val lang: String,
val text: String,
)
}