Kaynağa Gözat

训练正样本查看

louhr 6 yıl önce
ebeveyn
işleme
b0b37e61e2

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

@@ -1,14 +1,18 @@
 package org.diagbot.nlp.controller;
 
+import org.diagbot.nlp.dao.model.TaggingResult;
 import org.diagbot.nlp.feature.FeatureType;
 import org.diagbot.nlp.relation.analyze.RelationAnalyze;
 import org.diagbot.nlp.relation.util.OutputInfo;
 import org.diagbot.pub.api.Response;
+import org.diagbot.pub.jdbc.MysqlJdbc;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @ClassName org.diagbot.nlp.controller.RelationExtractionController
@@ -31,4 +35,62 @@ public class RelationExtractionController {
         response.setData(outputInfos);
         return response;
     }
+
+    @RequestMapping({"/list"})
+    @ResponseBody
+    public Response<List<TaggingResult>> list(int pageNum) throws Exception {
+        Response<List<TaggingResult>> response = new Response();
+        MysqlJdbc nlpJdbc = new MysqlJdbc("root", "diagbot@20180822", "jdbc:mysql://192.168.2.235:3306/nlp-web?useUnicode=true&characterEncoding=UTF-8");
+        List<Map<String, String>> data = nlpJdbc.query("re_tagging_result_part",
+                new String[]{"sentence_id", "sentence", "entity_1_name", "entity_2_name", "relation", "entity_1_position", "entity_2_position"},
+                " where relation = 1 order by sentence_id, sentence limit " + pageNum * 100 + ", 100");
+
+        String sentence = "";
+        String s = "";
+        String[] position1 = null;
+        String[] position2 = null;
+        List<TaggingResult> taggingResults = new ArrayList<>();
+        for (Map<String, String> map : data) {
+            TaggingResult tr = new TaggingResult();
+            tr.setSentenceId(map.get("sentence_id"));
+            tr.setEntity1Name(map.get("entity_1_name"));
+            tr.setEntity2Name(map.get("entity_2_name"));
+            tr.setEntity1Position(map.get("entity_1_position"));
+            tr.setEntity2Position(map.get("entity_2_position"));
+            tr.setRelation(map.get("relation"));
+
+            sentence = map.get("sentence");
+            position1 = tr.getEntity1Position().split(",");
+            position2 = tr.getEntity2Position().split(",");
+            if ("0".equals(position1[0])) {
+                s = "<span class=\"label label-success\">";
+            } else {
+                s = sentence.substring(0, Integer.parseInt(position1[0]))
+                        + "<span class=\"label label-success\">";
+            }
+            s = s + sentence.substring(Integer.parseInt(position1[0]), Integer.parseInt(position1[1]) + 1) + "</span>";
+            if (position1[1].equals(position2[0])) {
+                if (Integer.parseInt(position2[1]) == sentence.length() - 1) {
+                    s = s + "<span class=\"label label-success\">" + sentence.substring(Integer.parseInt(position2[0])) + "</span>";
+                } else {
+                    s = s + "<span class=\"label label-success\">" + sentence.substring(Integer.parseInt(position2[0]), Integer.parseInt(position2[1]) + 1) + "</span>";
+                }
+            } else {
+                s = s + sentence.substring(Integer.parseInt(position1[1]) + 1, Integer.parseInt(position2[0]));
+
+                if (Integer.parseInt(position2[1]) == sentence.length() - 1) {
+                    s = s + "<span class=\"label label-success\">" + sentence.substring(Integer.parseInt(position2[0])) + "</span>";
+                } else {
+                    s = s + "<span class=\"label label-success\">" + sentence.substring(Integer.parseInt(position2[0]), Integer.parseInt(position2[1]) + 1) + "</span>";
+                    s = s + sentence.substring(Integer.parseInt(position2[1]) + 1);
+                }
+            }
+
+            tr.setSentence(s);
+            taggingResults.add(tr);
+        }
+
+        response.setData(taggingResults);
+        return response;
+    }
 }

+ 74 - 0
nlp-web/src/main/java/org/diagbot/nlp/dao/model/TaggingResult.java

@@ -0,0 +1,74 @@
+package org.diagbot.nlp.dao.model;
+
+/**
+ * @ClassName org.diagbot.nlp.dao.model.TaggingResult
+ * @Description TODO
+ * @Author fyeman
+ * @Date 2019/3/27/027 13:25
+ * @Version 1.0
+ **/
+public class TaggingResult {
+    private String sentenceId;
+    private String sentence;
+    private String entity1Name;
+    private String entity2Name;
+    private String relation;
+    private String entity1Position;
+    private String entity2Position;
+
+    public String getSentenceId() {
+        return sentenceId;
+    }
+
+    public void setSentenceId(String sentenceId) {
+        this.sentenceId = sentenceId;
+    }
+
+    public String getSentence() {
+        return sentence;
+    }
+
+    public void setSentence(String sentence) {
+        this.sentence = sentence;
+    }
+
+    public String getEntity1Name() {
+        return entity1Name;
+    }
+
+    public void setEntity1Name(String entity1Name) {
+        this.entity1Name = entity1Name;
+    }
+
+    public String getEntity2Name() {
+        return entity2Name;
+    }
+
+    public void setEntity2Name(String entity2Name) {
+        this.entity2Name = entity2Name;
+    }
+
+    public String getRelation() {
+        return relation;
+    }
+
+    public void setRelation(String relation) {
+        this.relation = relation;
+    }
+
+    public String getEntity1Position() {
+        return entity1Position;
+    }
+
+    public void setEntity1Position(String entity1Position) {
+        this.entity1Position = entity1Position;
+    }
+
+    public String getEntity2Position() {
+        return entity2Position;
+    }
+
+    public void setEntity2Position(String entity2Position) {
+        this.entity2Position = entity2Position;
+    }
+}

+ 0 - 28
nlp/src/main/java/org/diagbot/nlp/relation/extract/PresentExtract.java

@@ -110,33 +110,5 @@ public class PresentExtract extends BaseExtract {
             negative.setNegaName(lemma.getText());
             symptom.setNegative(negative);
         }
-
-        //体征指标
-        if (NlpUtil.isFeature(lemma.getProperty(), Constants.vital_index_type)) {
-            Item item = new Item();
-            item.setItemName(lemma.getText());
-            for (Lemma l : lemma.getRelationLemmas()) {
-                if (NlpUtil.isFeature(l.getProperty(), Constants.vital_type)) {
-                    Desc desc = new Desc();
-                    desc.setInfo(l.getText());
-                    item.setDesc(desc);
-                }
-            }
-            symptom.setItem(item);
-        }
-
-        //体征指标值 体征结果放入描述信息
-        if (NlpUtil.isFeature(lemma.getProperty(), Constants.vital_type)) {
-            Desc desc = new Desc();
-            desc.setInfo(lemma.getText());
-            for (Lemma l : lemma.getRelationLemmas()) {
-                if (NlpUtil.isFeature(l.getProperty(), Constants.degree_type)) {
-                    Degree degree = new Degree();
-                    degree.setDegreeName(l.getText());
-                    desc.setDegree(degree);
-                }
-            }
-            symptom.setDesc(desc);
-        }
     }
 }

+ 0 - 27
nlp/src/main/java/org/diagbot/nlp/relation/module/Symptom.java

@@ -18,9 +18,6 @@ public class Symptom {
     private Cause cause;
     private Property property;
     private PD pd;
-    private Factor factor;
-    private Item item;
-    private Desc desc;
 
     public String getSymptomName() {
         return symptomName;
@@ -77,28 +74,4 @@ public class Symptom {
     public void setPd(PD pd) {
         this.pd = pd;
     }
-
-    public Factor getFactor() {
-        return factor;
-    }
-
-    public void setFactor(Factor factor) {
-        this.factor = factor;
-    }
-
-    public Item getItem() {
-        return item;
-    }
-
-    public void setItem(Item item) {
-        this.item = item;
-    }
-
-    public Desc getDesc() {
-        return desc;
-    }
-
-    public void setDesc(Desc desc) {
-        this.desc = desc;
-    }
 }

+ 6 - 6
nlp/src/test/java/org/diagbot/nlp/test/EntityExtractTest.java

@@ -87,11 +87,11 @@ public class EntityExtractTest {
                         "entity_1_name", "entity_2_name", "entity_1_prop", "entity_2_prop", "entity_1_prop_name", "entity_2_prop_name", "relation"});
             }
 
-//            if (results_none_pair.size() > 0) {
-//                MysqlJdbc nlpJdbc = new MysqlJdbc("root", "diagbot@20180822", "jdbc:mysql://192.168.2.235:3306/nlp-web?useUnicode=true&characterEncoding=UTF-8");
-//                nlpJdbc.insert(results_none_pair, "re_tagging_result_none_compare", new String[]{"sentence_id", "sentence_uuid", "sentence", "entity_1_position", "entity_2_position",
-//                        "entity_1_name", "entity_2_name", "entity_1_prop", "entity_2_prop", "entity_1_prop_name", "entity_2_prop_name", "relation"});
-//            }
+            if (results_none_pair.size() > 0) {
+                MysqlJdbc nlpJdbc = new MysqlJdbc("root", "diagbot@20180822", "jdbc:mysql://192.168.2.235:3306/nlp-web?useUnicode=true&characterEncoding=UTF-8");
+                nlpJdbc.insert(results_none_pair, "re_tagging_result_part_new_none", new String[]{"sentence_id", "sentence_uuid", "sentence", "entity_1_position", "entity_2_position",
+                        "entity_1_name", "entity_2_name", "entity_1_prop", "entity_2_prop", "entity_1_prop_name", "entity_2_prop_name", "relation"});
+            }
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -132,7 +132,7 @@ public class EntityExtractTest {
 
     public List<Map<String, String>> searchData() {
         MysqlJdbc nlpJdbc = new MysqlJdbc("root", "diagbot@20180822", "jdbc:mysql://192.168.2.235:3306/nlp-web?useUnicode=true&characterEncoding=UTF-8");
-        List<Map<String, String>> data = nlpJdbc.query("tb_ryjl_extract", new String[]{"zyxh", "xbs"}, " limit 3, 3");
+        List<Map<String, String>> data = nlpJdbc.query("tb_ryjl_extract", new String[]{"zyxh", "xbs"}, " limit 15, 100");
         return data;
     }
 

+ 5 - 0
push-web/src/main/java/org/diagbot/push/controller/RelationController.java

@@ -21,4 +21,9 @@ public class RelationController extends BaseController {
     public String index() {
         return listView;
     }
+
+    @RequestMapping({"/list"})
+    public String list() {
+        return "/pages/label/list.html";
+    }
 }

+ 2 - 0
push-web/src/main/resources/static/index.html

@@ -67,6 +67,8 @@
             <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/relation/list"><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>
             <li class="active"><a href="/push-web/graph/index"><i class="fa fa-circle-o"></i>知识图谱分析</a></li>
           </ul>

+ 2 - 0
push-web/src/main/resources/static/pages/algorithm/list.html

@@ -63,6 +63,8 @@
                     <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/list"><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>

+ 2 - 0
push-web/src/main/resources/static/pages/extract/feature.html

@@ -63,6 +63,8 @@
                     <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/list"><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>

+ 210 - 0
push-web/src/main/resources/static/pages/label/list.html

@@ -0,0 +1,210 @@
+<!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">
+
+    <!-- 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>
+</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>
+    <!-- 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/list"><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">
+            <div class="row">
+                <div class="row">
+                    <div class="col-xs-12">
+                        <button type="button" class="btn btn-success pull-right"
+                                onclick="_ajax()"><i
+                                class="fa fa-credit-card"></i> 开始
+                        </button>
+                        <button type="button" class="btn btn-success pull-right"
+                                onclick="after()"><i
+                                class="fa fa-credit-card"></i> 下一页
+                        </button>
+                        <button type="button" class="btn btn-success pull-right"
+                                onclick="before()"><i
+                                class="fa fa-credit-card"></i> 上一页
+                        </button>
+                    </div>
+                </div>
+                <div class="col-md-12">
+                    <!-- TABLE: LATEST ORDERS -->
+                    <div class="box box-info">
+                        <div class="box-header with-border">
+                            <h3 class="box-title">正样本信息</h3>
+                            <div class="box-tools pull-right">
+                                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
+                                </button>
+                                <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
+                            </div>
+                        </div>
+                        <!-- /.box-header -->
+                        <div class="box-body">
+                            <div class="table-responsive">
+                                <table class="table no-margin">
+                                    <thead>
+                                    <tr>
+                                        <th width="90%">样本</th>
+                                        <th width="10%">ID</th>
+                                    </tr>
+                                    </thead>
+                                    <tbody id="symptom_extract_id">
+                                    </tbody>
+                                </table>
+                            </div>
+                            <!-- /.table-responsive -->
+                        </div>
+                    </div>
+                    <!-- /.box -->
+                </div>
+                <!-- ./col -->
+            </div>
+
+
+
+            <script>
+                var pageNum = 0;
+                function before() {
+                    if (pageNum > 0) {
+                        pageNum = pageNum -1;
+                    }
+                    _ajax();
+                }
+
+                function after() {
+                    pageNum = pageNum +1;
+                    _ajax();
+                }
+
+                function _ajax() {
+                    $.support.cors = true;
+                    $.ajax({
+                        url: nlp_web_url + '/relation/list',
+                        data: {"pageNum":pageNum},
+                        dataType: "json",
+                        type: "post",
+                        success: function (data) {
+                            var taggingResults = data.data;
+                            var h = "";
+                            $.each(taggingResults, function (index, taggingResult) {
+                                h += "<tr><td>";
+                                h += taggingResult.sentence;
+                                h += "</td>";
+                                h += "<td>";
+                                    h += taggingResult.sentenceId;
+                                h += "</td></tr>";
+                            });
+
+                            $("#symptom_extract_id").html(h);
+                        }
+                    });
+                };
+            </script>
+    </section>
+    <!-- /.content -->
+    <div class="clearfix"></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>
+</div>
+<!-- ./wrapper -->
+
+<!-- jQuery 2.2.3 -->
+<script src="../plugins/jQuery/jquery-2.2.3.min.js"></script>
+<!-- Bootstrap 3.3.6 -->
+<script src="../bootstrap/js/bootstrap.min.js"></script>
+<!-- FastClick -->
+<script src="../plugins/fastclick/fastclick.js"></script>
+<!-- AdminLTE App -->
+<script src="../dist/js/app.min.js"></script>
+<!-- AdminLTE for demo purposes -->
+<script src="../dist/js/demo.js"></script>
+
+<script src="../dist/js/push.js"></script>
+</body>
+</html>

+ 2 - 0
push-web/src/main/resources/static/pages/participle/sample.html

@@ -63,6 +63,8 @@
           <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/list"><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>

+ 2 - 0
push-web/src/main/resources/static/pages/relation/sample.html

@@ -64,6 +64,8 @@
                         <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/list"><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>