This commit is contained in:
zyronon
2023-12-03 20:58:59 +08:00
parent c94f20645a
commit 20165db2f3
5 changed files with 98 additions and 22 deletions

View File

@@ -70,6 +70,8 @@ watch(() => props.article, val => {
function renewSections() {
if (editArticle.text.trim()) {
renewSectionTexts(editArticle)
editArticle.sections = []
return
if (editArticle.useTranslateType === TranslateType.custom) {
failCount = renewSectionTranslates(editArticle, editArticle.textCustomTranslate)
}

View File

@@ -1,6 +1,6 @@
<script setup lang="ts">
import {Dict} from "@/types.ts";
import {Dict, DictType} from "@/types.ts";
import {Icon} from "@iconify/vue";
defineProps<{
@@ -25,7 +25,10 @@ const emit = defineEmits<{
<div class="name">{{ dict.name }}</div>
<div class="desc">{{ dict.description }}</div>
</div>
<div class="num">{{ dict.length ?? dict.originWords.length }}</div>
<div class="bottom">
<div class="num">{{ dict.length ?? dict.originWords.length }}</div>
</div>
<div class="pin" v-if="dict.type === DictType.article">文章</div>
</template>
<div v-else class="add" @click.stop="emit('add')">
<Icon icon="fluent:add-20-filled" width="38" color="#929596"/>
@@ -49,23 +52,24 @@ const emit = defineEmits<{
display: flex;
flex-direction: column;
justify-content: space-between;
overflow: hidden;
.name {
font-size: 16rem;
overflow: hidden;
text-overflow: ellipsis;
display:-webkit-box; //作为弹性伸缩盒子模型显示。
-webkit-box-orient:vertical; //设置伸缩盒子的子元素排列方式--从上到下垂直排列
-webkit-line-clamp:2; //显示的行
display: -webkit-box; //作为弹性伸缩盒子模型显示。
-webkit-box-orient: vertical; //设置伸缩盒子的子元素排列方式--从上到下垂直排列
-webkit-line-clamp: 2; //显示的行
}
.desc {
color: var(--color-font-2);
overflow: hidden;
text-overflow: ellipsis;
display:-webkit-box; //作为弹性伸缩盒子模型显示。
-webkit-box-orient:vertical; //设置伸缩盒子的子元素排列方式--从上到下垂直排列
-webkit-line-clamp:2; //显示的行
display: -webkit-box; //作为弹性伸缩盒子模型显示。
-webkit-box-orient: vertical; //设置伸缩盒子的子元素排列方式--从上到下垂直排列
-webkit-line-clamp: 2; //显示的行
}
.num {
@@ -100,6 +104,22 @@ const emit = defineEmits<{
width: 100%;
height: 100%;
}
.pin {
position: absolute;
bottom: 0;
left: 0;
height: 50rem;
width: 50rem;
color: white; background-color: skyblue;
clip-path: polygon(0 10%, 0% 100%, 100% 100%);
font-size: 12rem;
display: flex;
justify-content: flex-start;
align-items: flex-end;
padding: 5rem;
box-sizing: border-box;
}
}
</style>

View File

@@ -46,6 +46,7 @@ export function splitEnArticle(text: string): { sections: Sentence[][], newText:
let doc = nlp.tokenize(rowSection)
let sentences = doc.json()
// console.log('--')
console.log('ss', sentences)
sentences.map(sentenceRow => {
let sentence: Sentence = {
//他没有空格,导致修改一行一行的数据时,汇总时全没有空格了,库无法正常断句
@@ -56,16 +57,20 @@ export function splitEnArticle(text: string): { sections: Sentence[][], newText:
}
section.push(sentence)
const checkQuote = (pre: string) => {
const checkQuote = (pre: string, index?: number) => {
let nearSymbolPosition = null
//TODO 可以优化成for+break
section.toReversed().map((sentenceItem, b) => {
sentenceItem.words.toReversed().map((wordItem, c) => {
if (wordItem.symbolPosition !== '' && nearSymbolPosition === null) {
nearSymbolPosition = wordItem.symbolPosition
}
if (index === 0) {
nearSymbolPosition = 'end'
} else {
//TODO 可以优化成for+break
section.toReversed().map((sentenceItem, b) => {
sentenceItem.words.toReversed().map((wordItem, c) => {
if (wordItem.symbolPosition !== '' && nearSymbolPosition === null) {
nearSymbolPosition = wordItem.symbolPosition
}
})
})
})
}
let word3: ArticleWord = {
...DefaultArticleWord,
@@ -74,7 +79,8 @@ export function splitEnArticle(text: string): { sections: Sentence[][], newText:
isSymbol: true,
symbolPosition: ''
};
// console.log('rrr', sentenceRow)
// console.log('nearSymbolPosition', nearSymbolPosition)
if (nearSymbolPosition === 'end' || nearSymbolPosition === null) {
word3.symbolPosition = 'start'
sentence.words.push(word3)
@@ -96,7 +102,8 @@ export function splitEnArticle(text: string): { sections: Sentence[][], newText:
let lastSentence = section[section.length - 2]
lastSentence.words = lastSentence.words.concat(sentence.words)
lastSentence.words.push(word3)
section.pop()
sentence.words = []
// section.pop()
}
}
}
@@ -131,6 +138,7 @@ export function splitEnArticle(text: string): { sections: Sentence[][], newText:
break
//类似于这种的“' -- ”的。需要保留空格用了一个占位符才处理因为每个符号都会把前面的那个字符的nextSpace改为false
case ' ':
console.log('sentence', sentence)
sentence.words[sentence.words.length - 1].nextSpace = true
let word3 = cloneDeep({
...DefaultArticleWord,
@@ -161,12 +169,12 @@ export function splitEnArticle(text: string): { sections: Sentence[][], newText:
}
}
sentenceRow.terms.map(v => {
sentenceRow.terms.map((v, index: number) => {
// console.log('v', v)
if (v.text) {
let pre: string = v.pre.trim()
if (pre) {
checkQuote(pre)
checkQuote(pre, index)
}
let word = cloneDeep({...DefaultArticleWord, name: v.text, nextSpace: true});
@@ -175,7 +183,11 @@ export function splitEnArticle(text: string): { sections: Sentence[][], newText:
let post: string = v.post
//判断是不是等于空,因为正常的词后面都会有个空格。这种不需要处理。
if (post && post !== ' ') {
checkSymbol(post)
try {
checkSymbol(post)
} catch (e) {
console.log('err', v)
}
}
}
})
@@ -196,6 +208,8 @@ export function splitEnArticle(text: string): { sections: Sentence[][], newText:
// })
// console.log(sections)
// console.timeEnd()
console.log('sections', sections)
return {
newText: text,
sections

38
src/pages/test.vue Normal file
View File

@@ -0,0 +1,38 @@
<script setup lang="ts">
import {splitEnArticle} from "@/hooks/article.ts";
let data = {
"title": "A cold welcome",
"titleTranslate": "冷遇",
"text": "On Wednesday evening, we went to the Town Hall. It was the last day of the year and a large crowd of people had gathered under the Town Hall clock. It would strike twelve in twenty minutes' time. Fifteen minutes passed and then, at five to twelve, the clock stopped. The big minute hand did not move. We waited and waited, but nothing happened. Suddenly someone shouted. 'It's two minutes past twelve! The clock has stopped!' I looked at my watch. It was true. The big clock refused to welcome the New Year. At that moment, everybody began to laugh and sing.\n",
"textCustomTranslate": "星期三的晚上,我们去了市政厅。 那是一年的最后一天一大群人聚集在市政厅的大钟下面。再过20分钟大钟将敲响12下。15分钟过去了而就在11点55分时大钟停了。那根巨大的分针不动了。 我们等啊等啊可情况没有变化。突然有人喊道“已经12点零2分了那钟已经停了”我看了一下我的手表果真如此。那座大钟不愿意迎接新年。此时大家已经笑了起来同时唱起了歌。",
"textNetworkTranslate": "",
"textCustomTranslateIsFormat": false,
"useTranslateType": "custom",
"newWords": [],
"id": "UydP2M"
}
// data = {
// "title": "The best and the worst",
// "titleTranslate": "最好的和最差的",
// "text": "Joe Sanders has the most beautiful garden in our town. Nearly everybody enters for 'The Nicest Garden Competition' each year, but Joe wins every time. Bill Frith's garden is larger than Joe's. Bill works harder than Joe and grows more flowers and vegetables, but Joe's garden is more interesting. He has made neat paths and has built a wooden bridge over a pool. I like gardens too, but I do not like hard work. Every year I enter for the garden competition too, and I always win a little prize for the worst garden in the town!",
// "textCustomTranslate": "乔.桑德斯拥有我们镇上最漂亮的花园。\n几乎每个人都参加每年举办的“最佳花园竞赛”而每次都是乔获胜。\n比尔.弗里斯的花园比乔的花园大,\n他比乔也更为勤奋种植的花卉和蔬菜也更多但乔的花园更富有情趣。\n他修筑了一条条整洁的小路并在一个池塘上架了一座小木桥。\n我也喜欢花园但我却不愿意辛勤劳动。\n每年的花园竞赛我也参加但总因是镇上最劣的花园而获得一个小奖",
// "textNetworkTranslate": "",
// "textCustomTranslateIsFormat": true,
// "useTranslateType": "custom",
// "newWords": [],
// "id": "TdAAqD"
// }
splitEnArticle(data.text)
</script>
<template>
<div>
test
</div>
</template>
<style scoped lang="scss">
</style>

View File

@@ -1,11 +1,13 @@
import * as VueRouter from 'vue-router'
import Practice from "@/pages/practice/index.vue";
import Dict from '@/pages/dict'
import Test from "@/pages/test.vue";
const routes: any[] = [
{path: '/practice', component: Practice},
{path: '/dict', name: 'dict', component: Dict},
{path: '/', redirect: '/practice'},
{path: '/test', name: 'test', component: Test},
{path: '/', redirect: '/test'},
]
const router = VueRouter.createRouter({