当前位置: 首页>>代码示例>>Python>>正文


Python py2neo.Node类代码示例

本文整理汇总了Python中py2neo.Node的典型用法代码示例。如果您正苦于以下问题:Python Node类的具体用法?Python Node怎么用?Python Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: createNodeFromMapping

def createNodeFromMapping(en,df):
    node =  Node()
    for label in en['label']:
        node.labels.add(label)
    for i in range(len(en['graph'])):
        node.properties[en['graph'][i]] = df[en['mysql'][i]][0]
    return node, en['resolve']
开发者ID:amartyaamp,项目名称:power_networks,代码行数:7,代码来源:graphdb.py

示例2: addMultiNodesFromJsonFile

def addMultiNodesFromJsonFile(neoGraph,filename):
    file = open(filename)
# for all lines in the file
    while 1:
        line = file.readline()
        if not line:
            break
        # replace '' with ""
        respCmtJson = line.replace("'", "\"");
        # ture string to json
        js = simplejson.loads(respCmtJson)
        # lable  and key_values
        labels = []
        key_values = {}
        #put ID into the dict
        key_values['ID'] = js['ID']
        keyValues = js['AVP_LIST']
        # for all key_values in the AVP_LIST
        for keyValue in keyValues:
            # if ATTRIBUTE is category then put the value into label
              if keyValue['ATTRIBUTE'] == 'entity_category':
                  labels = keyValue['VALUE'].split(',')
                  labels = tuple(labels)
                  #print len(labels)
              else:
                  key_values[keyValue['ATTRIBUTE']] = keyValue['VALUE']
        # labels is tuple  and key_values is a dict
        # use with which can create a node
        node = Node()
        neoGraph.create(node)
        node.__init__(*labels,**key_values)
        node.push() 
        createIndexofNode(neoGraph,node)
        autoBuildRelationShip(neoGraph,node)  
开发者ID:zhu-dq,项目名称:Neo4jCPP,代码行数:34,代码来源:newOne.py

示例3: mass_Import_WX_ID_from_opml

	def mass_Import_WX_ID_from_opml(self, opemlFile_or_Content_or_URL):
		'''
		listparser.parse(obj[, agent, etag, modified])
		Parameters:
			obj (file or string) – a file-like object or a string containing a URL, an absolute or relative filename, or an XML document
			agent (string) – User-Agent header to be sent when requesting a URL
			etag (string) – ETag header to be sent when requesting a URL
			modified (string or datetime) – Last-Modified header to be sent when requesting a URL
		'''
		opml = listparser.parse(opemlFile_or_Content_or_URL)
		for feed in opml.feeds:
			try:
				wx_id=re.findall("weixin\?id=(\S+)$", feed.url)[0]
			except IndexError:
				print "---- WX_ID Paste Error!%s"%feed.url
			if not self.is_WX_ID_Exists(wx_id):
				WX_ID = Node("WX_ID")
				info = {
					"wx_id": wx_id,
					"name": feed.title,
					"group": feed.categories[0][0]
				}
				WX_ID.update(info)
				self.neo4j.create(WX_ID)
				print "++++ WX_ID Simple stored:\t%s" % wx_id
		return True
开发者ID:Sendarg,项目名称:all2rss,代码行数:26,代码来源:wx_id.py

示例4: test_binding_node_if_labels_not_supported_casts_to_legacy_node

def test_binding_node_if_labels_not_supported_casts_to_legacy_node():
    with patch("py2neo.Graph.supports_node_labels") as mocked:
        mocked.__get__ = Mock(return_value=False)
        alice = Node(name="Alice Smith")
        assert isinstance(alice, Node)
        alice.bind("http://localhost:7474/db/data/node/1")
        assert isinstance(alice, LegacyNode)
开发者ID:JohannesOos,项目名称:py2neo,代码行数:7,代码来源:node_test.py

示例5: test_can_pull_node

def test_can_pull_node(graph):
    uri = graph.cypher.execute_one("CREATE (a {name:'Alice'}) RETURN a").uri
    alice = Node()
    alice.bind(uri)
    assert alice.properties["name"] is None
    batch = PullBatch(graph)
    batch.append(alice)
    batch.pull()
    assert alice.properties["name"] == "Alice"
开发者ID:EricEllett,项目名称:py2neo,代码行数:9,代码来源:pullbatch_test.py

示例6: __init__

class GraphNode:

    def __init__(self, node=None):

        if node is None:
            self.node = Node()
        else:
            self.node = node

    def id(self):
        """
        :return: node's unique Id
        """

        return self.node._id

    def labels(self):
        """
        :return: labels set
        """
        return self.node.labels

    def degree(self):
        """
        :return: number of relations
        """
        return self.node.degree

    def property(self, key):
        """
        :param key: property name
        :return: property value
        """
        return self.node.properties[key]

    def properties(self):
        """
        :return: node's properties dict
        """
        return self.node.properties

    def relationships(self):
        """
        :return: node's relationships iterator
        """
        for rel in self.node.match():
            i_rel = GraphRelation(rel)
            yield i_rel

    def outgoing_relationships(self):
        """
        :return: node's outgoing relationships iterator
        """
        for rel in self.node.match_outgoing():
            i_rel = GraphRelation(rel)
            yield i_rel
开发者ID:dkleinbe,项目名称:Graph42,代码行数:56,代码来源:GraphDatabase.py

示例7: test_rel_and_rev_hashes

def test_rel_and_rev_hashes(graph):
    assert hash(Rel("KNOWS")) == hash(Rel("KNOWS"))
    assert hash(Rel("KNOWS")) == -hash(Rev("KNOWS"))
    assert hash(Rel("KNOWS", well=True, since=1999)) == hash(Rel("KNOWS", since=1999, well=True))
    rel_1 = Node("KNOWS", since=1999)
    graph.create(rel_1)
    rel_2 = Node("KNOWS", since=1999)
    rel_2.bind(rel_1.uri)
    assert rel_1 is not rel_2
    assert hash(rel_1) == hash(rel_2)
开发者ID:JohannesOos,项目名称:py2neo,代码行数:10,代码来源:hash_test.py

示例8: test_node_hashes

def test_node_hashes(graph):
    assert hash(Node()) == hash(Node())
    assert hash(Node(name="Alice")) == hash(Node(name="Alice"))
    assert hash(Node(name="Alice", age=33)) == hash(Node(age=33, name="Alice"))
    assert hash(Node("Person", name="Alice", age=33)) == hash(Node("Person", age=33, name="Alice"))
    node_1 = Node("Person", name="Alice")
    graph.create(node_1)
    node_2 = Node("Person", name="Alice")
    node_2.bind(node_1.uri)
    assert node_1 is not node_2
    assert hash(node_1) == hash(node_2)
开发者ID:JohannesOos,项目名称:py2neo,代码行数:11,代码来源:hash_test.py

示例9: create_WX_ID

	def create_WX_ID(self, wx_id_info):
		'''
		CREATE (TheMatrix:Movie {title:'The Matrix', released:1999, tagline:'Welcome to the Real World'})
		CREATE (Hugo:Person {name:'Hugo Weaving', born:1960})
		'''
		if not self.is_WX_ID_Exists(wx_id_info['wx_id']):
			wxid1 = Node("WX_ID")
			wxid1.update(wx_id_info)
			self.neo4j.create(wxid1)
			print "++++ WX_ID stored:\t%s" % wx_id_info['wx_id']
			return True
开发者ID:Sendarg,项目名称:all2rss,代码行数:11,代码来源:wx_id.py

示例10: get_product_details

    def get_product_details(self,product_url,gender):

        print self.count
        self.count = self.count + 1
        try:
            product_html = requests.get(product_url).content
        except Exception as e:
            product_html = requests.get(product_url).content
    	product_soup = BeautifulSoup(product_html,"lxml")
    	product_image = product_soup.find("img","articleMedia_imagePlaceholder")
    	article_span = product_soup.find("span","sku")
    	product_name = product_soup.find("h1","productName noBg")
    	brand = product_name.contents[1]

        product_info = dict()
    	product_info["article_number"] = article_span.string
    	product_info["brand"] = brand.string
        product_info["gender"] = gender

    	ul = article_span.parent.parent
    	self.logger.write("%s being explored" %(article_span.string)+"\n")
    	for li in ul.contents:
    		if li.string is not None and str(type(li))=="<class 'bs4.element.Tag'>":
    			var = li.get('class')[0]
    			if(len(li.string.split(":")) > 1 ):
    				product_info[li['class'][0]] = li.string.split(":")[1].encode("ascii","ignore")

    	n = Node(gender,"Zalando","Product")
    	for key in product_info:
    		n.properties[key] = product_info[key]

        while (product_image is not None):
            url = product_image['src']
            file_name = url.split('/')[-1]
            folder_name = file_name.split('@')[0]
            if os.path.exists(folder_name):
                break
            os.makedirs(folder_name)
            os.chdir(folder_name)
            url = url.replace("detail","large")
            try:
                r = requests.get(url)
            except Exception as e:
                r = requests.get(url)
            open(file_name,"w").write(r.content)
            os.chdir("..")
            n["file_system_url"] = "Zalando/"+folder_name
            n["image_url"] = url
            product_image = product_image.nextSibling.nextSibling
        try:
            self.zalando_graph.create(n)
        except Exception as e:
            self.logger.write("Node %s already exists" %(article_span.string))
开发者ID:ShrutiGanesh18,项目名称:Scraper,代码行数:53,代码来源:ZalandoCrawler.py

示例11: make_node

def make_node(nodetype,uid,name,properties=None,property_key="id"):
    node = None
    if graph.find_one(nodetype,property_key='id', property_value=uid) == None:
        print("Creating %s:%s, %s" %(nodetype,name,uid))
        timestamp = graph.cypher.execute("RETURN timestamp()").one
        node = Node(nodetype, name=name,id=uid,creation_time=timestamp,last_updated=timestamp)
        graph.create(node)
        if properties != None:
            for property_name in properties.keys():
                node.properties[property_name] = properties[property_name]
            node.push()
    return node
开发者ID:rwblair,项目名称:cogat-docker,代码行数:12,代码来源:migrate_database.py

示例12: test_node_cast

def test_node_cast():
    alice = Node("Person", "Employee", name="Alice", age=33)
    assert Node.cast() == Node()
    assert Node.cast(None) is None
    assert Node.cast(alice) is alice
    assert Node.cast("Person") == Node("Person")
    assert Node.cast(name="Alice") == Node(name="Alice")
    assert Node.cast("Person", "Employee", name="Alice", age=33) == alice
    assert Node.cast({"name": "Alice"}) == Node(name="Alice")
    assert Node.cast(("Person", "Employee", {"name": "Alice", "age": 33})) == alice
    assert Node.cast(42) == NodePointer(42)
    assert Node.cast(NodePointer(42)) == NodePointer(42)
开发者ID:JohannesOos,项目名称:py2neo,代码行数:12,代码来源:cast_test.py

示例13: test_node_exists_will_raise_non_404_errors

def test_node_exists_will_raise_non_404_errors():
    with patch.object(_Resource, "get") as mocked:
        error = GraphError("bad stuff happened")
        error.response = DodgyClientError()
        mocked.side_effect = error
        alice = Node(name="Alice Smith")
        alice.bind("http://localhost:7474/db/data/node/1")
        try:
            _ = alice.exists
        except GraphError:
            assert True
        else:
            assert False
开发者ID:JohannesOos,项目名称:py2neo,代码行数:13,代码来源:node_test.py

示例14: test_can_pull_node_with_label

def test_can_pull_node_with_label(graph):
    if not graph.supports_node_labels:
        return
    uri = graph.cypher.execute_one("CREATE (a:Person {name:'Alice'}) RETURN a").uri
    alice = Node()
    alice.bind(uri)
    assert "Person" not in alice.labels
    assert alice.properties["name"] is None
    batch = PullBatch(graph)
    batch.append(alice)
    batch.pull()
    assert "Person" in alice.labels
    assert alice.properties["name"] == "Alice"
开发者ID:EricEllett,项目名称:py2neo,代码行数:13,代码来源:pullbatch_test.py

示例15: test_full_node_hydrate

def test_full_node_hydrate():
    dehydrated = {
        "extensions": {
        },
        "paged_traverse": "http://localhost:7474/db/data/node/0/paged/traverse/{returnType}{?pageSize,leaseTime}",
        "labels": "http://localhost:7474/db/data/node/0/labels",
        "outgoing_relationships": "http://localhost:7474/db/data/node/0/relationships/out",
        "traverse": "http://localhost:7474/db/data/node/0/traverse/{returnType}",
        "all_typed_relationships": "http://localhost:7474/db/data/node/0/relationships/all/{-list|&|types}",
        "property": "http://localhost:7474/db/data/node/0/properties/{key}",
        "all_relationships": "http://localhost:7474/db/data/node/0/relationships/all",
        "self": "http://localhost:7474/db/data/node/0",
        "outgoing_typed_relationships": "http://localhost:7474/db/data/node/0/relationships/out/{-list|&|types}",
        "properties": "http://localhost:7474/db/data/node/0/properties",
        "incoming_relationships": "http://localhost:7474/db/data/node/0/relationships/in",
        "incoming_typed_relationships": "http://localhost:7474/db/data/node/0/relationships/in/{-list|&|types}",
        "create_relationship": "http://localhost:7474/db/data/node/0/relationships",
        "data": {
            "name": "Alice",
            "age": 33,
        },
    }
    hydrated = Node.hydrate(dehydrated)
    assert isinstance(hydrated, Node)
    assert hydrated.properties == dehydrated["data"]
    assert hydrated.bound
    assert hydrated.resource.uri == dehydrated["self"]
开发者ID:EricEllett,项目名称:py2neo,代码行数:27,代码来源:hydrate_test.py


注:本文中的py2neo.Node类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。