浏览代码

关系抽取页面展示

louhr 6 年之前
父节点
当前提交
c959dd46e4

+ 3 - 3
nlp-web/src/main/java/org/diagbot/nlp/controller/RelationExtractionController.java

@@ -26,9 +26,9 @@ public class RelationExtractionController {
     public Response extraction(String content) throws Exception {
         Response response = new Response();
         response.start();
-//        RelationAnalyze relationAnalyze = new RelationAnalyze();
-//        List<OutputInfo> outputInfos = relationAnalyze.analyze(content, FeatureType.parse("1"));
-//        response.setData(outputInfos);
+        RelationAnalyze relationAnalyze = new RelationAnalyze();
+        List<OutputInfo> outputInfos = relationAnalyze.analyze(content, FeatureType.parse("1"));
+        response.setData(outputInfos);
         return response;
     }
 }

+ 9 - 7
nlp/src/main/java/org/diagbot/nlp/relation/RelationAnalyze.java

@@ -33,7 +33,7 @@ public class RelationAnalyze {
         List<OutputInfo> outputInfos = new ArrayList<>();
         for (String part_content : part_contents) {
             LexemePath<Lexeme> lexemes = ParticipleUtil.participle(part_content, true);
-            //分词结果转词元结构,因为部分特征信息未在三元组中,所以需要把分词结果也一并传入
+            //分词结果转词元结构,只提取有词性信息,因为部分特征信息未在三元组中,所以需要把分词结果也一并传入
             List<Lemma> lemmaParticiple = lexemeToTriadLemma(lexemes);
             //调用CNN模型
             AlgorithmCNNExecutor executor = new RelationExtractionModelImpl();
@@ -61,12 +61,14 @@ public class RelationAnalyze {
     private List<Lemma> lexemeToTriadLemma(LexemePath<Lexeme> lexemes) {
         List<Lemma> lemmas = new ArrayList<>();
         for (Lexeme lexeme : lexemes) {
-            Lemma lemma = new Lemma();
-            lemma.setLen(lexeme.getLength());
-            lemma.setPosition(lexeme.getOffset() + "," + (lexeme.getOffset() + lexeme.getLength()));
-            lemma.setText(lexeme.getText());
-            lemma.setProperty(lexeme.getProperty());
-            lemmas.add(lemma);
+            if (!lexeme.getProperty().equals("99")) {
+                Lemma lemma = new Lemma();
+                lemma.setLen(lexeme.getLength());
+                lemma.setPosition(lexeme.getOffset() + "," + (lexeme.getOffset() + lexeme.getLength()));
+                lemma.setText(lexeme.getText());
+                lemma.setProperty(lexeme.getProperty());
+                lemmas.add(lemma);
+            }
         }
         return lemmas;
     }

+ 181 - 167
push-web/src/main/resources/static/pages/relation/sample.html

@@ -1,190 +1,204 @@
 <!DOCTYPE html>
 <html>
 <head>
-  <meta charset="utf-8">
-  <meta http-equiv="X-UA-Compatible" content="IE=edge">
-  <title>AdminLTE 2 | Invoice</title>
-  <!-- Tell the browser to be responsive to screen width -->
-  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
-  <!-- Bootstrap 3.3.6 -->
-  <link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css">
-  <!-- Font Awesome -->
-  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
-  <!-- Ionicons -->
-  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
-  <!-- Theme style -->
-  <link rel="stylesheet" href="../dist/css/AdminLTE.min.css">
-  <!-- AdminLTE Skins. Choose a skin from the css/skins
-       folder instead of downloading all of them to reduce the load. -->
-  <link rel="stylesheet" href="../dist/css/skins/_all-skins.min.css">
+    <meta charset="utf-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <title>AdminLTE 2 | Invoice</title>
+    <!-- Tell the browser to be responsive to screen width -->
+    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
+    <!-- Bootstrap 3.3.6 -->
+    <link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css">
+    <!-- Font Awesome -->
+    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
+    <!-- Ionicons -->
+    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
+    <!-- Theme style -->
+    <link rel="stylesheet" href="../dist/css/AdminLTE.min.css">
+    <!-- AdminLTE Skins. Choose a skin from the css/skins
+         folder instead of downloading all of them to reduce the load. -->
+    <link rel="stylesheet" href="../dist/css/skins/_all-skins.min.css">
 
-  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
-  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
-  <!--[if lt IE 9]>
-  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
-  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
-  <![endif]-->
-  <style>
-    .interval {
-      padding : 1px 8px!important;
-    }
+    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
+    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
+    <!--[if lt IE 9]>
+    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
+    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
+    <![endif]-->
+    <style>
+        .interval {
+            padding: 1px 8px !important;
+        }
 
-    #my_file {
-      visibility: hidden;    /* 隐藏 */
-    }
-  </style>
+        #my_file {
+            visibility: hidden; /* 隐藏 */
+        }
+    </style>
 </head>
 <body class="hold-transition skin-blue sidebar-mini">
 <div class="wrapper">
 
-  <header class="main-header">
-    <!-- Logo -->
-    <a href="#" class="logo">
-      <!-- logo for regular state and mobile devices -->
-      <span class="logo-lg"><b>D</b>iagbot</span>
-    </a>
+    <header class="main-header">
+        <!-- Logo -->
+        <a href="#" class="logo">
+            <!-- logo for regular state and mobile devices -->
+            <span class="logo-lg"><b>D</b>iagbot</span>
+        </a>
 
-  </header>
-  <!-- Left side column. contains the logo and sidebar -->
-  <aside class="main-sidebar">
-    <!-- sidebar: style can be found in sidebar.less -->
-    <section class="sidebar">
-      <!-- /.search form -->
-      <!-- sidebar menu: : style can be found in sidebar.less -->
-      <ul class="sidebar-menu">
-        <li class="header">MAIN NAVIGATION</li>
-        <li class="treeview active">
-          <a href="#">
-            <i class="fa fa-folder"></i> <span>diagbot</span>
-            <span class="pull-right-container">
+    </header>
+    <!-- Left side column. contains the logo and sidebar -->
+    <aside class="main-sidebar">
+        <!-- sidebar: style can be found in sidebar.less -->
+        <section class="sidebar">
+            <!-- /.search form -->
+            <!-- sidebar menu: : style can be found in sidebar.less -->
+            <ul class="sidebar-menu">
+                <li class="header">MAIN NAVIGATION</li>
+                <li class="treeview active">
+                    <a href="#">
+                        <i class="fa fa-folder"></i> <span>diagbot</span>
+                        <span class="pull-right-container">
               <i class="fa fa-angle-left pull-right"></i>
             </span>
-          </a>
-          <ul class="treeview-menu">
-            <li class="active"><a href="/push-web/participle/index"><i class="fa fa-circle-o"></i>分词示例</a></li>
-            <li class="active"><a href="/push-web/extract/index"><i class="fa fa-circle-o"></i>提取特征</a></li>
-            <li class="active"><a href="/push-web/relation/index"><i class="fa fa-circle-o"></i>关系抽取</a></li>
-            <li class="active"><a href="/push-web/algorithm/index"><i class="fa fa-circle-o"></i>算法分析</a></li>
-          </ul>
-        </li>
-      </ul>
-    </section>
-    <!-- /.sidebar -->
-  </aside>
+                    </a>
+                    <ul class="treeview-menu">
+                        <li class="active"><a href="/push-web/participle/index"><i class="fa fa-circle-o"></i>分词示例</a>
+                        </li>
+                        <li class="active"><a href="/push-web/extract/index"><i class="fa fa-circle-o"></i>提取特征</a></li>
+                        <li class="active"><a href="/push-web/relation/index"><i class="fa fa-circle-o"></i>关系抽取</a>
+                        </li>
+                        <li class="active"><a href="/push-web/algorithm/index"><i class="fa fa-circle-o"></i>算法分析</a>
+                        </li>
+                    </ul>
+                </li>
+            </ul>
+        </section>
+        <!-- /.sidebar -->
+    </aside>
 
-  <!-- Content Wrapper. Contains page content -->
-  <div class="content-wrapper">
-    <!-- Content Header (Page header) -->
-    <section class="content-header">
-      <h1>
-        <small></small>
-      </h1>
-      <ol class="breadcrumb">
-        <li><a href="#"><i class="fa fa-dashboard"></i>Diagbot</a></li>
-        <li><a href="#">nlp</a></li>
-        <li class="active">分词示例</li>
-      </ol>
-    </section>
-    <!-- Main content -->
-    <section class="invoice">
-      <!-- title row -->
-      <div class="row">
-        <div class="col-xs-12">
-          <h2 class="page-header">
-            <form role="form" id="up_file_form" enctype='multipart/form-data' style="position: relative;">
-              <i class="fa"></i>病 例
-            </form>
-          </h2>
-        </div>
-        <!-- /.col -->
-      </div>
-      <!-- /.box-header -->
-      <div class="box-body">
-        <div class="row">
-          <div class="col-xs-12">
-            <form role="form" id="participle_form">
-              <!-- textarea -->
-              <div class="form-group">
+    <!-- Content Wrapper. Contains page content -->
+    <div class="content-wrapper">
+        <!-- Content Header (Page header) -->
+        <section class="content-header">
+            <h1>
+                <small></small>
+            </h1>
+            <ol class="breadcrumb">
+                <li><a href="#"><i class="fa fa-dashboard"></i>Diagbot</a></li>
+                <li><a href="#">nlp</a></li>
+                <li class="active">分词示例</li>
+            </ol>
+        </section>
+        <!-- Main content -->
+        <section class="invoice">
+            <!-- title row -->
+            <div class="row">
+                <div class="col-xs-12">
+                    <h2 class="page-header">
+                        <form role="form" id="up_file_form" enctype='multipart/form-data' style="position: relative;">
+                            <i class="fa"></i>病 例
+                        </form>
+                    </h2>
+                </div>
+                <!-- /.col -->
+            </div>
+            <!-- /.box-header -->
+            <div class="box-body">
+                <div class="row">
+                    <div class="col-xs-12">
+                        <form role="form" id="participle_form">
+                            <!-- textarea -->
+                            <div class="form-group">
                 <textarea class="form-control" rows="5" placeholder="Enter ..." name="content" id="content">
 患者11天前烧水时出现心悸,胸闷,感全身不适全身血管跳动,头晕,四肢乏力,视物旋转,恶心,耳鸣,持续1小时后好转。10天前再次出现心悸,胸闷,感全身血管跳动,四肢乏力。6天前聊天时再次出现意识丧失,症状同前,建议转上级医院诊治,遂来我院就诊。
 </textarea>
-              </div>
-            </form>
-          </div>
-        </div>
-        <div class="row">
-          <div class="col-xs-12">
-            <button type="button" class="btn btn-success pull-right" onclick="_ajax('/relation/extraction')"><i
-                    class="fa fa-credit-card"></i> 开&nbsp;始&nbsp;分&nbsp;析
-            </button>
-          </div>
-        </div>
-      </div>
-      <script>
-          function _ajax(url) {
-              $.support.cors = true;
-              $.ajax({
-                  url: nlp_web_url + url,
-                  data: $("#participle_form").serialize(),
-                  dataType: "json",
-                  type: "post",
-                  success: function (data) {
-                      var outputInfos = data.data;
-                      $.each(outputInfos, function (key, item) {
-                          h += "<div class='form-group'><label>" + key + ":&nbsp;</label>";
-                          $.each(item,function (k, t) {
-                              if  (t == null) {
-                                  t = "";
-                              }
-                              h += "&nbsp;(<label>" + k + ":" + t + "</label>)&nbsp;";
-                          });
-                          h += "</div>";
-                      });
-                      $("#relation_result").html(data.data);
-                  }
-              });
-          };
-      </script>
-      <div class="row">
-          <div class="col-md-12">
-              <div class="box box-solid">
-                  <div class="box-header with-border">
-                      <i class="fa fa-text-width"></i>
-                      <h3 class="box-title">结 构 化</h3>
-                  </div>
-                  <!-- /.box-header -->
-                  <div class="box-body">
-                      <dl class="dl-horizontal" id="relation_result">
-                          <dt>Description lists</dt>
-                          <dd>A description list is perfect for defining terms.</dd>
-                          <dd>A description list is perfect for defining terms.</dd>
-                          <dt>Euismod</dt>
-                          <dd>Vestibulum id ligula porta felis euismod semper eget lacinia odio sem nec elit.</dd>
-                          <dd>Donec id elit non mi porta gravida at eget metus.</dd>
-                          <dt>Malesuada porta</dt>
-                          <dd>Etiam porta sem malesuada magna mollis euismod.</dd>
-                          <dt>Felis euismod semper eget lacinia</dt>
-                          <dd>Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo
-                              sit amet risus.
-                          </dd>
-                      </dl>
-                  </div>
-                  <!-- /.box-body -->
-              </div>
-              <!-- /.box -->
-          </div>
-          <!-- ./col -->
-        </div>
-      </div>
+                            </div>
+                        </form>
+                    </div>
+                </div>
+                <div class="row">
+                    <div class="col-xs-12">
+                        <button type="button" class="btn btn-success pull-right"
+                                onclick="_ajax('/relation/extraction')"><i
+                                class="fa fa-credit-card"></i> 开&nbsp;始&nbsp;分&nbsp;析
+                        </button>
+                    </div>
+                </div>
+            </div>
+            <script>
+                function _ajax(url) {
+                    $.support.cors = true;
+                    $.ajax({
+                        url: nlp_web_url + url,
+                        data: $("#participle_form").serialize(),
+                        dataType: "json",
+                        type: "post",
+                        success: function (data) {
+                            var outputInfos = data.data;
+                            var h = "";
+                            $.each(outputInfos, function (index, symptoms) {
+                                $.each(symptoms, function (symptom_index, symptom) {
+                                    h += "<dt>" + symptom.symptomName + "</dt>";
+                                    if (symptom.bodyPart != null) {
+                                        if (symptom.bodyPart.direction != null) {
+                                            h += "<dd>" + symptom.bodyPart.direction + symptom.bodyPart.partBodyName + "</dd>";
+                                        } else {
+                                            h += "<dd>" + symptom.bodyPart.partBodyName + "</dd>";
+                                        }
+                                    }
+                                    if (symptom.property != null) {
+                                        h += "<dd>" + symptom.property.propertyName + "</dd>";
+                                    }
+                                    if (symptom.cause != null) {
+                                        h += "<dd>" + symptom.cause.causeName + "</dd>";
+                                    }
+                                    if (symptom.pd != null) {
+                                        h += "<dd>" + symptom.pd.value + "</dd>";
+                                    }
+                                    if (symptom.degree != null) {
+                                        if (symptom.degree.pd != null) {
+                                            h += "<dd>" + symptom.degree.degreeName + "(" + symptom.degree.pd.value + ")</dd>";
+                                        } else {
+                                            h += "<dd>" + symptom.degree.degreeName + "</dd>";
+                                        }
+                                    }
+                                    if (symptom.negative != null) {
+                                        h += "<dd>" + symptom.negative.negaName + "</dd>";
+                                    }
+                                });
+                            });
+                            $("#relation_result").html(h);
+                        }
+                    });
+                };
+            </script>
+            <div class="row">
+                <div class="col-md-12">
+                    <div class="box box-solid">
+                        <div class="box-header with-border">
+                            <i class="fa fa-text-width"></i>
+                            <h3 class="box-title">结 构 化</h3>
+                        </div>
+                        <!-- /.box-header -->
+                        <div class="box-body">
+                            <dl class="dl-horizontal" id="relation_result">
+                            </dl>
+                        </div>
+                        <!-- /.box-body -->
+                    </div>
+                    <!-- /.box -->
+                </div>
+                <!-- ./col -->
+            </div>
+    </div>
     </section>
     <!-- /.content -->
     <div class="clearfix"></div>
-  </div>
+</div>
 
-  <!-- /.control-sidebar -->
-  <!-- Add the sidebar's background. This div must be placed
-       immediately after the control sidebar -->
-  <div class="control-sidebar-bg"></div>
+<!-- /.control-sidebar -->
+<!-- Add the sidebar's background. This div must be placed
+     immediately after the control sidebar -->
+<div class="control-sidebar-bg"></div>
 </div>
 <!-- ./wrapper -->