Compare commits
No commits in common. "f27ed7006df3f004267ef9628d5a38431f6b9bd1" and "bece46f89ccceb403c47ba8bc6dcbd08c3674faa" have entirely different histories.
f27ed7006d
...
bece46f89c
@ -18,9 +18,9 @@ jobs:
|
|||||||
java-version: 21
|
java-version: 21
|
||||||
- name: Setup Gradle
|
- name: Setup Gradle
|
||||||
uses: gradle/actions/setup-gradle@v4
|
uses: gradle/actions/setup-gradle@v4
|
||||||
- name: Lint
|
|
||||||
run: ./gradlew detekt
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: ./gradlew build testClasses -x check
|
run: ./gradlew build testClasses -x test -x detekt
|
||||||
|
- name: Detekt
|
||||||
|
run: ./gradlew detekt
|
||||||
- name: Test
|
- name: Test
|
||||||
run: ./gradlew test
|
run: ./gradlew test
|
@ -9,16 +9,11 @@ version = "1.0-SNAPSHOT"
|
|||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven {
|
|
||||||
url = uri("https://gitea.marvinelsen.com/api/packages/marvinelsen/maven")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
detektPlugins(libs.detekt.formatting)
|
detektPlugins(libs.detekt.formatting)
|
||||||
|
|
||||||
implementation("com.marvinelsen:chinese-transliteration:1.1-SNAPSHOT") { isChanging = true }
|
|
||||||
|
|
||||||
testImplementation(libs.kotest.core)
|
testImplementation(libs.kotest.core)
|
||||||
testImplementation(libs.kotest.assertions)
|
testImplementation(libs.kotest.assertions)
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
package com.marvinelsen.cedict.api
|
package com.marvinelsen.cedict.api
|
||||||
|
|
||||||
import com.marvinelsen.chinese.transliteration.Syllable
|
|
||||||
|
|
||||||
data class CedictEntry(
|
data class CedictEntry(
|
||||||
val traditional: String,
|
val traditional: String,
|
||||||
val simplified: String,
|
val simplified: String,
|
||||||
val pinyinSyllables: List<Syllable>,
|
val pinyinSyllables: List<PinyinSyllable>,
|
||||||
val definitions: List<CedictDefinition>,
|
val definitions: List<CedictDefinition>,
|
||||||
)
|
)
|
||||||
|
27
src/main/kotlin/com/marvinelsen/cedict/api/PinyinSyllable.kt
Normal file
27
src/main/kotlin/com/marvinelsen/cedict/api/PinyinSyllable.kt
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package com.marvinelsen.cedict.api
|
||||||
|
|
||||||
|
data class PinyinSyllable(
|
||||||
|
val syllable: String,
|
||||||
|
val tone: Tone,
|
||||||
|
) {
|
||||||
|
companion object {
|
||||||
|
fun fromString(pinyinWithNumbers: String): PinyinSyllable {
|
||||||
|
require(pinyinWithNumbers.isNotBlank()) { "Argument pinyinWithNumbers must not be blank." }
|
||||||
|
|
||||||
|
val lastCharacter = pinyinWithNumbers.last()
|
||||||
|
return if (lastCharacter.isDigit()) {
|
||||||
|
PinyinSyllable(
|
||||||
|
syllable = pinyinWithNumbers.substring(0, pinyinWithNumbers.lastIndex),
|
||||||
|
tone = Tone.fromDigit(lastCharacter)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
PinyinSyllable(
|
||||||
|
syllable = pinyinWithNumbers,
|
||||||
|
tone = Tone.NONE
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString() = syllable + tone.toString()
|
||||||
|
}
|
25
src/main/kotlin/com/marvinelsen/cedict/api/Tone.kt
Normal file
25
src/main/kotlin/com/marvinelsen/cedict/api/Tone.kt
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package com.marvinelsen.cedict.api
|
||||||
|
|
||||||
|
enum class Tone {
|
||||||
|
NONE, FIRST, SECOND, THIRD, FORTH, FIFTH;
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun fromDigit(digit: Char) = when (digit) {
|
||||||
|
'1' -> FIRST
|
||||||
|
'2' -> SECOND
|
||||||
|
'3' -> THIRD
|
||||||
|
'4' -> FORTH
|
||||||
|
'5' -> FIFTH
|
||||||
|
else -> error("Digit $digit is not a valid tone")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString() = when (this) {
|
||||||
|
NONE -> ""
|
||||||
|
FIRST -> "1"
|
||||||
|
SECOND -> "2"
|
||||||
|
THIRD -> "3"
|
||||||
|
FORTH -> "4"
|
||||||
|
FIFTH -> "5"
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,7 @@ package com.marvinelsen.cedict.internal
|
|||||||
import com.marvinelsen.cedict.api.CedictDefinition
|
import com.marvinelsen.cedict.api.CedictDefinition
|
||||||
import com.marvinelsen.cedict.api.CedictEntry
|
import com.marvinelsen.cedict.api.CedictEntry
|
||||||
import com.marvinelsen.cedict.api.CedictParser
|
import com.marvinelsen.cedict.api.CedictParser
|
||||||
import com.marvinelsen.chinese.transliteration.Syllable
|
import com.marvinelsen.cedict.api.PinyinSyllable
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
|
||||||
internal class CedictParserImpl : CedictParser {
|
internal class CedictParserImpl : CedictParser {
|
||||||
@ -42,9 +42,10 @@ internal class CedictParserImpl : CedictParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun toPinyinSyllables(pinyinWithNumbers: String) = pinyinWithNumbers
|
private fun toPinyinSyllables(pinyinWithNumbers: String) = pinyinWithNumbers
|
||||||
|
.lowercase()
|
||||||
|
.replace("u:", "ü")
|
||||||
.split(" ")
|
.split(" ")
|
||||||
.filter { Syllable.isValidPinyinWithToneNumberSyllable(it) }
|
.map { PinyinSyllable.fromString(it) }
|
||||||
.map { Syllable.fromPinyinWithToneNumber(it) }
|
|
||||||
|
|
||||||
private fun toCedictDefinitions(definitions: String) = definitions
|
private fun toCedictDefinitions(definitions: String) = definitions
|
||||||
.split(DEFINITION_SEPARATOR)
|
.split(DEFINITION_SEPARATOR)
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package com.marvinelsen.cedict.internal
|
package com.marvinelsen.cedict.internal
|
||||||
|
|
||||||
import com.marvinelsen.cedict.api.CedictDefinition
|
import com.marvinelsen.cedict.api.CedictDefinition
|
||||||
import com.marvinelsen.chinese.transliteration.Syllable
|
import com.marvinelsen.cedict.api.PinyinSyllable
|
||||||
import com.marvinelsen.chinese.transliteration.Tone
|
import com.marvinelsen.cedict.api.Tone
|
||||||
import io.kotest.core.spec.style.ShouldSpec
|
import io.kotest.core.spec.style.ShouldSpec
|
||||||
import io.kotest.matchers.shouldBe
|
import io.kotest.matchers.shouldBe
|
||||||
import java.util.zip.GZIPInputStream
|
import java.util.zip.GZIPInputStream
|
||||||
@ -16,8 +16,8 @@ class CedictParserImplTest : ShouldSpec({
|
|||||||
cedictEntry.traditional shouldBe "皮實"
|
cedictEntry.traditional shouldBe "皮實"
|
||||||
cedictEntry.simplified shouldBe "皮实"
|
cedictEntry.simplified shouldBe "皮实"
|
||||||
cedictEntry.pinyinSyllables shouldBe listOf(
|
cedictEntry.pinyinSyllables shouldBe listOf(
|
||||||
Syllable("pi", Tone.SECOND),
|
PinyinSyllable("pi", Tone.SECOND),
|
||||||
Syllable("shi", Tone.FIFTH)
|
PinyinSyllable("shi", Tone.FIFTH)
|
||||||
)
|
)
|
||||||
cedictEntry.definitions shouldBe listOf(
|
cedictEntry.definitions shouldBe listOf(
|
||||||
CedictDefinition(listOf("(of things) durable")),
|
CedictDefinition(listOf("(of things) durable")),
|
||||||
|
Loading…
Reference in New Issue
Block a user