const $ = require("jquery"); require("babel-polyfill"); require("./../css/participle.less"); require("./../css/common.css"); const { post, api } = require('./api.js'); require('./../resources/images/empty2.png'); require('./../resources/images/iconUp.png'); require('./../resources/images/iconDown.png'); require('./../resources/images/iconClose3.png'); require('./../css/img/icon_tu.png'); require('./../css/img/icon_wenzi.png'); const {currentIIData} = require('./data.js') function appendCurrentII(currentIIList){ for(let i = 0; i < currentIIList.length; i++){ let str = `
${currentIIList[i].title} 引用
正在分析...
`); $("#svg").html(`正在分析...
`); $(".analying").css('display','block'); $('table').css("display","none") $('.empty').hide(); post(api.entity_predict, param).then(res =>{ if(res.data.code == '0'){ const data = JSON.parse(res.data.data) const result = data.data[0].entity_relation_object const entryList = result&&result.outputs&&result.outputs.annotation['T'] const relationList = result&&result.outputs&&result.outputs.annotation['R'] let content = result.content if((JSON.stringify(entryList)!='[""]')&&(JSON.stringify(relationList)!='[""]')){ // getRelationList(relationList,entryList) let enter = chageEnter(entryList) let rela = chageRelation(relationList) svgData = Object.assign(enter,rela,{"content":content}) if($("#svg").css("display") == "block"){ showSvg(svgData) } getSchema(content,entryList) getRelationList(relationList,entryList) $('#analy').removeClass('disabled') }else{ // $('#analy').addClass('disabled') $('#resultBoxInfo').html('') $('.empty').css("display","block"); $('.analying').css("display","none"); $('table').css("display","none"); } } }) } $("#toggleImg").click(()=>{ $("#resultBoxInfo").css("display","block") $("#svg").css("display","none") $("#toggleImg").css("display","none"); $("#toggleImgs").css("display","block"); }) $("#toggleImgs").click(()=>{ $("#resultBoxInfo").css("display","none") $("#svg").css("display","block") showSvg(svgData) $("#toggleImgs").css("display","none"); $("#toggleImg").css("display","block"); }) function chageEnter(data){ var keyMap = { "name" : "text", "start" : "startIndex", "end" : "endIndex", "id" : "categoryId", }; for(let i = 0;i < data.length;i++){ let obj = data[i]; for(let key in obj){ let newKey = keyMap[key]; if(newKey){ obj[newKey] = obj[key]; // delete obj[key]; } obj.color = "red" obj.borderColor = "#5A8EEE" } } data.splice(0,1) return { "labelCategories":data, "labels":data } } function chageRelation(data){ var keyMap = { "name" : "text", "from" : "fromId", "to" : "toId", "id" : "categoryId", }; for(let i = 0;i < data.length;i++){ let obj = data[i]; for(let key in obj){ let newKey = keyMap[key]; if(newKey){ obj[newKey] = obj[key]; } obj.id = i obj.categoryId = i } } data.splice(0,1) return { "connectionCategories":data, "connections":data, } } function getSchema(content, entryList){ let addNum = 0 for(let i = 1; i < entryList.length; i++){ content = insertStr(content, entryList[i].start+addNum, `* ${entryList[i].name}`) addNum += 107 + entryList[i].name.length if(i < entryList.length-1&&(entryList[i].end ===entryList[i+1].start)){ content = insertStr(content, entryList[i].end+addNum, '') addNum += 7 } else{ content = insertStr(content, entryList[i].end+addNum, '*') addNum += 34 } } $('#resultBoxInfo').html(content) } function getRelationList(relationList,entryList){ let str = '' for(let i = 1; i < relationList.length; i++){ const relationItem = relationList[i] const relationName = relationList[i].name const entry1 = entryList.find(item => item.id === relationList[i].from).value const entry2 = entryList.find(item => item.id === relationList[i].to).value str += `