participle.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. const $ = require("jquery");
  2. require("babel-polyfill");
  3. require("./../css/participle.less");
  4. require("./../css/common.css");
  5. const { post, api } = require('./api.js');
  6. require('./../resources/images/empty2.png');
  7. function insertStr(soure, start, newStr){
  8. return soure.slice(0, start) + newStr + soure.slice(start);
  9. }
  10. function getEntityPredict(){
  11. const val = $('#infoTxt').val()
  12. const param ={
  13. data:[
  14. {"medical_text_type": "chief_present",
  15. "content": val,
  16. "title": "自定义添加的属性",
  17. "detail_title": "自定义添加的属性"
  18. }
  19. ]
  20. }
  21. post(api.entity_predict, param).then(res =>{
  22. const data = JSON.parse(res.data)
  23. if(data.status){
  24. const result = data.data[0].entity_relation_object
  25. const entryList = result.outputs.annotation['T']
  26. const relationList = result.outputs.annotation['R']
  27. let content = result.content
  28. getSchema(content,entryList)
  29. getRelationList(relationList,entryList)
  30. }
  31. })
  32. }
  33. function getSchema(content, entryList){
  34. let addNum = 0
  35. for(let i = 1; i < entryList.length; i++){
  36. content = insertStr(content, entryList[i].start+addNum, `<span class="entryItem"><span class="type"><span class="trangle"></span>${entryList[i].name}</span>`)
  37. addNum += 50 + entryList[i].name.length + 29
  38. content = insertStr(content, entryList[i].end+addNum, '</span>')
  39. addNum += 7
  40. }
  41. $('.resultBoxInfo').html(content)
  42. }
  43. function getRelationList(relationList,entryList){
  44. let str = ''
  45. for(let i = 1; i < relationList.length; i++){
  46. const relationItem = relationList[i]
  47. const relationName = relationList[i].name
  48. const entry1 = entryList.find(item => item.id === relationList[i].from).value
  49. const entry2 = entryList.find(item => item.id === relationList[i].to).value
  50. str += `<tr>
  51. <td class="entry1">${entry1}</td>
  52. <td class="relationType">${relationName}</td>
  53. <td class="entry2">${entry2}</td>
  54. </tr>`
  55. }
  56. if(str){
  57. $('.empty').css("display","none");
  58. $('table').css("display","table")
  59. }
  60. $('.relationBody').html(str)
  61. }
  62. $("#analy").click(function(){
  63. const val = $("#infoTxt").val().trim()
  64. if(val){
  65. getEntityPredict()
  66. }
  67. })
  68. $("#infoTxt").bind("input propertychange",function(event){
  69. const val = $("#infoTxt").val().trim()
  70. if(!val){
  71. $('#analy').addClass('disabled')
  72. $('.resultBoxInfo').html('')
  73. $('.empty').css("display","block");
  74. $('table').css("display","none")
  75. }else{
  76. $('#analy').removeClass('disabled')
  77. }
  78. });