feat: 增加文本分类功能

This commit is contained in:
马琦钧 2021-08-08 01:10:51 +08:00
parent d9dbf5cbc7
commit 4bb5838795
2 changed files with 36 additions and 5 deletions

View File

@ -25,7 +25,7 @@
<div class="title">
<span>选择标签</span>
<div class="type-box">
<span v-for="type in typeList" :key="type" @click="setType(type)" @contextmenu="delType(type, $event)" :class="nowType===type?'type selected':'type'"
<span v-for="type in typeList" :key="type" @click="setType(type)" @contextmenu="delType(type, $event)" :class="isTypeSelected(type)?'type selected':'type'"
:style="{
backgroundColor: types[type] ? types[type].color : '#fff'
}"
@ -328,7 +328,24 @@ export default {
* @param 类型
*/
setType: function (type, ev) {
this.$set(this, 'nowType', type)
if (this.projectType === '命名识别识别')
this.$set(this, 'nowType', type)
if (this.projectType === '文本分类') {
let typeIdx = -1;
this.ners.some((ner, idx) => {
if (ner.type === type) {
typeIdx = idx
return ner.type === type
}
})
if (typeIdx === -1) {
this.ners.push({type})
} else {
this.ners.splice(typeIdx, 1)
}
this.$set(this, 'nowType', type)
this.save()
}
},
delType: function (type, ev) {
if (!this.configCanCtlType) return false
@ -419,6 +436,7 @@ export default {
this.$set(this, 'wordsOutType', this.wordsOutType)
},
startSelect: function (idx, event) {
if (this.projectType !== '命名实体识别') return;
if (event.which === 3) {
event.preventDefault()
//
@ -506,7 +524,10 @@ export default {
outAllNers () {
if (!isLocal) {
// url
window.open(`/v1/files/get_json?projectName=${this.projectName}`, '_self')
if (this.projectType === '命名实体识别')
window.open(`/v1/files/get_json?projectName=${this.projectName}`, '_self')
if (this.projectType === '文本分类')
window.open(`/v1/files/get_labels?projectName=${this.projectName}`, '_self')
return true
}
this.nersCache[this.nowFile] = this.ners
@ -549,6 +570,15 @@ export default {
console.log(tarType, ev.target.value)
that.$set(that.types[tarType], 'color', ev.target.value)
updateType2Server(that.projectName, that.typeList, that.types)
},
//
isTypeSelected: function(type) {
if (this.projectType === '命名实体识别')
return this.nowType === type;
if (this.projectType === '文本分类')
return this.ners.some((ner)=>{
return ner.type === type
})
}
},
watch: {
@ -584,8 +614,8 @@ export default {
return entityType.type
})
that.types = types
//
if (that.typeList && that.typeList[0]) that.nowType = that.typeList[0]
//
if (that.typeList && that.typeList[0] && projectType === '命名实体识别') that.nowType = that.typeList[0]
get(`/v1/files/query?projectName=${projectName}&pageNumber=${that.pageNumber}&pageSize=${that.pageSize}`, function (info) {
that.$set(that, 'files', info.map((item) => {
if (typeof item === 'string') return item

View File

@ -26,6 +26,7 @@
<p>类型
<select class="type-input" name="type" @change="setType" :value="projectType">
<option value ="命名实体识别">命名实体识别</option>
<option value ="文本分类">文本分类</option>
</select>
</p>
<div class="title">