示例#1
0
 def store_symptom2tonguezhi(self, filter=False, filterSet=set([])):
     FileUtil.print_string(u"开始存储症状和舌质的关系...", True)
     mysqlDb = MysqlOpt()
     neoDb = Neo4jOpt()
     treamentMysql = mysqlDb.select('treatment',
                                    'id,symptomIds,tongueZhiId')
     for treamentUnit in treamentMysql:
         syptomeIds = treamentUnit[1].split(",")
         tid = int(treamentUnit[0])
         tongueZhiId = treamentUnit[2]
         if (filter == True and tid not in filterSet):
             continue
         for syptomeId in syptomeIds:
             tongueZhiNodes = neoDb.selectNodeElementsFromDB(
                 self.TONGUEZHITAG,
                 condition=[],
                 properties={self.NODEID: int(tongueZhiId)})
             syptomeNodes = neoDb.selectNodeElementsFromDB(
                 self.SYMPTOMTAG,
                 condition=[],
                 properties={self.NODEID: int(syptomeId)})
             if (len(tongueZhiNodes) > 0 and len(syptomeNodes) > 0):
                 tongueZhiNode = tongueZhiNodes[0]
                 syptomeNode = syptomeNodes[0]
                 # print(tongueZhiNode['name'])
                 # print(syptomeNode['name'])
                 # print("输出症状%s和舌质%s的关系:%d" % (
                 # syptomeNode['name'].encode('utf8'), tongueZhiNode['name'].encode('utf8'), tid))
                 # 如果节点之间已经存在关系了,则权重加1,否则创建关系
                 relations = neoDb.selectRelationshipsFromDB(
                     syptomeNode, self.SYMPTOM2TONGUEZHITAG, tongueZhiNode)
                 if (len(relations) > 0):
                     # print("更新症状%s和舌质%s的关系" % (syptomeNode['name'].encode('utf8'), tongueZhiNode['name'].encode('utf8')))
                     relation = relations[0]
                     tids = relation[self.RELATIONTID]
                     tids.append(tid)
                     ntids = list(set(tids))
                     nweight = len(ntids)
                     neoDb.updateKeyInRelationship(relation,
                                                   properties={
                                                       self.RELATIONTID:
                                                       ntids,
                                                       self.RELATIONWEIGHT:
                                                       nweight
                                                   })
                 else:
                     tids = [tid]
                     weight = 1
                     neoDb.createRelationship(self.SYMPTOM2TONGUEZHITAG,
                                              syptomeNode,
                                              tongueZhiNode,
                                              propertyDic={
                                                  self.RELATIONTID: tids,
                                                  self.RELATIONWEIGHT:
                                                  weight
                                              })
     mysqlDb.close()
示例#2
0
 def store_pulse(self, filter=False, filterSet=set([])):
     mysqlDb = MysqlOpt()
     neoDb = Neo4jOpt()
     cql = "MATCH (n:" + self.PULSETAG + ") DETACH DELETE n"
     neoDb.graph.data(cql)
     FileUtil.print_string(u"开始存储脉搏节点...", True)
     mysqlDatas = mysqlDb.select('pulse', 'id,name')
     for unit in mysqlDatas:
         id = unit[0]
         name = unit[1]
         if (filter == True and id not in filterSet):
             continue
         neoDb.createNode([self.PULSETAG], {
             self.NODEID: id,
             self.NODENAME: name
         })
     mysqlDb.close()
示例#3
0
 def store_medicine_weight(self, filter=False, filterSet=set([])):
     FileUtil.print_string(u"开始存储每个中药节点的出现的次数...", True)
     mysqlDb = MysqlOpt()
     neoDb = Neo4jOpt()
     treamentMysql = mysqlDb.select('treatment', 'id,prescriptionId')
     for treamentUnit in treamentMysql:
         tid = int(treamentUnit[0])
         # print tid
         pid = int(treamentUnit[1])
         if (filter == True and tid not in filterSet):
             continue
         priscriptionMysql = mysqlDb.select('prescription', 'name',
                                            'id = ' + str(pid))
         if (len(priscriptionMysql) > 0):
             medicineIds = priscriptionMysql[0][0].split(",")
         else:
             continue
         # 针对name末尾有逗号的情况进行处理
         lenth = len(medicineIds)
         if (medicineIds[lenth - 1] == ''):
             medicineIds.pop()
         for medicineId in medicineIds:
             # print "mid"+str(medicineId)
             medicineNodes = neoDb.selectNodeElementsFromDB(
                 self.MEDICINETAG,
                 condition=[],
                 properties={self.NODEID: int(medicineId)})
             if (len(medicineNodes) > 0):
                 medicineNode = medicineNodes[0]
                 tids = []
                 for i in medicineNode[self.NODETID]:
                     tids.append(int(i))
                 tids.append(tid)
                 ntids = list(set(tids))
                 nweight = len(ntids)
                 neoDb.updateKeyInNode(medicineNode,
                                       properties={
                                           self.NODETID: ntids,
                                           self.NODEWEIGHT: nweight
                                       })
     mysqlDb.close()
示例#4
0
 def store_medicine(self, filter=False, filterSet=set([])):
     mysqlDb = MysqlOpt()
     neoDb = Neo4jOpt()
     # 先删除数据库中存在的medicine节点以及和其有关联的关系
     cql = "MATCH (n:" + self.MEDICINETAG + ") DETACH DELETE n"
     neoDb.graph.data(cql)
     FileUtil.print_string(u"开始存储中药节点...", True)
     mysqlDatas = mysqlDb.select('medicine', 'id,name')
     for unit in mysqlDatas:
         id = unit[0]
         name = unit[1]
         if (filter == True and (id not in filterSet)):
             continue
         # print("输出id为%d的药物:%s"%(id,name.encode('utf8')))
         defaultTid = []
         defaultWeight = 0
         neoDb.createNode(
             [self.MEDICINETAG], {
                 self.NODEID: id,
                 self.NODENAME: name,
                 self.NODEWEIGHT: defaultWeight,
                 self.NODETID: defaultTid
             })
     mysqlDb.close()
示例#5
0
 def store_tonguezhi2medicine(self, filter=False, filterSet=set([])):
     FileUtil.print_string(u"开始存储舌质和中药的关系...", True)
     mysqlDb = MysqlOpt()
     neoDb = Neo4jOpt()
     treamentMysql = mysqlDb.select('treatment',
                                    'id,tongueZhiId,prescriptionId')
     for treamentUnit in treamentMysql:
         tongueZhiId = treamentUnit[1]
         tid = int(treamentUnit[0])
         if (filter == True and tid not in filterSet):
             continue
         priscriptionMysql = mysqlDb.select('prescription', 'name',
                                            'id = ' + str(treamentUnit[2]))
         if (len(priscriptionMysql) > 0):
             medicineIds = priscriptionMysql[0][0].split(",")
         else:
             continue
         # 针对name末尾有逗号的情况进行处理
         lenth = len(medicineIds)
         if (medicineIds[lenth - 1] == ''):
             medicineIds.pop()
         for medicineId in medicineIds:
             medicineNodes = neoDb.selectNodeElementsFromDB(
                 self.MEDICINETAG,
                 condition=[],
                 properties={self.NODEID: int(medicineId)})
             tongueZhiNodes = neoDb.selectNodeElementsFromDB(
                 self.TONGUEZHITAG,
                 condition=[],
                 properties={self.NODEID: int(tongueZhiId)})
             if (len(medicineNodes) > 0 and len(tongueZhiNodes) > 0):
                 medicineNode = medicineNodes[0]
                 tongueZhiNode = tongueZhiNodes[0]
                 # print(medicineNode['name'])
                 # print(tongueZhiNode['name'])
                 # print("输出舌质%s和药物%s的关系:%d"%(tongueZhiNode['name'].encode('utf8'),medicineNode['name'].encode('utf8'),tid))
                 # 如果节点之间已经存在关系了,则权重加1,否则创建关系
                 relations = neoDb.selectRelationshipsFromDB(
                     tongueZhiNode, self.TONGUEZHI2MEDICINETAG,
                     medicineNode)
                 if (len(relations) > 0):
                     # print("更新舌质%s和药物%s的关系" % (tongueZhiNode['name'].encode('utf8'), medicineNode['name'].encode('utf8')))
                     relation = relations[0]
                     tids = relation[self.RELATIONTID]
                     tids.append(tid)
                     ntids = list(set(tids))
                     nweight = len(ntids)
                     neoDb.updateKeyInRelationship(relation,
                                                   properties={
                                                       self.RELATIONTID:
                                                       ntids,
                                                       self.RELATIONWEIGHT:
                                                       nweight
                                                   })
                 else:
                     tids = [tid]
                     weight = 1
                     neoDb.createRelationship(self.TONGUEZHI2MEDICINETAG,
                                              tongueZhiNode,
                                              medicineNode,
                                              propertyDic={
                                                  self.RELATIONTID: tids,
                                                  self.RELATIONWEIGHT:
                                                  weight
                                              })
     mysqlDb.close()