128 lines
2.5 KiB
TypeScript
128 lines
2.5 KiB
TypeScript
import {bridge} from "@/core/bridge.ts";
|
|
import {CACHE_DATA} from "@/core/cache.ts";
|
|
import GovInfo = V3.GovInfo;
|
|
|
|
/**
|
|
* 队列信息
|
|
*/
|
|
const QUEUE_INFO: {
|
|
state: 'initial' | 'pause' | 'marking' | 'ended';
|
|
list: V3.ProofreadSentence[];
|
|
govExtra: {
|
|
[key:string]: GovInfo[]
|
|
},
|
|
confusionNotice: {
|
|
[key:string]: string
|
|
};
|
|
correctId: number[];
|
|
index: number;
|
|
} = {
|
|
state: 'initial',
|
|
govExtra: {},
|
|
confusionNotice: {},
|
|
list: [],
|
|
correctId: [],
|
|
index: 0,
|
|
}
|
|
|
|
/**
|
|
* 初始化队列信息
|
|
*/
|
|
export function init() {
|
|
QUEUE_INFO.list = [];
|
|
QUEUE_INFO.govExtra = {};
|
|
QUEUE_INFO.confusionNotice = {};
|
|
QUEUE_INFO.correctId = [];
|
|
QUEUE_INFO.index = 0;
|
|
QUEUE_INFO.state = 'initial';
|
|
return QUEUE_INFO;
|
|
}
|
|
|
|
/**
|
|
* 获取队列信息
|
|
*/
|
|
export function getQueue() {
|
|
return QUEUE_INFO;
|
|
}
|
|
|
|
export function getQueueItem(count: number) {
|
|
const list: V3.ProofreadSentence[] = [];
|
|
for (let i = 0; i < count; i++) {
|
|
if (QUEUE_INFO.index >= QUEUE_INFO.list.length) {
|
|
break;
|
|
}
|
|
list.push(QUEUE_INFO.list[QUEUE_INFO.index])
|
|
QUEUE_INFO.index++;
|
|
}
|
|
return list;
|
|
}
|
|
|
|
// 获取当前处理句子
|
|
export function getCurrent() {
|
|
return QUEUE_INFO.list[QUEUE_INFO.index];
|
|
}
|
|
|
|
export function pause() {
|
|
QUEUE_INFO.state = 'pause';
|
|
}
|
|
|
|
export function resume() {
|
|
if (QUEUE_INFO.state !== 'pause') return;
|
|
QUEUE_INFO.state = 'marking';
|
|
processCurrentSentence();
|
|
}
|
|
|
|
export function end() {
|
|
QUEUE_INFO.state = 'ended';
|
|
QUEUE_INFO.index = QUEUE_INFO.list.length;
|
|
}
|
|
|
|
// 处理当前队列的句子
|
|
export function processCurrentSentence() {
|
|
if (QUEUE_INFO.state !== 'marking') return;
|
|
if (QUEUE_INFO.index >= QUEUE_INFO.list.length) {
|
|
QUEUE_INFO.state = 'ended'
|
|
return;
|
|
}
|
|
// 每次取5个句子进行标记
|
|
const list = getQueueItem(5)
|
|
// 提交句子到word进行标记
|
|
try {
|
|
// console.log('mark sentence ===> ', list)
|
|
bridge.MarkSentence(JSON.stringify(list), CACHE_DATA.DocumentID)
|
|
.then(() => {
|
|
processCurrentSentence()
|
|
})
|
|
.catch(e => {
|
|
console.log(e)
|
|
processCurrentSentence()
|
|
})
|
|
} catch (e) {
|
|
console.log('MarkSentence==>', e)
|
|
}
|
|
|
|
// const sentence = getCurrent();
|
|
// setTimeout(() => {
|
|
// console.log('sentence', sentence.insert)
|
|
// }, 800)
|
|
}
|
|
|
|
/**
|
|
* 添加到队列
|
|
* @param sentence
|
|
*/
|
|
export function push(sentence: V3.ProofreadSentence) {
|
|
// 判断数据是否重复
|
|
// 添加到队列中
|
|
QUEUE_INFO.list.push(sentence);
|
|
// 判断状态是未开始
|
|
if (QUEUE_INFO.state === 'marking') {
|
|
return;
|
|
}
|
|
|
|
// 状态改为标记中
|
|
QUEUE_INFO.state = 'marking';
|
|
// 处理当前句子
|
|
processCurrentSentence()
|
|
}
|