kongwz 6 vuotta sitten
vanhempi
commit
4fc160d628

+ 1 - 0
graph-web/src/main/java/org/diagbot/graphWeb/work/GraphCalculate.java

@@ -30,6 +30,7 @@ public class GraphCalculate {
         if(searchData.getLisArr().size()!=0){
             JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(searchData.getLisArr()));
             List<String> lisResult = neo4jAPI.AnalysisLISResult(jsonArray);
+            System.out.println(lisResult);
             inputList.addAll(lisResult);
         }
         //计算提出的词,是否在图谱中找到

+ 20 - 25
graph/src/main/java/org/diagbot/graph/encryption/Coder.java

@@ -53,7 +53,7 @@ public abstract class Coder {
     /**
      * BASE64解密
      *
-     * @param key
+     *
      * @return
      * @throws Exception
      *
@@ -64,7 +64,7 @@ public abstract class Coder {
     /**
      * BASE64加密
      *
-     * @param key
+     *
      * @return
      * @throws Exception
      *
@@ -75,7 +75,7 @@ public abstract class Coder {
     /**
      * MD5加密
      *
-     * @param data
+     *
      * @return
      * @throws Exception
      *
@@ -91,7 +91,7 @@ public abstract class Coder {
     /**
      * SHA加密
      *
-     * @param data
+     *
      * @return
      * @throws Exception
      *
@@ -119,8 +119,8 @@ public abstract class Coder {
     /**
      * HMAC加密
      *
-     * @param data
-     * @param key
+     *
+     *
      * @return
      * @throws Exception
      *
@@ -137,7 +137,7 @@ public abstract class Coder {
     /**
      * 将加密后的数据转换成16进制
      *
-     * @param encryptbytes
+     *
      *
     public static String getHash(byte[] encryptbytes) {
 
@@ -176,7 +176,7 @@ public abstract class Coder {
     /**
      * 将16进制的加密数据转换成byte数组
      *
-     * @param hash
+     *
      *
     public static byte[] deHash(String hash) {
 
@@ -215,26 +215,22 @@ public abstract class Coder {
         }
     }
     */
-
+    /**
+     * 加密
+     * @param token
+     * @return
+     */
     public static String Encrypt(String token) {
-        String result = null;
         String hash = null;
 
         try {
-//            System.out.println(token);
-//            result = DESUtil.encrypt(token, DESUtil.KEY_LANTONE);
-
-//            hash = DESUtil.padding + Encrypt.getHash(Base64.decodeBase64(result));
-            if (!Encrypt.isEng(token)) {
+            if (!isEng(token)) {
                 hash = Coder.StringToUTF8(token);
             }
             else {
                 hash = Coder.StringToA(token);
             }
             hash = Base64.encodeBase64String(hash.getBytes("utf-8"));
-
-//            result = token;
-//            System.out.println(result);
         }
         catch (Exception ex) {
             ex.printStackTrace();
@@ -244,24 +240,23 @@ public abstract class Coder {
         }
     }
 
+    /**
+     * 解密
+     * @param code
+     * @return
+     */
     public static String Decrypt(String code) {
         String result = null;
 
         try {
-//            code = code.substring(DESUtil.padding.length());
             byte[] bytes = Base64.decodeBase64(code);
-//            byte[] bytes = Encrypt.deHash(code);
-//            System.out.println(bytes);
             result = new String(bytes, "utf-8");
-//            System.out.println(result);
-//            result = DESUtil.decrypt(code, DESUtil.KEY_LANTONE);
-            if (Encrypt.isNum(result)) {
+            if (isNum(result)) {
                 result = Coder.AToString(result);
             }
             else {
                 result = Coder.UTF8ToString(result);
             }
-//            System.out.println(result);
         }
         catch (Exception ex) {
             ex.printStackTrace();

+ 3 - 3
graph/src/main/java/org/diagbot/graph/encryption/DESUtil.java

@@ -34,7 +34,7 @@ public class DESUtil {
     /**
      *
      * 生成密钥key对象
-     * @param KeyStr 密钥字符串
+     *
      * @return 密钥对象
      * @throws InvalidKeyException
      * @throws NoSuchAlgorithmException
@@ -91,10 +91,10 @@ public class DESUtil {
             }
             results = cipher.doFinal(data.getBytes());
             // 该部分是为了与加解密在线测试网站(http://tripledes.online-domain-tools.com/)的十六进制结果进行核对
-            for (int i = 0; i < results.length; i++) {
+           /* for (int i = 0; i < results.length; i++) {
                 System.out.print(results[i] + " ");
             }
-            System.out.println();
+            System.out.println();*/
         }
         catch (Exception ex) {
             ex.printStackTrace();

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 138 - 0
graph/src/main/java/org/diagbot/graph/encryptionNeo4j/ReadNeo4jData2Neo4j.java


+ 4 - 0
graph/src/main/java/org/diagbot/graph/jdbc/Neo4jAPI.java

@@ -681,7 +681,10 @@ public class Neo4jAPI {
                 fildList.add(d);
             }
             newList.addAll(fildList);
+            System.out.println("开始输入的词为:"+newList);
+            int i=0;
             while (newList.size()>0){
+                i++;
                 query="with "+newList+" as data unwind data as row\n" +
                         "match (l)-[r:诊断依据]->(m)\n" +
                         "where l.name= row\n" +
@@ -689,6 +692,7 @@ public class Neo4jAPI {
                         "match (n)-[r:诊断依据]->(m)\n" +
                         "where n.name= row\n" +
                         "return m.name as condition, count(distinct r)>=m.path as jundgement, labels(m)[0] as label";
+                System.out.println(i+"\t"+query);
                 result=session.run(query);
                 newList.clear();
                 while (result.hasNext()){

+ 76 - 0
graph/src/main/java/org/diagbot/graph/util/ConnectionNeo4j.java

@@ -0,0 +1,76 @@
+package org.diagbot.graph.util;
+
+import org.neo4j.driver.v1.AuthTokens;
+import org.neo4j.driver.v1.Config;
+import org.neo4j.driver.v1.Driver;
+import org.neo4j.driver.v1.GraphDatabase;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * 连接neo4j,关闭neo4j工具类
+ * Created by DELL on 2018/11/15.
+ */
+public class ConnectionNeo4j {
+    public Driver connectionNeo4j(){
+        Driver driver=null;
+        InputStream inputstream;
+        try {
+            Properties prop = new Properties();
+
+            inputstream = this.getClass().getClassLoader().getResourceAsStream("bolt.properties");
+
+            if (inputstream != null) {
+                prop.load(inputstream);
+                String uri = prop.getProperty("bolt.uri");
+                String user = prop.getProperty("bolt.user");
+                String passwd = prop.getProperty("bolt.passwd");
+
+                driver = GraphDatabase.driver(uri, AuthTokens.basic(user, passwd),
+                        Config.build().withMaxConnectionLifetime(30, TimeUnit.MINUTES)
+                                .withMaxTransactionRetryTime(5, TimeUnit.SECONDS)
+                                .withMaxConnectionPoolSize(50)
+                                .withConnectionAcquisitionTimeout(2, TimeUnit.MINUTES)
+                                .toConfig()
+                );
+            }
+        } catch (IOException ioe) {
+            ioe.printStackTrace();
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+        return driver;
+    }
+    public Driver connection232Neo4j(){
+        Driver driver=null;
+        InputStream inputstream;
+        try {
+            Properties prop = new Properties();
+
+            inputstream = this.getClass().getClassLoader().getResourceAsStream("bolt.properties");
+
+            if (inputstream != null) {
+                prop.load(inputstream);
+                String uri = prop.getProperty("bolt232.uri");
+                String user = prop.getProperty("bolt232.user");
+                String passwd = prop.getProperty("bolt232.passwd");
+
+                driver = GraphDatabase.driver(uri, AuthTokens.basic(user, passwd),
+                        Config.build().withMaxConnectionLifetime(30, TimeUnit.MINUTES)
+                                .withMaxTransactionRetryTime(5, TimeUnit.SECONDS)
+                                .withMaxConnectionPoolSize(50)
+                                .withConnectionAcquisitionTimeout(2, TimeUnit.MINUTES)
+                                .toConfig()
+                );
+            }
+        } catch (IOException ioe) {
+            ioe.printStackTrace();
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+        return driver;
+    }
+}

+ 175 - 0
graph/src/main/java/org/diagbot/graph/util/NodeRelationUtil.java

@@ -0,0 +1,175 @@
+package org.diagbot.graph.util;
+
+import org.diagbot.graph.encryption.DESUtil;
+import org.neo4j.driver.v1.*;
+import org.neo4j.graphdb.RelationshipType;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.neo4j.driver.v1.Values.parameters;
+
+/**
+ * 节点,关系库
+ * Created by DELL on 2018/11/26.
+ */
+public class NodeRelationUtil {
+    private static Driver driver;
+    private static Map<String, String> RelaType = new HashMap<>();
+    private enum RelType implements RelationshipType {
+        is_a, equal
+    }
+
+    /**
+     * 获取driver
+     * @return
+     */
+    public Driver getDriver(){
+        ConnectionNeo4j connectionNeo4j = new ConnectionNeo4j();
+        driver=connectionNeo4j.connectionNeo4j();
+        return driver;
+    }
+    public Driver get232Driver(){
+        ConnectionNeo4j connectionNeo4j = new ConnectionNeo4j();
+        driver=connectionNeo4j.connection232Neo4j();
+        return driver;
+    }
+
+    /**
+     * 创建节点,节点不带属性
+     * @param lbl 标签名字
+     * @param val 节点名字
+     */
+    public void AddNode(final Driver driver, final String lbl, final String val) {
+
+        Session session = null;
+
+
+        try {
+            session = driver.session(AccessMode.WRITE);
+            session.writeTransaction(new TransactionWork<Integer>() {
+                @Override
+                public Integer execute(Transaction tx) {
+                    String query = "MERGE (n:" + DESUtil.encrypt(lbl,DESUtil.KEY_LANTONE) + "{name:$name}) RETURN n";
+
+                    int result = processNode(tx, query, "name", DESUtil.encrypt(val,DESUtil.KEY_LANTONE));
+                    return result;
+                }
+            });
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        } finally {
+            if (session != null) session.close();
+        }
+    }
+    /**
+     * 创建节点,节点带属性
+     * @param lbl 标签名字
+     * @param val 节点名字
+     */
+    public void AddNode(final Driver driver, final String lbl, final String val, final Integer path) {
+
+        Session session = null;
+
+
+        try {
+            session = driver.session(AccessMode.WRITE);
+            session.writeTransaction(new TransactionWork<Integer>() {
+                @Override
+                public Integer execute(Transaction tx) {
+                    String query = "MERGE (n:" + lbl + "{name:$name,path:$path}) RETURN n";
+                    int result = processNodepro(tx, query, "name", val,"path",path);
+                    return result;
+                }
+            });
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        } finally {
+            if (session != null) session.close();
+        }
+    }
+    /**
+     * 创建节点,节点带属性
+     * @param lbl 标签名字
+     * @param val 节点名字
+     */
+    public void AddNode(final Driver driver, final String lbl, final String val, final Integer path, final String relation) {
+
+        Session session = null;
+
+
+        try {
+            session = driver.session(AccessMode.WRITE);
+            session.writeTransaction(new TransactionWork<Integer>() {
+                @Override
+                public Integer execute(Transaction tx) {
+                    String query = "MERGE (n:" + DESUtil.encrypt(lbl,DESUtil.KEY_LANTONE) + "{name:$val,path:$path,relation:$relation}) RETURN n";
+                    int result = processNodepro(tx, query, "val", DESUtil.encrypt(val,DESUtil.KEY_LANTONE),"path",path,"relation",relation);
+                    return result;
+                }
+            });
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        } finally {
+            if (session != null) session.close();
+        }
+    }
+    /**
+     * 为两个节点添加关系
+     * @param fromlbl 标签类型
+     * @param fromval 节点名字
+     * @param relation 关系
+     * @param tolbl 标签类型
+     * @param toval 节点名字
+     */
+    public void addRelation(final Driver driver, final String fromlbl, final String fromval, final String relation, final String tolbl, final String toval){
+        Session session = null;
+        //两个节点之间,有关系,先删除
+        try {
+            session = driver.session(AccessMode.WRITE);
+//            session.writeTransaction(new TransactionWork<Integer>() {
+//                @Override
+//                public Integer execute(Transaction tx) {
+//                    String query = "MATCH (e:" + fromlbl + "{name:$src})-[r]->(c:" +
+//                            tolbl + "{name:$dest}) DELETE r";
+//                    int result = processRelation(tx, query, "src", fromval, "dest", toval);
+//                    return result;
+//                }
+//            });
+            //为两个节点添加关系
+            session.writeTransaction(new TransactionWork<Integer>() {
+                @Override
+                public Integer execute(Transaction tx) {
+                    String query = "MATCH (e:" + DESUtil.encrypt(fromlbl,DESUtil.KEY_LANTONE) + "{name:$src}), (c:" + DESUtil.encrypt(tolbl,DESUtil.KEY_LANTONE) + "{name:$dest}) " +
+                            "MERGE (e)-[r:" + DESUtil.encrypt(relation,DESUtil.KEY_LANTONE) + "]->(c) RETURN e.name, type(r), c.name";
+                    int result = processRelation(tx, query, "src", DESUtil.encrypt(fromval,DESUtil.KEY_LANTONE), "dest", DESUtil.encrypt(toval,DESUtil.KEY_LANTONE));
+                    return result;
+                }
+            });
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        } finally {
+            if (session != null) session.close();
+        }
+    }
+
+    private int processRelation(Transaction tx, String query, String srclbl,
+                                String srcname, String destlbl, String destname) {
+        tx.run(query, parameters(srclbl, srcname, destlbl, destname));
+        return 1;
+    }
+    private int processNode(Transaction tx, String query, String label, String val) {
+        tx.run(query, parameters(label, val));
+        return 1;
+    }
+    //带属性
+    private int processNodepro(Transaction tx, String query, String label, String val, String parm, Integer path) {
+        tx.run(query, parameters(label, val,parm,path));
+        return 1;
+    }
+    //带属性
+    private int processNodepro(Transaction tx, String query, String label, String val, String parm, Integer path, String relation, String relation1) {
+        tx.run(query, parameters(label, val,parm,path,relation,relation1));
+        return 1;
+    }
+}

+ 11 - 0
graph/src/main/java/org/diagbot/graph/util/PropertityTest.java

@@ -0,0 +1,11 @@
+package org.diagbot.graph.util;
+
+import org.diagbot.pub.utils.PropertiesUtil;
+
+public class PropertityTest {
+    public static void main(String[] args) {
+        PropertiesUtil propertiesUtil = new PropertiesUtil("bolt.properties");
+        String property = propertiesUtil.getProperty("bolt232.uri");
+        System.out.println(property);
+    }
+}

+ 25 - 0
graph/src/main/resources/bolt.properties

@@ -0,0 +1,25 @@
+# neo4j bolt credentials
+#\u05AA\u02B6\u037C\uFFFD\uFFFD233
+bolt.uri=bolt://192.168.2.233
+bolt.user=neo4j
+bolt.passwd=root
+
+bolt232.uri=bolt://192.168.2.232
+bolt232.user=neo4j
+bolt232.passwd=root
+
+#\u05AA\u02B6\u037C\uFFFD\uFFFD192.168.3.112
+#bolt.uri=bolt://192.168.3.112
+#bolt.user=neo4j
+#bolt.passwd=123456
+
+sql1=with "+newList+" as data unwind data as row\n \
+  match (l)-[r:\u8BCA\u65AD\u4F9D\u636E]->(m)\n \
+  where l.name= row\n \
+  with m,"+fildList+" as data unwind data as row\n \
+  match (n)-[r:\u8BCA\u65AD\u4F9D\u636E]->(m)\n \
+  where n.name= row\n \
+  return m.name as condition, count(distinct r)>=m.path as jundgement, labels(m)[0] as label
+
+#\u67E5\u627E\u4E00\u4E9B\u8BCD\u662F\u5426\u5728\u56FE\u8C31\u4E2D
+searchWords=match(d) where d.name in fildList return distinct d.name as name