本文整理汇总了Python中py2neo.Node类的典型用法代码示例。如果您正苦于以下问题:Python Node类的具体用法?Python Node怎么用?Python Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Node类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: create_company_node
def create_company_node(name, tw=None, em=None, fb=None):
""" Creates a company type node
Parameters: Name, Twitter Handle, Email Address, Facebook URL
Returns: Company Node
"""
properties = {"name" : name}
properties["facebook"] = [fb] if fb else []
properties["twitter"] = [tw] if tw else []
properties["email"] = [em] if em else []
company = Node.cast("company", properties)
# searches for company nodes with the same name
results = list(graph.find("company", "name", name))
if results:
# if there are already nodes of the same name in the graph,
# add the information from the incoming node to the duplicate
dupe = results[0]
if fb and not fb in dupe["facebook"]: dupe["facebook"].append(fb)
if tw and not tw in dupe["twitter"]: dupe["twitter"].append(tw)
if em and not em in dupe["email"]: dupe["email"].append(em)
dupe.push()
else:
# if there are no nodes of the same name in the graph,
# add the company node to the graph as it is
graph.create(company)
开发者ID:karishay,项目名称:advocate_calculator,代码行数:26,代码来源:graph_model.py
示例17: create_node
def create_node(self, node_label, node_dict):
cur_nid = self.get_max_nid() + 1
node_dict[ArianeDefinitions.GRAPH_NODE_ID] = cur_nid
node = Node.cast(node_dict)
node.labels.add(node_label)
self.graph.create(node)
return node, cur_nid
开发者ID:echinopsii,项目名称:net.echinopsii.ariane.community.relmgr,代码行数:7,代码来源:neographDB.py
示例18: peuple
def peuple(self, commune):
voiesdelacommune = self.voies[commune]
nbvoiesdelacommune = len(self.voies[commune])
placecommune = list(self.communes).index(commune)+1
nbcommunes = len(self.communes)
cpt = 0
for v in voiesdelacommune:
#if not re.compile(".*D59.*").match(v.libelle): continue
numero = Numero(7, v.libelle, v.sti, v.rivoli[:-1], v.rivoli, None, None)
cpt += 1
## Pour contourner un bug d'espace dans le fichier d'open data..
if numero.lib_off[0] == " ": numero.lib_off = numero.lib_off[1:]
try:
## On recupere le noeud de rue qui va recevoir ce numero. Ne retourne normalement qu'une rue donc on selectionne le premier et unique resultat avec ,
#voie, = self.graph.cypher.execute( "match (v:Voie { libelle:'%s' })-[:ORGANISE]-(c:Commune {libcom:'%s'}) return v" % (numero.lib_off, commune) )
voie, = self.graph.cypher.execute( "match (v:Voie { libelle:'%s' })-[:ORGANISE]-(c:Commune {libcom:'%s'}) return v" % (numero.lib_off, commune) )
except ValueError as e:
print("WARNING;%s; La voie <%s> de la commune <%s> n'existe pas." % (cpt,numero.lib_off,commune) )
print("%s" % (e) )
continue
for n in self.nums_dans_rue:
numero.no = n
newnum = Node.cast("Numero", numero.to_dict() )
#print( " %s ; %s ; %s\n%s" % (n,type(newnum),newnum,voie) )
## Le noeud Numero est crée en meme temps que la relation
arete = self.graph.create( Relationship(voie['v'],"COMPORTE",newnum) )
#if n % 50 == 0 : print( "%s ; %s ; %s" % (n,type(newnum),newnum) )
#if n % 50 == 0 : print( " %s" % (arete) )
if cpt %10 == 0 : print( "Voie %s/%s de la commune %s / %s" % (cpt,nbvoiesdelacommune, placecommune, nbcommunes) )
开发者ID:wh6b,项目名称:study-neo4j-vs-orientdb,代码行数:31,代码来源:generateur_urbanisme.py
示例19: save_publications_list
def save_publications_list(publications):
"""
Method to save all the publications to neo4j database
"""
graph = Graph()
for publication in publications:
publication_node = Node("Publication")
for key in publication:
if key not in ['_id', 'authorsSearched', 'identifiers', 'rank', 'work-citation-type']:
publication_node.properties[key] = publication[key]
graph.create(publication_node)
print 'Inserted Publication: ' + publication['doi']
开发者ID:jasonzou,项目名称:bibliometric,代码行数:16,代码来源:PublicationLoad.py
示例20: infect
def infect(self):
# Deploys new version of Khan Academy to this user
self.khanAcademyVersion = 'B'
######################DATABASE#######################
# save all relationships, ingoing and outgoing of this node
incomingRel = self.databaseNode.match_incoming(rel_type="IS_COACHING")
outgoingRel = self.databaseNode.match_outgoing(rel_type="IS_COACHING")
# create a node that is of typer UserN
self.databaseNode = Node("UserB", name = self.name, khanAcademyVersion = self.khanAcademyVersion, LastLogin = self.lastLogin)
graph.create(self.databaseNode)
# Build the same relationships as the UserA node
for r in incomingRel:
startNode = r.start_node
graph.create(Relationship(startNode, "IS_COACHING", self.databaseNode))
for r in outgoingRel:
endNode = r.end_node
graph.create(Relationship(self.databaseNode, "IS_COACHING", endNode))
# Delete the old node
cypher.execute("MATCH (u :UserA {khanAcademyVersion: {khanAcademyVersion}, name: {name}})-[r]-() DELETE r", khanAcademyVersion = 'A', name = self.name)
cypher.execute("MATCH n WHERE (n.khanAcademyVersion = {khanAcademyVersion} AND n.name = {name}) DELETE n", khanAcademyVersion = 'A', name = self.name)
开发者ID:nrkfeller,项目名称:user_infection,代码行数:27,代码来源:userclass.py
注:本文中的py2neo.Node类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论