feat: 中文简繁处理库换成 HanLP 极大提升性能和效果

Signed-off-by: hingbong <hingbonglo@gmail.com>
pull/192/head
hingbong 5 years ago
parent 8ddda38c75
commit 4621da9739
  1. 2
      app/build.gradle
  2. 6
      app/src/main/java/io/legado/app/help/BookHelp.kt
  3. 6
      app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
  4. 6
      app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt

@ -191,7 +191,7 @@ dependencies {
implementation 'ru.noties.markwon:core:3.1.0' implementation 'ru.noties.markwon:core:3.1.0'
// //
implementation 'com.github.houbb:opencc4j:1.4.0' implementation 'com.hankcs:hanlp:portable-1.7.7'
} }

@ -1,6 +1,6 @@
package io.legado.app.help package io.legado.app.help
import com.github.houbb.opencc4j.core.impl.ZhConvertBootstrap import com.hankcs.hanlp.HanLP
import io.legado.app.App import io.legado.app.App
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
@ -233,8 +233,8 @@ object BookHelp {
} }
try { try {
when (AppConfig.chineseConverterType) { when (AppConfig.chineseConverterType) {
1 -> c = ZhConvertBootstrap.newInstance().toSimple(c) 1 -> c = HanLP.convertToSimplifiedChinese(c)
2 -> c = ZhConvertBootstrap.newInstance().toTraditional(c) 2 -> c = HanLP.convertToTraditionalChinese(c)
} }
} catch (e: Exception) { } catch (e: Exception) {
withContext(Main) { withContext(Main) {

@ -5,7 +5,7 @@ import android.content.Context
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.view.MotionEvent import android.view.MotionEvent
import android.widget.FrameLayout import android.widget.FrameLayout
import com.github.houbb.opencc4j.core.impl.ZhConvertBootstrap import com.hankcs.hanlp.HanLP
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.AppConst.timeFormat import io.legado.app.constant.AppConst.timeFormat
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
@ -119,8 +119,8 @@ class ContentView(context: Context) : FrameLayout(context) {
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
fun setProgress(textPage: TextPage) = textPage.apply { fun setProgress(textPage: TextPage) = textPage.apply {
val title = when (AppConfig.chineseConverterType) { val title = when (AppConfig.chineseConverterType) {
1 -> ZhConvertBootstrap.newInstance().toSimple(textPage.title) 1 -> HanLP.convertToSimplifiedChinese(textPage.title)
2 -> ZhConvertBootstrap.newInstance().toTraditional(textPage.title) 2 -> HanLP.convertToTraditionalChinese(textPage.title)
else -> textPage.title else -> textPage.title
} }
if (ReadBookConfig.hideStatusBar) { if (ReadBookConfig.hideStatusBar) {

@ -2,7 +2,7 @@ package io.legado.app.ui.welcome
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import com.github.houbb.opencc4j.util.ZhConverterUtil import com.hankcs.hanlp.HanLP
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseActivity import io.legado.app.base.BaseActivity
@ -37,8 +37,8 @@ open class WelcomeActivity : BaseActivity(R.layout.activity_welcome) {
.clearExpired(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1)) .clearExpired(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1))
//初始化简繁转换引擎 //初始化简繁转换引擎
when (AppConfig.chineseConverterType) { when (AppConfig.chineseConverterType) {
1 -> ZhConverterUtil.toSimple("初始化") 1 -> HanLP.convertToSimplifiedChinese("初始化")
2 -> ZhConverterUtil.toTraditional("初始化") 2 -> HanLP.convertToTraditionalChinese("初始化")
else -> null else -> null
} }
} }

Loading…
Cancel
Save