2023-11-02 01:56:14 +00:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="set-rules">
|
2023-11-08 11:08:54 +00:00
|
|
|
|
<el-row class="set-rules-height">
|
2023-11-17 03:36:16 +00:00
|
|
|
|
<el-col :span="10" class="p-24">
|
2023-11-06 11:06:02 +00:00
|
|
|
|
<h4 class="title-decoration-1 mb-8">设置分段规则</h4>
|
2023-11-08 11:08:54 +00:00
|
|
|
|
<div>
|
2023-11-06 11:06:02 +00:00
|
|
|
|
<el-scrollbar>
|
2023-11-08 11:08:54 +00:00
|
|
|
|
<div class="left-height">
|
2023-11-06 11:06:02 +00:00
|
|
|
|
<el-radio-group v-model="radio" class="set-rules__radio">
|
|
|
|
|
|
<el-radio label="1" size="large" border class="mb-16">
|
|
|
|
|
|
<p>智能分段(推荐)</p>
|
|
|
|
|
|
<el-text type="info">不了解如何设置分段规则推荐使用智能分段</el-text>
|
|
|
|
|
|
</el-radio>
|
|
|
|
|
|
<el-radio label="2" size="large" border class="mb-16">
|
|
|
|
|
|
<p>高级分段</p>
|
2023-11-21 02:56:25 +00:00
|
|
|
|
<el-text type="info"
|
|
|
|
|
|
>用户可根据文档规范自行设置分段标识符、分段长度以及清洗规则
|
2023-11-06 11:06:02 +00:00
|
|
|
|
</el-text>
|
|
|
|
|
|
<el-card shadow="never" class="card-never mt-16" v-if="radio === '2'">
|
2023-11-08 11:08:54 +00:00
|
|
|
|
<div class="set-rules__form">
|
|
|
|
|
|
<div class="form-item mb-16">
|
|
|
|
|
|
<div class="title flex align-center mb-8">
|
|
|
|
|
|
<span style="margin-right: 4px">分段标识</span>
|
2023-11-21 02:56:25 +00:00
|
|
|
|
<el-tooltip
|
|
|
|
|
|
effect="dark"
|
|
|
|
|
|
content="按照所选符号先后顺序做递归分割,分割结果超出分段长度将截取至分段长度。"
|
|
|
|
|
|
placement="right"
|
|
|
|
|
|
>
|
2023-11-21 02:57:20 +00:00
|
|
|
|
<el-icon style="font-size: 16px">
|
|
|
|
|
|
<Warning />
|
|
|
|
|
|
</el-icon>
|
2023-11-14 10:12:55 +00:00
|
|
|
|
</el-tooltip>
|
2023-11-08 11:08:54 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2023-11-21 02:56:25 +00:00
|
|
|
|
<el-select
|
|
|
|
|
|
v-loading="patternLoading"
|
|
|
|
|
|
v-model="form.patterns"
|
|
|
|
|
|
multiple
|
|
|
|
|
|
placeholder="请选择"
|
|
|
|
|
|
>
|
|
|
|
|
|
<el-option
|
|
|
|
|
|
v-for="item in splitPatternList"
|
|
|
|
|
|
:key="item"
|
|
|
|
|
|
:label="item.key"
|
|
|
|
|
|
:value="item.value"
|
|
|
|
|
|
multiple
|
|
|
|
|
|
>
|
2023-11-08 11:08:54 +00:00
|
|
|
|
</el-option>
|
2023-11-06 11:06:02 +00:00
|
|
|
|
</el-select>
|
2023-11-08 11:08:54 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="form-item mb-16">
|
|
|
|
|
|
<div class="title mb-8">分段长度</div>
|
2023-11-21 02:56:25 +00:00
|
|
|
|
<el-slider
|
|
|
|
|
|
v-model="form.limit"
|
|
|
|
|
|
show-input
|
|
|
|
|
|
:show-input-controls="false"
|
|
|
|
|
|
:min="50"
|
|
|
|
|
|
:max="1024"
|
|
|
|
|
|
/>
|
2023-11-08 11:08:54 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="form-item mb-16">
|
|
|
|
|
|
<div class="title mb-8">自动清洗</div>
|
|
|
|
|
|
<el-switch v-model="form.with_filter" />
|
|
|
|
|
|
<div style="margin-top: 4px">
|
|
|
|
|
|
<el-text type="info">去掉重复多余符号空格、空行、制表符</el-text>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2023-11-06 11:06:02 +00:00
|
|
|
|
</el-card>
|
|
|
|
|
|
</el-radio>
|
|
|
|
|
|
</el-radio-group>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-scrollbar>
|
|
|
|
|
|
<div class="text-right">
|
|
|
|
|
|
<el-button @click="splitDocument">生成预览</el-button>
|
2023-11-02 01:56:14 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
|
2023-11-17 03:36:16 +00:00
|
|
|
|
<el-col :span="14" class="p-24 border-l">
|
2023-11-10 09:18:00 +00:00
|
|
|
|
<div v-loading="loading">
|
2023-11-06 11:06:02 +00:00
|
|
|
|
<h4 class="title-decoration-1 mb-8">分段预览</h4>
|
2023-11-14 10:12:55 +00:00
|
|
|
|
<ParagraphPreview v-model:data="paragraphList" />
|
2023-11-06 11:06:02 +00:00
|
|
|
|
</div>
|
2023-11-02 01:56:14 +00:00
|
|
|
|
</el-col>
|
|
|
|
|
|
</el-row>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
2023-11-21 02:57:20 +00:00
|
|
|
|
import { ref, computed, onMounted, reactive, watch } from 'vue'
|
2023-11-14 10:12:55 +00:00
|
|
|
|
import ParagraphPreview from '@/views/dataset/component/ParagraphPreview.vue'
|
2023-11-02 01:56:14 +00:00
|
|
|
|
import DatasetApi from '@/api/dataset'
|
|
|
|
|
|
import useStore from '@/stores'
|
2023-11-20 10:53:18 +00:00
|
|
|
|
import type { KeyValue } from '@/api/type/common'
|
2023-11-02 01:56:14 +00:00
|
|
|
|
const { dataset } = useStore()
|
|
|
|
|
|
const documentsFiles = computed(() => dataset.documentsFiles)
|
2023-11-21 02:57:20 +00:00
|
|
|
|
const splitPatternList = ref<Array<KeyValue<string, string>>>([])
|
2023-11-02 01:56:14 +00:00
|
|
|
|
|
2023-11-06 11:06:02 +00:00
|
|
|
|
const radio = ref('1')
|
2023-11-02 01:56:14 +00:00
|
|
|
|
const loading = ref(false)
|
2023-11-14 10:12:55 +00:00
|
|
|
|
const paragraphList = ref<any[]>([])
|
2023-11-21 02:57:20 +00:00
|
|
|
|
const patternLoading = ref<boolean>(false)
|
2023-11-06 11:06:02 +00:00
|
|
|
|
|
2023-11-21 05:52:58 +00:00
|
|
|
|
const form = reactive<{
|
|
|
|
|
|
patterns: Array<string>,
|
|
|
|
|
|
limit: number,
|
|
|
|
|
|
with_filter: boolean,
|
|
|
|
|
|
[propName: string]: any
|
|
|
|
|
|
}>({
|
|
|
|
|
|
patterns: [],
|
2023-11-08 11:08:54 +00:00
|
|
|
|
limit: 0,
|
2023-11-21 05:52:58 +00:00
|
|
|
|
with_filter: false,
|
|
|
|
|
|
|
2023-11-06 11:06:02 +00:00
|
|
|
|
})
|
|
|
|
|
|
|
2023-11-02 01:56:14 +00:00
|
|
|
|
function splitDocument() {
|
|
|
|
|
|
loading.value = true
|
|
|
|
|
|
let fd = new FormData()
|
|
|
|
|
|
documentsFiles.value.forEach((item) => {
|
|
|
|
|
|
if (item?.raw) {
|
|
|
|
|
|
fd.append('file', item?.raw)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2023-11-10 09:18:00 +00:00
|
|
|
|
if (radio.value === '2') {
|
|
|
|
|
|
Object.keys(form).forEach((key) => {
|
2023-11-21 05:52:58 +00:00
|
|
|
|
if (key == 'patterns') {
|
|
|
|
|
|
form.patterns.forEach(item => fd.append('patterns', item))
|
|
|
|
|
|
} else {
|
|
|
|
|
|
fd.append(key, form[key])
|
|
|
|
|
|
}
|
2023-11-10 09:18:00 +00:00
|
|
|
|
})
|
|
|
|
|
|
}
|
2023-11-02 01:56:14 +00:00
|
|
|
|
DatasetApi.postSplitDocument(fd)
|
2023-11-06 11:06:02 +00:00
|
|
|
|
.then((res: any) => {
|
2023-11-14 10:12:55 +00:00
|
|
|
|
paragraphList.value = res.data
|
2023-11-02 01:56:14 +00:00
|
|
|
|
loading.value = false
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch(() => {
|
|
|
|
|
|
loading.value = false
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-20 10:53:18 +00:00
|
|
|
|
const initSplitPatternList = () => {
|
2023-11-21 02:56:25 +00:00
|
|
|
|
DatasetApi.listSplitPattern(patternLoading).then((ok) => {
|
2023-11-21 02:57:20 +00:00
|
|
|
|
splitPatternList.value = ok.data
|
2023-11-20 10:53:18 +00:00
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-21 02:57:20 +00:00
|
|
|
|
watch(radio, () => {
|
|
|
|
|
|
if (radio.value === '2') {
|
2023-11-20 10:53:18 +00:00
|
|
|
|
initSplitPatternList()
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2023-11-10 09:18:00 +00:00
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
splitDocument()
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
defineExpose({
|
2023-11-14 10:12:55 +00:00
|
|
|
|
paragraphList
|
2023-11-10 09:18:00 +00:00
|
|
|
|
})
|
2023-11-02 01:56:14 +00:00
|
|
|
|
</script>
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
|
.set-rules {
|
2023-11-06 11:06:02 +00:00
|
|
|
|
width: 100%;
|
2023-11-21 02:57:20 +00:00
|
|
|
|
|
2023-11-08 11:08:54 +00:00
|
|
|
|
.set-rules-height {
|
|
|
|
|
|
height: var(--create-dataset-height);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.left-height {
|
|
|
|
|
|
max-height: calc(var(--create-dataset-height) - 105px);
|
|
|
|
|
|
overflow-x: hidden;
|
|
|
|
|
|
}
|
2023-11-21 02:57:20 +00:00
|
|
|
|
|
2023-11-02 01:56:14 +00:00
|
|
|
|
&__radio {
|
|
|
|
|
|
display: block;
|
2023-11-21 02:57:20 +00:00
|
|
|
|
|
2023-11-06 11:06:02 +00:00
|
|
|
|
.el-radio {
|
|
|
|
|
|
white-space: break-spaces;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 100%;
|
2023-11-08 11:08:54 +00:00
|
|
|
|
padding: calc(var(--app-base-px) * 2);
|
2023-11-06 11:06:02 +00:00
|
|
|
|
line-height: 22px;
|
2023-11-13 11:02:13 +00:00
|
|
|
|
color: var(--app-text-color);
|
2023-11-06 11:06:02 +00:00
|
|
|
|
}
|
2023-11-21 02:57:20 +00:00
|
|
|
|
|
2023-11-06 11:06:02 +00:00
|
|
|
|
:deep(.el-radio__label) {
|
|
|
|
|
|
padding-left: 32px;
|
2023-11-08 11:08:54 +00:00
|
|
|
|
width: 100%;
|
2023-11-06 11:06:02 +00:00
|
|
|
|
}
|
2023-11-21 02:57:20 +00:00
|
|
|
|
|
2023-11-06 11:06:02 +00:00
|
|
|
|
:deep(.el-radio__input) {
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
top: 30px;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-11-21 02:57:20 +00:00
|
|
|
|
|
2023-11-08 11:08:54 +00:00
|
|
|
|
&__form {
|
|
|
|
|
|
.el-select {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
}
|
2023-11-21 02:57:20 +00:00
|
|
|
|
|
2023-11-08 11:08:54 +00:00
|
|
|
|
.title {
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
font-weight: 400;
|
|
|
|
|
|
}
|
2023-11-02 01:56:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|