本文整理汇总了Python中py2neo.cypher.execute函数的典型用法代码示例。如果您正苦于以下问题:Python execute函数的具体用法?Python execute怎么用?Python execute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了execute函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: creating_rels
def creating_rels():
print rels
print allRels
for rel in rels:
query ='START a=node(*), b=node(*) WHERE has(a.IDX) and a.IDX? = "'+rel[0]+'" and has(a.DB) and a.DB? = "'+traversalName+'" and has(b.IDX) and b.IDX? ="'+rel[1]+'" and has(b.DB) and b.DB? ="'+traversalName+'" CREATE a-[r:_'+str(allRels.count(rel))+']->b RETURN r'
print query
cypher.execute(graph_db, query, {}, row_handler=print_row,error_handler=print_error)
开发者ID:CulturePlex,项目名称:GameMining,代码行数:7,代码来源:creandoGrafoConTraversals.py
示例2: main
def main(ts, START = None, END = None, mode = 1):
"""
Does the graph processing at time_stamp ts and returns stats.
mode = 1 for complete graph traversal
else for graph traversal within time_window.
"""
global time_stamp
time_stamp = ts
global graph_component
# It's necessary to flush the graph_component to remove the last map
graph_component ={}
global START_TIME
START_TIME = START
global END_TIME
END_TIME = END
# print time_stamp, START_TIME, END_TIME, graph_component, mode
# handle_row_custom([2])
# return
graph_db = neo4j.GraphDatabaseService("http://localhost:7475/db/data/")
if (mode == 1):
cypher.execute(graph_db, "START z=node(*) RETURN z", row_handler = handle_row )
else :
cypher.execute(graph_db, "START z=node(*) RETURN z", row_handler = handle_row_custom )
return get_comp_sizes(graph_component.values())
开发者ID:pranayiitd,项目名称:validation,代码行数:30,代码来源:connected_comp.py
示例3: test_query_with_params
def test_query_with_params(self):
a, b = self.graph_db.create_nodes(
{"name": "Alice"},
{"name": "Bob"}
)
ab = a.create_relationship_to(b, "KNOWS")
def check_metadata(metadata):
self.assertTrue(isinstance(metadata.columns, list))
self.assertEqual(5, len(metadata.columns))
self.assertEqual("a", metadata.columns[0])
self.assertEqual("b", metadata.columns[1])
self.assertEqual("ab", metadata.columns[2])
self.assertEqual("a.name", metadata.columns[3])
self.assertEqual("b.name", metadata.columns[4])
def check_row(row):
self.assertTrue(isinstance(row, list))
self.assertEqual(5, len(row))
self.assertTrue(isinstance(row[0], neo4j.Node))
self.assertTrue(isinstance(row[1], neo4j.Node))
self.assertTrue(isinstance(row[2], neo4j.Relationship))
self.assertEqual(row[0], a)
self.assertEqual(row[1], b)
self.assertEqual(row[2], ab)
self.assertEqual(row[3], "Alice")
self.assertEqual(row[4], "Bob")
query = """\
start a=node({A}),b=node({B})\
match a-[ab]-b\
return a,b,ab,a.name,b.name"""
cypher.execute(self.graph_db, query, {"A": a.id, "B": b.id},
row_handler=check_row, metadata_handler=check_metadata
)
开发者ID:gwik,项目名称:py2neo,代码行数:32,代码来源:cypher_test.py
示例4: test_query_with_params
def test_query_with_params(self):
a, b, ab = alice_and_bob(self.graph_db)
def check_metadata(metadata):
self.assertEqual(5, len(metadata.columns))
self.assertEqual("a", metadata.columns[0])
self.assertEqual("b", metadata.columns[1])
self.assertEqual("ab", metadata.columns[2])
self.assertEqual("a.name", metadata.columns[3])
self.assertEqual("b.name", metadata.columns[4])
def check_row(row):
self.assertTrue(isinstance(row, list))
self.assertEqual(5, len(row))
self.assertTrue(isinstance(row[0], neo4j.Node))
self.assertTrue(isinstance(row[1], neo4j.Node))
self.assertTrue(isinstance(row[2], neo4j.Relationship))
self.assertEqual(row[0], a)
self.assertEqual(row[1], b)
self.assertEqual(row[2], ab)
self.assertEqual(row[3], "Alice")
self.assertEqual(row[4], "Bob")
query = (
"START a=node({A}),b=node({B}) "
"MATCH a-[ab]-b "
"RETURN a,b,ab,a.name,b.name"
)
cypher.execute(self.graph_db, query, {"A": a._id, "B": b._id},
row_handler=check_row, metadata_handler=check_metadata
)
开发者ID:hdngr,项目名称:py2neo,代码行数:28,代码来源:cypher_test.py
示例5: outputD3JSON
def outputD3JSON(output_file):
nodes = []
links = []
node_id_to_index = {}
to_output = {
"nodes":nodes,
"links":links
}
rows, metadata = cypher.execute(GRAPHDB, "MATCH (n) RETURN n")
for index,row in enumerate(rows):
node = row[0]
node_id = node._id
node_to_write = {
"id":node_id
}
nodes.append(node_to_write)
node_id_to_index[node_id] = index
rows, metadata = cypher.execute(GRAPHDB, "MATCH (a)-[r:RELEVANCY]->(b) RETURN a,r,b")
for nodeA, rel, nodeB in rows:
weight = rel["weight"]
edge_to_write = {
"source":node_id_to_index[nodeA._id],
"target":node_id_to_index[nodeB._id],
"weight":weight
}
links.append(edge_to_write)
to_write = json.dumps(to_output)
with open(output_file, "w") as f:
f.write(to_write)
开发者ID:R4chel,项目名称:RecommendationGraph,代码行数:34,代码来源:convertToJson.py
示例6: alice_bob_test
def alice_bob_test(self):
# Build a Cypher query
query = "START a=node({A}) MATCH a-[:KNOWS]->b RETURN a,b"
# ...and execute the query
cypher.execute(self.graph_db, query, {"A": self.node_a.id}, row_handler=print_row)
开发者ID:AndrewX192,项目名称:pcap2neo4j,代码行数:7,代码来源:db_neo4j.py
示例7: test_reload_external_changes
def test_reload_external_changes(manager, connection, static_types):
Thing = static_types['Thing']
manager.save(Thing)
manager.reload_types() # cache type registry
# update the graph as an external manager would
# (change a value and bump the typesystem version)
match_clauses = (
get_match_clause(Thing, 'Thing', manager.type_registry),
get_match_clause(manager.type_system, 'ts', manager.type_registry),
)
query = join_lines(
'MATCH',
(match_clauses, ','),
'SET ts.version = {version}',
'SET Thing.cls_attr = {cls_attr}',
'RETURN Thing'
)
query_params = {
'cls_attr': 'placeholder',
'version': str(uuid.uuid4())
}
cypher.execute(connection, query, query_params)
# reloading types should see the difference
manager.reload_types()
descriptor = manager.type_registry.get_descriptor(Thing)
assert "cls_attr" in descriptor.class_attributes
开发者ID:onefinestay,项目名称:kaiso,代码行数:29,代码来源:test_type_system_caching.py
示例8: print_edge_list
def print_edge_list(db):
print "0"
fout = open('topic_edge_list.txt', 'w')
print ".5"
topic_results, metadata = cypher.execute(db, "START n=node(*) MATCH (n)-[b:SPOKE_ABOUT]->(c) RETURN n,c")
print "1"
for row in topic_results:
person_props = row[0].get_properties()
person = person_props['name']
topic_props = row[1].get_properties()
topic = topic_props['subject']
str = person + "#" + topic + "#S"
print str
fout.write(str+"\r\n")
fout.close()
fout = open('influence_edge_list.txt', 'w')
influence_results, metadata = cypher.execute(db, "START n=node(*) MATCH (n)-[b:INFLUENCED]->(c) RETURN n,c")
for row in influence_results:
person1_props = row[0].get_properties()
person1 = person1_props['name']
person2_props = row[1].get_properties()
person2 = person2_props['name']
str = person1 + "#" + person2 + "#I"
fout.write(str+"\r\n")
fout.close()
开发者ID:R4chel,项目名称:funnyGraph,代码行数:25,代码来源:crawler.py
示例9: convert_to_json_influence
def convert_to_json_influence(db):
name_dict = {}
nodes_list = []
edge_list = []
nodes, metadata = cypher.execute(db, "START n=node(*) MATCH (n:ComedianInfobox) RETURN n")
i = 0
for row in nodes:
node = row[0]
props = node.get_properties()
name = props['name']
name_dict[name] = i
json_str = '{"name": "'+ name + '"}'
nodes_list.append(json_str)
i += 1
nodes_list_str = ",".join(nodes_list)
influence_results, metadata = cypher.execute(db, "START n=node(*) MATCH (n:ComedianInfobox)-[b:INFLUENCED]->(c:ComedianInfobox) RETURN n,c")
for row in influence_results:
person1_props = row[0].get_properties()
person1_name = person1_props['name']
person1 = name_dict[person1_name]
person2_props = row[1].get_properties()
person2_name = person2_props['name']
person2 = name_dict[person2_name]
json_str = '{"source":' + str(person1) + ', "target": '+ str(person2) + '}'
edge_list.append(json_str)
edge_list_str = ",".join(edge_list)
fout = open('influences_json.json','w')
complete_json_str = '{ "nodes":[' + nodes_list_str + '], "links":[' + edge_list_str + ']}'
json.dump(complete_json_str, fout, indent=4)
fout.close()
开发者ID:R4chel,项目名称:funnyGraph,代码行数:31,代码来源:crawler.py
示例10: get_all_meanings
def get_all_meanings(self, word):
'''
Get all meanings as assigned by the disambiguation index (should be very fast! approx O(1) hopefully)
If that fails, get all meanings given by the following regex: <word>*
If even that fails, get all meanings fuzzily equal to <word> using Levenshtein distance or soundex
If even THAT fails, return an error saying no meanings and ask the user what the hell he meant to say
word => string keyword to get all possible neo4j objects for
'''
print "WORD:", word
data, metadata = cypher.execute(self.graphdb, 'start n=node:%s(name="%s") match n-[]-m return m' % (self.DISAMBIGUATION, word))
if data:
print data
return [d[0] for d in data]
res = self.disambiguation_index.query("name:%s~" % word)
if res:
print res
return [d[0] for d in data]
res = self.disambiguation_index.query("name:%s*" % word)
if res:
print res
return [d[0] for d in data]
data, metadata = cypher.execute(self.graphdb, 'START root=node(*) WHERE root.name=~".*%s.*" RETURN root' % word)
if data:
print data
return [d[0] for d in data]
return []
开发者ID:saurabhkb,项目名称:tailor,代码行数:27,代码来源:learner.py
示例11: docsSearch
def docsSearch(request):
ipAddr = request.META.get("REMOTE_ADDR")
filename = "/home/qingyuan/log/" + ipAddr
writeObject = request.GET["log"]
with open(filename, "a") as f:
f.write(str(writeObject) + "\n")
if "n" in request.GET:
nodeID = int(request.GET["ID"])
query = "start n=node({clicked}) return n.docs"
data, metadata = cypher.execute(graph_db, query, params={"clicked": nodeID})
docsList = json.dumps(data[0][0])
elif "r" in request.GET:
startID = int(request.GET["startID"])
endID = int(request.GET["endID"])
query = "start n=node({startnode}), m=node({endnode}) match n-[r]-m where has(r.docs) return r.docs"
data, metadata = cypher.execute(graph_db, query, params={"startnode": startID, "endnode": endID})
docsList = []
if data:
docsList = json.dumps(data[0][0])
elif "sn" in request.GET:
rawID = request.GET["ID"]
nodeID = [int(x) for x in rawID.split(",")]
query = "start n=node({clicked}) return n.docs"
data, metadata = cypher.execute(graph_db, query, params={"clicked": nodeID})
docsList = []
for d in data:
curDoc = ast.literal_eval(d[0])[0]
docsList.append(curDoc)
docsList = json.dumps(docsList)
return HttpResponse(docsList, content_type="application/json")
开发者ID:rebirth2nd,项目名称:semanticgraph,代码行数:34,代码来源:views.py
示例12: check_join_Existing_line_existing_point_not_on_line
def check_join_Existing_line_existing_point_not_on_line():
print(" inside check_join_Existing_line_existing_point_not_on_line function")
print("Pick existing set of point and line not connected to it")
query = "START b=node(*),a=node(*) MATCH b-[r?:CONTAIN]->a WHERE b.type = {A} AND a.type = {B} AND r IS NULL RETURN a,b"
cypher.execute(graph_db, query, {"A" :"line","B":"point"}, row_handler=print_row_new)
if len(count) == 0: return false
#Join this point with the end-points of the chosen line
randomSet = random.sample(dictLine_Point,1)
print(" randomset of line and point chosen is ")
print( "selectedPoint is " +randomSet[0][0])
print( "selectedLine is " +randomSet[0][1])
node1 = randomSet[0][0]
node2 = randomSet[0][1]
#Fill in the details of the calling function TODO
lineMane = "hjk"
length = 10
ang1 = 10
ang2 = 30
ang3 = 40
ang4 = 50
node_triangle = "fdg"
addLineInTriangle(lineName, length, ang1, ang2,ang3,ang4,node_triangle)
count = 0
return true
开发者ID:shreyasrk,项目名称:Question-Generation,代码行数:28,代码来源:algorithm.py
示例13: getUsers
def getUsers():
g=neo4j.GraphDatabaseService()
s="MATCH (n)-[k:KNOWS]-(b) SET k.bond=0"
cypher.execute(g,s)
s="MATCH (s) RETURN s.tag"
a=cypher.execute(g,s)[0]
a=[str(i[0]) for i in a]
return a
开发者ID:rishav2708,项目名称:beta-scribbie,代码行数:8,代码来源:bonding.py
示例14: tCommonNeighbors
def tCommonNeighbors(graph_db):
ret, meta = cypher.execute(graph_db, "start a=node(*) return max(a.neighbors!)")
threshold = ret[0][0] or 0
while (threshold>0):
threshold /= 2
ret, meta = cypher.execute(graph_db, bCommonNeighbors % threshold, {}, error_handler=print)
if ret[-1][2] > threshold:
return
开发者ID:natict,项目名称:gdbb,代码行数:8,代码来源:benchmark_neo4j.py
示例15: test_nonsense_query_with_error_handler
def test_nonsense_query_with_error_handler(self):
def print_error(message, exception, stacktrace):
print message
self.assertTrue(len(message) > 0)
cypher.execute(
self.graph_db, "select z=nude(0) returns x",
error_handler=print_error
)
self.assertTrue(True)
开发者ID:sirpengi,项目名称:py2neo,代码行数:9,代码来源:cypher_test.py
示例16: test_nonsense_query_with_error_handler
def test_nonsense_query_with_error_handler(self):
def print_error(message, exception, stacktrace):
print(message)
self.assertTrue(len(message) > 0)
cypher.execute(self.graph_db, (
"SELECT z=nude(0) "
"RETURNS x"
), error_handler=print_error)
self.assertTrue(True)
开发者ID:hdngr,项目名称:py2neo,代码行数:9,代码来源:cypher_test.py
示例17: creating_nodesA
def creating_nodesA(row):
query=''
a=row[0]
if not a in newNodes:
newNodes.append(a)
query += "CREATE n = {IDX:'"+a+"',DB:'"+traversalName+"'} "
if query != '':
print query
cypher.execute(graph_db, query, {}, row_handler=print_row,error_handler=print_error)
开发者ID:CulturePlex,项目名称:GameMining,代码行数:9,代码来源:creandoGrafoConTraversals.py
示例18: createRels
def createRels(user,person):
a="MATCH (n)-[r:KNOWS]-(b)WHERE n.name=""'"+user+"'"" AND b.name=""'" +person+"'""RETURN r"
a=cypher.execute(g,a)
a=a[0]
if len(a)==0:
b="MATCH (n),(b) WHERE n.name=""'"+user+"'"" AND b.name=""'"+person+"'"" CREATE (n)-[r:KNOWS {bond:0}]->(b)"
cypher.execute(g,b)
print "Creation Successfully Done"
else:
print "Already They know each other"
开发者ID:rishav2708,项目名称:beta-scribbie,代码行数:10,代码来源:friend.py
示例19: update_info
def update_info(user,path):
tag=genId()
id1=genId()
id2=genId()
id3=genId()
g=neo4j.GraphDatabaseService()
s="CREATE (p:Photo {path:""'"+path+"'"",tag:""'"+tag+"'"",id1:""'"+id1+"'"",id2:""'"+id2+"'"",id3:""'"+id3+"'""})"
cypher.execute(g,s)
t="MATCH (n),(p) WHERE n.name= ""'"+user+"'"" AND p.path= ""'"+path+"'"" CREATE (n)-[:UPLOADS]->(p)"
cypher.execute(g,t)
开发者ID:rishav2708,项目名称:beta-scribbie,代码行数:10,代码来源:path1.py
示例20: drawPerpendicular
def drawPerpendicular(firstTime, change = 0):
print("Inside drawPerpendicular function")
#Pick any one triangle
query = "START z=node(*) WHERE z.type={A} RETURN z"
data, metadata = cypher.execute(graph_db, query, {"A": "triangle"})
for row in data:
print(row[0]["name"])
node_triangle = row[0]
#Pick existing set of point and line not connected to it
query = "START c = node(*) , b= node(*), a= node(*)MATCH c-[:KD1]->d-[:HAS]->b-[r?:CONTAIN]->a WHERE b.type = {A} AND a.type = {B} AND r IS NULL RETURN a,b"
cypher.execute(graph_db, query, {"A" :"line","B":"point"}, row_handler=print_row_new)
#Pick any one set randomly
randomSet = random.sample(dictLine_Point,1)
if change == 1 :
for save_perp in randomset:
randomSet = random.sample(dictLine_Point,1)
# TODO Remove old perpendicular line ********************
removeLine_Fig(old_perp_line)
save_perp.append(randomset)
print(" randomset of line and point chosen is ")
print( "selectedPoint is " +randomSet[0][0])
print( "selectedLine is " +randomSet[0][1])
selectedLine = randomSet[0][1]
selectedPoint = randomSet[0][0]
#Find new point by computation TODO *************
#Add point on line
newPoint = getNewPointName()
print(newPoint)
write_Name_In_File(newPoint)
addPointOnLine(newPoint,10,20,selectedLine,40,40,node_triangle)
#Add line in triangle
newLine = selectedPoint + newPoint
old_perp_line = newLine
addLineInTriangle(newLine, 40, 90, 90,20,25,node_triangle)
perpBase1 = newPoint + selectedLine[0]
perpBase2 = newPoint + selectedLine[1]
perpBase3 = selectedLine
addPerpendicularAngle(newLine,perpBase1)
addPerpendicularAngle(newLine,perpBase2)
addPerpendicularAngle(newLine,perpBase3)
print("Exiting drawPerpendicular function")
开发者ID:RahulSinghal,项目名称:Question-Generation,代码行数:55,代码来源:generateConfiguration.py
注:本文中的py2neo.cypher.execute函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论