Python py2neo.Relationship() Examples

The following are 3 code examples of py2neo.Relationship(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module py2neo , or try the search function .
Example #1
Source File: mongo2neo.py    From novel-kg with MIT License 5 votes vote down vote up
def insert_one_data(arr):
    start = look_and_create(arr[0])
    items = [arr[2]] if isinstance(arr[2], str) else arr[2]
    for name in items:
        end = look_and_create(name)
        r = Relationship(start, arr[1], end, name=arr[1])   
        graph.create(r) 
Example #2
Source File: neoHandler.py    From BeaconGraph with GNU General Public License v3.0 5 votes vote down vote up
def insertAiroData(self, data):
        print("Inserting node data!")
        bssidNodes, stationNodes = data[0][0], data[0][1]
        for b in bssidNodes:
            try:
                bNode = Node(b['type'], name=b['name'], bssid=b['bssid'], oui=b['oui'], encryption=b["encryption"], speed=b['speed'], channel=b['channel'], auth=b['auth'], cipher=b['cipher'], lan=b['lan'])
                bNode.add_label("Device")
                self.graph.create(bNode)
            except ClientError:
                pass
        
        for essids, s in stationNodes:
            sNode = self.graph.nodes.match("Device", bssid=s['bssid']).first()
            if sNode is None:
                sNode = Node(s["type"], name=s['name'], bssid=s['bssid'], FirstTimeSeen=s['fts'], LastTimeSeen=s['lts'],Power=s['pwr'], NumPackets=s['pkts'], Association=s['assoc'], oui=s['oui'])
                sNode.add_label("Device")
            else:
                sNode['FirstTimeSeen'] = s['fts']
                sNode['LastTimeSeen'] = s['lts']
                sNode['Power'] = s['pwr']
                sNode['NumPackets'] = s['pkts']
                sNode['Association'] =s['assoc']
                self.graph.push(sNode)
                sNode = self.graph.nodes.match("Device", bssid=s['bssid']).first()

            for essid in essids: 
                nExisting = self.graph.nodes.match("Device", name=essid).first()
                if len(essid) > 0:
                    newProbe = Node("AP", name=essid)
                    newProbe.add_label("Device")
                    self.graph.create(Relationship(sNode, "Probes", nExisting or newProbe))
            
            if s['assoc'] is not None:
                aExisting = self.graph.nodes.match("Device", bssid=s['assoc']).first()
                newAssoc = Node("AP", bssid=s['assoc'])
                newAssoc.add_label("Device")
                self.graph.create(Relationship(sNode, "AssociatedTo", aExisting or newAssoc))
        
        print("Database updated!") 
Example #3
Source File: qa.py    From chat with MIT License 4 votes vote down vote up
def add_to_memory(self, question="question", userid="A0001"):
        """Add user question to memory.
        将用户当前对话加入信息记忆。

        Args:
            question: 用户问题。
                Defaults to "question".
            userid: 用户唯一标识。
                Defaults to "userid".
        """
        previous_node = self.graph.find_one("Memory", "qa_id", self.qa_id)
        self.qa_id = get_current_time()
        node = Node("Memory", question=question, userid=userid, qa_id=self.qa_id)
        if previous_node:
            relation = Relationship(previous_node, "next", node)
            self.graph.create(relation)
        else:
            self.graph.create(node)

    # def extract_navigation(self, question):
        """Extract navigation from question。从问题中抽取导航地点。
        从导航地点列表选取与问题匹配度最高的地点。
        QA匹配模式:(模糊匹配/全匹配)

        Args:
            question: User question. 用户问题。
        """
        # result = dict(question=question, name='', content=self.iformat(random_item(self.do_not_know)), \
            # context="", tid="", ftid="", url="", behavior=0, parameter="", txt="", img="", button="", valid=1)
        
        # 模式1:模糊匹配
        # temp_sim = 0
        # sv1 = synonym_cut(question, 'wf')
        # if not sv1:
            # return result
        # for location in self.locations:
            # sv2 = synonym_cut(location, 'wf')
            # if sv2:
                # temp_sim = similarity(sv1, sv2, 'j')
            # 匹配加速,不必选取最高相似度,只要达到阈值就终止匹配
            # if temp_sim > 0.92:
                # print("Navigation location: " + location + " Similarity Score: " + str(temp_sim))
                # result["content"] = location
                # result["context"] = "user_navigation"
                # result["behavior"] = int("0x001B", 16)
                # return result
        
        # 模式2:全匹配,判断“去”和地址关键词是就近的动词短语情况
        # for location in self.locations:
            
            # keyword = "去" + location
            # if keyword in question:
                # print("Original navigation")
                # result["name"] = keyword
                # result["content"] = location
                # result["context"] = "user_navigation"
                # result["behavior"] = int("0x001B", 16)
                # return result
        # return result