From 79ddeec20d04cad8e6bf7082bd176afac95504a0 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 13 Dec 2020 09:56:11 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/BookHelp.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 6ae431662..6b8dffb31 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -68,16 +68,16 @@ object BookHelp { content.split("\n").forEach { val matcher = AppPattern.imgPattern.matcher(it) if (matcher.find()) { - var src = matcher.group(1) - src = NetworkUtils.getAbsoluteURL(bookChapter.url, src) - src?.let { - saveImage(book, src) + matcher.group(1)?.let { src -> + val mSrc = NetworkUtils.getAbsoluteURL(bookChapter.url, src) + saveImage(book, mSrc) } } } postEvent(EventBus.SAVE_CONTENT, bookChapter) } + @Suppress("unused") fun saveFont(book: Book, bookChapter: BookChapter, font: ByteArray) { FileUtils.createFileIfNotExist( downloadDir, From 74454371abd2afcf6f9182603e70a3faba95cd4d Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 13 Dec 2020 10:09:24 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 3 --- app/src/main/java/io/legado/app/help/BookHelp.kt | 10 ++++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 0772e219c..74a7b5b01 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -192,9 +192,6 @@ dependencies { //apache implementation 'org.apache.commons:commons-text:1.9' - //字符串比较 - implementation 'net.ricecode:string-similarity:1.0.0' - //MarkDown implementation 'io.noties.markwon:core:4.6.0' implementation 'io.noties.markwon:image-glide:4.6.0' diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 6b8dffb31..c8fad6f6e 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -10,8 +10,7 @@ import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.localBook.LocalBook import io.legado.app.utils.* import kotlinx.coroutines.delay -import net.ricecode.similarity.JaroWinklerStrategy -import net.ricecode.similarity.StringSimilarityServiceImpl +import org.apache.commons.text.similarity.JaccardSimilarity import java.io.File import java.util.concurrent.CopyOnWriteArraySet import java.util.regex.Matcher @@ -216,6 +215,10 @@ object BookHelp { .trim { it <= ' ' } } + private val jaccardSimilarity by lazy { + JaccardSimilarity() + } + /** * 根据目录名获取当前章节 */ @@ -248,10 +251,9 @@ object BookHelp { var newIndex = 0 var newNum = 0 if (oldName.isNotEmpty()) { - val service = StringSimilarityServiceImpl(JaroWinklerStrategy()) for (i in min..max) { val newName = getPureChapterName(newChapterList[i].title) - val temp = service.score(oldName, newName) + val temp = jaccardSimilarity.apply(oldName, newName) if (temp > nameSim) { nameSim = temp newIndex = i