This commit is contained in:
Horis
2025-02-12 19:13:02 +08:00
parent c4a3d12e82
commit c1e555c654
3 changed files with 13 additions and 68 deletions
@@ -2,8 +2,6 @@ package io.legado.app.utils
import com.github.liuyueyi.quick.transfer.ChineseUtils
import com.github.liuyueyi.quick.transfer.constants.TransType
import com.github.liuyueyi.quick.transfer.dictionary.BasicDictionary
import com.github.liuyueyi.quick.transfer.dictionary.DictionaryContainer
object ChineseUtils {
@@ -15,7 +13,6 @@ object ChineseUtils {
fun t2s(content: String): String {
if (!fixed) {
fixed = true
fixT2sDict()
}
return ChineseUtils.t2s(content)
@@ -30,29 +27,18 @@ object ChineseUtils {
}
fun fixT2sDict() {
val dict = DictionaryContainer.getInstance().getDictionary(TransType.TRADITIONAL_TO_SIMPLE)
dict.run {
remove(
"", "", "",
"支援", "沈默", "類比", "模擬", "划槳", "列根", "先進", "雪梨", "雪糕",
"零錢", "零钱", "離線", "碟片", "模組", "桌球", "案頭", "機車", "電漿",
"鳳梨", "魔戒", "載入", "菲林", "整合",
"路易斯", "非同步", "出租车", "周杰倫", "马铃薯", "馬鈴薯", "機械人", "電單車",
"電扶梯", "音效卡", "飆車族", "點陣圖", "個入球", "顆進球",
"獸紀元", "高空彈跳", "铁达尼号",
"魔鬼終結者", "純文字檔案"
)
}
}
fun BasicDictionary.remove(vararg keys: String) {
for (key in keys) {
if (key.length == 1) {
chars.remove(key[0])
} else {
dict.remove(key)
}
}
fixed = true
val excludeList = listOf(
"",
"划槳", "列根", "雪梨", "雪糕",
"零錢", "零钱", "離線", "碟片", "模組", "桌球", "案頭", "機車", "電漿",
"鳳梨", "魔戒", "載入", "菲林", "整合", "變數",
"路易斯", "非同步", "出租车", "周杰倫", "马铃薯", "馬鈴薯", "機械人", "電單車",
"電扶梯", "音效卡", "飆車族", "點陣圖", "個入球", "顆進球",
"魔獸紀元", "高空彈跳", "铁达尼号",
"鬼終結者", "純文字檔案"
)
ChineseUtils.loadExcludeDict(TransType.TRADITIONAL_TO_SIMPLE, excludeList)
}
}
@@ -1,41 +0,0 @@
package io.legado.app.utils
import com.github.liuyueyi.quick.transfer.Trie
import com.github.liuyueyi.quick.transfer.TrieNode
import java.util.HashMap
fun <T> Trie<T>.getRoot(): TrieNode<T> {
val rootField = javaClass.getDeclaredField("root")
.apply { isAccessible = true }
@Suppress("UNCHECKED_CAST")
return rootField.get(this) as TrieNode<T>
}
fun <T> TrieNode<T>.getChildren(): HashMap<Char, TrieNode<T>> {
val childrenField = javaClass.getDeclaredField("children")
.apply { isAccessible = true }
@Suppress("UNCHECKED_CAST")
return childrenField.get(this) as HashMap<Char, TrieNode<T>>
}
fun <T> Trie<T>.remove(value: String) {
kotlin.runCatching {
var node = getRoot()
val nodes = arrayListOf<TrieNode<T>>()
val chars = value.toCharArray()
for (c in chars) {
nodes.add(node)
node = node.getChildren()[c] ?: break
if (!node.isLeaf) {
continue
}
for ((ch, n) in chars.reversed().zip(nodes.reversed())) {
val children = n.getChildren()
children.remove(ch)
if (children.isNotEmpty()) {
break
}
}
}
}
}
+1 -1
View File
@@ -34,7 +34,7 @@ nanoHttpd = "2.3.1"
okhttp = "4.12.0"
preference = "1.2.1"
protobufJavalite = "4.26.1"
quickChineseTransfer = "0.2.15"
quickChineseTransfer = "0.2.16"
room = "2.6.1"
splitties = "3.0.0"
rhino = "1.8.0"