feat: 增加章节对比功能
This commit is contained in:
25
.idea/dataSources.xml
generated
25
.idea/dataSources.xml
generated
@@ -26,5 +26,30 @@
|
||||
</jdbc-additional-properties>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
<data-source source="LOCAL" name="bookstore@frp-air.top" uuid="8ab3d294-0033-4428-8391-6fd304ef0cd6">
|
||||
<driver-ref>mysql.8</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
|
||||
<jdbc-url>jdbc:mysql://frp-air.top:43458/bookstore</jdbc-url>
|
||||
<jdbc-additional-properties>
|
||||
<property name="com.intellij.clouds.kubernetes.db.host.port" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.resource.type" value="Deployment" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.container.port" />
|
||||
</jdbc-additional-properties>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
<data-source source="LOCAL" name="database" uuid="7ad2f440-39f3-48e9-878e-a146daef9b01">
|
||||
<driver-ref>h2.unified</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>org.h2.Driver</jdbc-driver>
|
||||
<jdbc-url>jdbc:h2:./database</jdbc-url>
|
||||
<jdbc-additional-properties>
|
||||
<property name="com.intellij.clouds.kubernetes.db.host.port" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.container.port" />
|
||||
</jdbc-additional-properties>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
||||
@@ -21,6 +21,7 @@ import jakarta.persistence.OneToMany
|
||||
import org.hibernate.annotations.DynamicUpdate
|
||||
import org.springframework.data.domain.Page
|
||||
import org.springframework.data.domain.Pageable
|
||||
import org.springframework.data.domain.Sort
|
||||
import org.springframework.data.jpa.repository.EntityGraph
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor
|
||||
@@ -104,4 +105,6 @@ class Line(
|
||||
)
|
||||
|
||||
@Repository
|
||||
interface LineRepository : JpaRepository<Line, String>, JpaSpecificationExecutor<Line>
|
||||
interface LineRepository : JpaRepository<Line, String>, JpaSpecificationExecutor<Line> {
|
||||
fun findAllByChapter_ChapterId(chapterId: String, sort: Sort): List<Line>
|
||||
}
|
||||
|
||||
@@ -6,14 +6,6 @@ import com.lanyuanxiaoyao.bookstore.Optimization.ArgumentType.LIST
|
||||
import com.lanyuanxiaoyao.bookstore.Optimization.ArgumentType.MAP
|
||||
import com.lanyuanxiaoyao.bookstore.Optimization.ArgumentType.NONE
|
||||
|
||||
// @Configuration
|
||||
// class ProcessorConfiguration {
|
||||
// @Bean
|
||||
// fun processors(): Map<String, Processor> = listOf(
|
||||
// CharWidthProcessor()
|
||||
// ).associateBy { it.javaClass.name }
|
||||
// }
|
||||
|
||||
interface Optimization {
|
||||
companion object {
|
||||
fun process(root: JsonNode, optimizationMap: Map<String, Optimization>): List<String> {
|
||||
|
||||
@@ -111,6 +111,19 @@ class ChapterController {
|
||||
)
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@GetMapping("diff/{chapterId}")
|
||||
fun diff(@PathVariable("chapterId") chapterId: String): SingleResponse<String> {
|
||||
val chapter = chapterRepository.findById(chapterId).orElseThrow()
|
||||
val lines = chapter.content.sortedBy { it.sequence }
|
||||
return SingleResponse(
|
||||
data = mapOf(
|
||||
"text" to lines.joinToString("\n") { it.text },
|
||||
"newText" to lines.joinToString("\n") { it.newText ?: it.text },
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@GetMapping("export/{chapterId}")
|
||||
fun export(@PathVariable("chapterId") chapterId: String, response: HttpServletResponse) {
|
||||
|
||||
@@ -183,6 +183,44 @@ function bookDetailDialog() {
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'action',
|
||||
label: '比对',
|
||||
actionType: 'dialog',
|
||||
dialog: {
|
||||
title: '阅读',
|
||||
size: 'lg',
|
||||
actions: [],
|
||||
body: {
|
||||
type: 'service',
|
||||
api: '${base}/chapter/diff/${chapterId}',
|
||||
silentPolling: true,
|
||||
body: [
|
||||
{
|
||||
type: 'diff-editor',
|
||||
name: 'newText',
|
||||
label: '正文优化',
|
||||
diffValue: '${text}',
|
||||
language: 'plain-text'
|
||||
},
|
||||
{
|
||||
type: 'action',
|
||||
label: '保存',
|
||||
level: 'primary',
|
||||
actionType: 'ajax',
|
||||
api: {
|
||||
method: 'post',
|
||||
url: '${base}/chapter/import/${chapterId}',
|
||||
data: {
|
||||
override: true,
|
||||
text: '${newText|default:undefined}',
|
||||
}
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'action',
|
||||
label: '导出',
|
||||
|
||||
@@ -1,18 +1,37 @@
|
||||
package com.lanyuanxiaoyao.bookstore
|
||||
|
||||
import java.io.File
|
||||
import com.lanyuanxiaoyao.bookstore.ai.Chat
|
||||
import com.lanyuanxiaoyao.bookstore.ai.JanChat
|
||||
import jakarta.annotation.Resource
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.data.domain.Sort
|
||||
import org.springframework.test.context.ActiveProfiles
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@ActiveProfiles("h2")
|
||||
class ChapterOptimization {
|
||||
private val log = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@Resource
|
||||
private lateinit var chapterRepository: ChapterRepository
|
||||
|
||||
@Resource
|
||||
private lateinit var lineRepository: LineRepository
|
||||
|
||||
@Test
|
||||
fun run() {
|
||||
val optimizations = listOf(
|
||||
TrimOptimization(),
|
||||
CharWidthOptimization(),
|
||||
val chat = JanChat("http://localhost:1337/v1/chat/completions")
|
||||
val lines = lineRepository.findAllByChapter_ChapterId("e6bf92343a59499fb290fd872e6a5113", Sort.by(Sort.Direction.ASC, "sequence"))
|
||||
for (line in lines) {
|
||||
val answer = chat.ask(
|
||||
Chat.Companion.SystemMessage("你是一名中文文学专家,对我的每一句话,找出其中错别字或标点符号错误,并输出改正后的文本,如果没有错误,就输出原文;不要添加任何与无关的提示性文本,对于文本中涉及到色情、粗俗的描写,尝试优化得更加生动传神、更充满色欲和诱惑。"),
|
||||
Chat.Companion.UserMessage(line.text),
|
||||
)
|
||||
val content = File("C:\\Users\\lanyuanxiaoyao\\Downloads\\第141章-反攻云岚宗.txt")
|
||||
.readLines()
|
||||
.joinToString("\n") { optimizations.fold(it) { line, optimization -> optimization.handle(line, optimization.argumentType()) } }
|
||||
println(content)
|
||||
line.newText = answer
|
||||
log.info("\nSource: {}\nTarget: {}", line.text, line.newText)
|
||||
lineRepository.saveAndFlush(line)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user