本文整理汇总了Python中py2neo.rel函数的典型用法代码示例。如果您正苦于以下问题:Python rel函数的具体用法?Python rel怎么用?Python rel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rel函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: create
def create(cls, name, *emails):
person_node, _ = graph_db.create(node(name=name),
rel(cls._root, "PERSON", 0))
for email in emails:
graph_db.create(node(email=email), rel(cls._root, "EMAIL", 0),
rel(person_node, "EMAIL", 0))
return Person(person_node)
开发者ID:arvindram03,项目名称:amazon-dashboard,代码行数:7,代码来源:del.py
示例2: create_operons
def create_operons(self):
f = open(self.directory + 'Operons.txt', 'r')
data = f.readlines()
f.close()
i = 0
for line in data:
if line[0] == '#':
continue
chunks = line.split('\t')
### testing
if chunks[0] == '' or chunks[1] == '' or chunks[2] == 0:
continue
if chunks[3] == '':
chunks[3] = 'unknown'
operon, term, term_rel, org_rel = self.connection.\
create(node({'name': chunks[0], 'start': int(chunks[1]),
'end': int(chunks[2]), 'strand': chunks[3],
'evidence': chunks[6], 'source': 'RegulonDB'}),
node({'text': chunks[0]}),
rel(0, 'HAS_NAME', 1),
rel(0, 'PART_OF', self.ecoli_node))
operon.add_labels('Operon', 'BioEntity', 'DNA')
i += 1
logging.info('%d operons were created!' % i)
开发者ID:promodel,项目名称:BiomeDB_load_RegulonDB,代码行数:26,代码来源:regulondb.py
示例3: whipUp
def whipUp(self):
objects = json.load(urlopen(self.api_url))["objects"]
for object in objects:
args = {}
args["ID"]=object["id"]
args["N"]=object["Name"]
args["DR"]=object["DateReg"]
#print args
db = self.graph_db.cypher.begin()
db.append(self.statement, args)
db.commit()
f = getFilia(args["ID"])
adr = getAddress(id = int(object["Address"]["id"]), Street = object["Address"]["Street"])
#per = getPerson(id = int(object["Person"]["id"]), Name = (object["Person"]["Surname"] + " " + object["Person"]["Name"]))
per = getPerson(Name = (object["Person"]["Surname"] + " " + object["Person"]["Name"]))
soc = getSocialFormation(id = int(object["SocialFormation"]["id"]))
if adr != None:
self.graph_db.create(rel(f.one, "HAVE_ADDRESS", adr.one))
if per != None:
self.graph_db.create(rel(f.one, "FILIA_HAVE_PERSON", per.one))
if soc != None:
self.graph_db.create(rel(f.one, "HAVE_SocialFormation", soc.one))
开发者ID:VadyaVL,项目名称:labs,代码行数:27,代码来源:loadSPDB.py
示例4: create_project_graph
def create_project_graph():
"""Creates a project Graph and stashes it in Neo4j.
Returns a tuple of (users, projects, relationships), where each item is
a list of the created data.
"""
# Create some Users
user_nodes = [node(name=t[0], username=t[1]) for t in random_users()]
users = db.create(*user_nodes)
for u in users:
# ...and label them as such.
u.add_labels("user")
# Create some Projects.
project_nodes = [node(name=s) for s in random_projects()]
projects = db.create(*project_nodes)
rels = []
for p in projects:
# ...and label them as such.
p.add_labels("project")
# Set up some relationships.
# 1. Give the project a single Owner
rels.append(rel((p, "OWNED_BY", random.choice(users))))
# 2. Give the project a random number of contributors.
for u in random.sample(users, random.randrange(3, 50)):
rels.append(rel((u, "CONTRIBUTES_TO", p)))
# Save the relationships
rels = db.create(*rels)
return (users, projects, rels)
开发者ID:bradmontgomery,项目名称:committed,代码行数:34,代码来源:db.py
示例5: processPlayerTeam
def processPlayerTeam(playerteam_dict,graph_db,root):
teams = set({})
# Add teams to database, connected to root node
# (Currently, each team requires a separate HTTP request)
team_node_dict = {}
for pair in playerteam_dict.values():
team = pair[0]
teams.add(team)
for team in teams:
team_node,relation = graph_db.create({"name":team},rel(root,"TEAM",0))
team_node.add_labels("team")
team_node_dict[team] = team_node
#Add players to database as a batch
batch = neo4j.WriteBatch(graph_db)
for player_id, player_tuple in playerteam_dict.iteritems():
team = player_tuple[0]
full_name = player_tuple[1]
player_node=batch.create({"name":full_name,"player_id":int(player_id)})
batch.create(rel(root,"PLAYER",player_node))
batch.add_labels(player_node,"player")
team_node = team_node_dict[team]
batch.create(rel(player_node,"PLAYS FOR",team_node))
results=batch.submit()
开发者ID:clementmiao,项目名称:clementmiao-cs123,代码行数:25,代码来源:graph_db.py
示例6: whipUp
def whipUp(self):
objects = json.load(urlopen(self.api_url))["objects"]
for object in objects:
args = {}
args["ID"]=object["id"]
args["NS"]=object["NStatement"]
args["DS"]=object["DateStatement"]
args["D"]=object["Date"]
args["AI"]=object["AddedInfo"]
db = self.graph_db.cypher.begin()
db.append(self.statement, args)
db.commit()
enc = getEncumbrance(id=int(args["ID"]))
obj = getObject(id=int(object["Obj"]["id"]))
docBase = getDocumentBase(id=int(object["DocBase"]["id"]))
if obj != None:
self.graph_db.create(rel(enc.one, "HAVE_OBJECT", obj.one))
if docBase != None:
self.graph_db.create(rel(enc.one, "HAVE_DOCUMENT", docBase.one))
for sp in object["SPerson"]:
s_p = getPerson(id=int(sp["id"]))
self.graph_db.create(rel(enc.one, "HAVE_DEPTOR", s_p.one))
for wp in object["WPerson"]:
w_p = getPerson(id=int(wp["id"]))
self.graph_db.create(rel(enc.one, "HAVE_WEIGHT", w_p.one))
开发者ID:VadyaVL,项目名称:labs,代码行数:32,代码来源:loadMyDB.py
示例7: create_update_promoters
def create_update_promoters(self):
f = open(self.directory + 'All Promoters.txt', 'r')
data = f.readlines()
f.close()
created, updated = [0]*2
for line in data:
if line[0] == '#':
continue
regid, name, strand, tss, sigma, seq, evidence = line.split('\t')
tss = int(tss)
# skipping incomplete data
if '' in [regid, name, strand, tss]:
continue
query = 'MATCH (ch:Chromosome {name: "%s"})<-[:PART_OF]-' \
'(p:Promoter {tss: %d})-[:PART_OF]->' \
'(o:Organism {name: "%s"}) ' \
'RETURN p' % (self.chro_name, tss, self.ecoli_name)
res = neo4j.CypherQuery(self.connection, query)
res_nodes = res.execute()
# creating promoter
if not res_nodes:
promoter, term, rel_org, rel_chr, rel_term = self.connection.create(
node({'name': name, 'start': tss,
'end': tss, 'strand': strand,
'tss': tss, 'seq': seq,
'evidence': evidence, 'Reg_id': regid,
'source': 'RegulonDB'}),
node({'text': name}),
rel(0, 'PART_OF', self.ecoli_node),
rel(0, 'PART_OF', self.chro_node),
rel(0, 'HAS_NAME', 1))
promoter.add_labels('Promoter', 'Feature', 'BioEntity', 'DNA')
term.add_labels('Term')
created += 1
else:
# one promoter with the tss
for record in res_nodes.data:
promoter = record.values[0]
promoter.update_properties({'seq': seq,
'evidence': evidence,
'Reg_id': regid})
update_source_property(promoter)
self.check_create_terms(promoter, name)
updated += 1
# duplicates!
if len(res_nodes.data) > 1:
logging.warning("There are %d nodes for a promoter with "
"tss in the %d position! It was skipped!"
% (len(res_nodes.data), tss))
logging.info("%d promoters were updated!" % updated)
logging.info("%d promoters were created!" % created)
开发者ID:promodel,项目名称:BiomeDB_load_RegulonDB,代码行数:57,代码来源:regulondb.py
示例8: updateOrCreateTagged
def updateOrCreateTagged(memeDict):
""" Description: Checks to see if the img, tag and relationship are in the db
if not, it adds them at each level and increments the
weighted property to indicate a stronger correlation
Params: memeDict, dictionary, keys are urls and values are list of tags
Returns: None """
# check to see if the image exists
urls = memeDict.keys()
for url in urls:
pImg = graph_db.get_indexed_node("Img", "imgSrc", url)
print "This should be an indexed img node: ", pImg
# this is working right now
tags = memeDict[url]
if str(type(pImg)) != "<type 'NoneType'>":
# if so check to see if the tag exists
print "This should be a list", tags
for tag in memeDict[url]:
tagName = tagsExist([tag])
if len(tagName) > 0:
pTagNode = graph_db.get_indexed_node("Tags", "tagName", tagName[0])
print "This should be an existing tag: ", pTagNode
# if so check to see if there's a relationship
pRel = graph_db.match_one(start_node=pImg, rel_type="TAGGED", end_node=pTagNode)
print "This should find the relationship or return none: ", pRel
# if so increment rel aweight
if str(type(pRel)) != "<type 'NoneType'>":
getOldWeight = pRel.get_properties()
oldWeight = getOldWeight.get("aWeight")
newWeight = oldWeight + 1
relProp = pRel.update_properties({"aWeight": newWeight})
print "This should be the old weight: ", oldWeight
# else
else:
# create a relationship
newRel = graph_db.create(rel(pImg, ("TAGGED", {"aWeight": 1}), pTagNode))
print "Hopefully this is a relationship: ", newRel
# and add the default weight
# else
else:
# create tag node
makeNewTagNode = getTagNode(tag)
newTagNode = graph_db.get_indexed_node("Tags", "tagName", tag)
# and then create a relationship
newRel = graph_db.create(rel(pImg, ("TAGGED", {"aWeight": 1}), newTagNode))
# else
else:
# create image node
newImgNode = createImgNode({url: tags})
print "this should be a new img node:", newImgNode
开发者ID:karishay,项目名称:eMeme_webapp,代码行数:52,代码来源:graphModel.py
示例9: co_appearance
def co_appearance(self, wid_a, wid_b):
"""two words appearing in the same document. create edge if not any, increment one otherwise"""
n_a = self.node_for_word(wid_a)
n_b = self.node_for_word(wid_b)
r = self.graph_db.match(start_node=n_a, end_node=n_b, bidirectional=True)
if len(r) == 0:
r0, r1 = self.graph_db.create(
rel(n_a, "COAPPEARS", n_b, count=0),
rel(n_b, "COAPPEARS", n_a, count=0))
r = [r0, r1]
r[0]["count"] += 1
r[1]["count"] += 1
开发者ID:akirashibata,项目名称:word_rel_graph,代码行数:13,代码来源:graph_io.py
示例10: processClusters
def processClusters(cluster_dict,graph_db,root):
for cluster_number in cluster_dict:
batch = neo4j.WriteBatch(graph_db)
name = "Cluster " + str(cluster_number)
cluster_node = batch.create({"name":name,"cluster_number":cluster_number})
batch.create(rel(root,"CLUSTER",cluster_node))
batch.add_labels(cluster_node,"cluster")
for pitcher_id in cluster_dict[cluster_number]:
for player_node in graph_db.find("player",property_key="player_id",property_value=int(pitcher_id)):
batch.create(rel(player_node, "BELONGS TO",cluster_node))
batch.submit()
开发者ID:clementmiao,项目名称:clementmiao-cs123,代码行数:13,代码来源:graph_db.py
示例11: create_RBSs
def create_RBSs(self):
f = open(self.directory + 'RBSs.txt', 'r')
data = f.readlines()
f.close()
created = 0
for line in data:
if line[0] == '#':
continue
regid, gene, start, end, strand, center, seq, \
evidence = line.split('\t')
### testing
if '' in [regid, strand, start, end] or 0 in [start, end]:
continue
start, end, center = [int(start), int(end), float(center)]
query = 'MATCH (o:Organism {name: "%s"})<-[:PART_OF]-' \
'(g:Gene {strand: "%s"})-[:HAS_NAME]-(t:Term {text: "%s"}) ' \
'RETURN g' % (self.ecoli_name, strand, gene)
res = neo4j.CypherQuery(self.connection, query)
res_nodes = res.execute()
if not res_nodes:
continue
elif len(res_nodes.data) == 1:
g = res_nodes.data[0].values[0]
else:
# if there are many genes with the same name, we will
# choose the closest by location gene
genes = [min(g.values[0]['start'] + center,
g.values[0]['end'] + center)
for g in res_nodes.data]
i = genes.index(min(genes))
g = res_nodes.data[i].values[0]
rbs, rel_chr, rel_gene = self.connection.create(
node({'evidence': evidence, 'Reg_id': regid,
'source': 'RegulonDB', 'start': start,
'end': end, 'strand': strand,
'seq': seq, 'center_from_tss': center}),
rel(0, 'PART_OF', self.chro_node),
rel(g, 'CONTAINS', 0))
rbs.add_labels('RBS', 'Feature')
created += 1
logging.info('%d RBSs were created!' % created)
开发者ID:promodel,项目名称:BiomeDB_load_RegulonDB,代码行数:49,代码来源:regulondb.py
示例12: set_configuration
def set_configuration(graph_db, node_lst):
graph_db.create(
rel(node_lst[0], "CONF_TO", node_lst[1], {'flow_id': 1, 'flow_size': 1}),
rel(node_lst[1], "CONF_TO", node_lst[2], {'flow_id': 1, 'flow_size': 1}),
rel(node_lst[0], "CONF_TO", node_lst[3], {'flow_id': 2, 'flow_size': 1}),
rel(node_lst[3], "CONF_TO", node_lst[4], {'flow_id': 2, 'flow_size': 1}),
rel(node_lst[4], "CONF_TO", node_lst[5], {'flow_id': 2, 'flow_size': 1}),
rel(node_lst[0], "CONF_TO", node_lst[3], {'flow_id': 3, 'flow_size': 1}),
rel(node_lst[3], "CONF_TO", node_lst[5], {'flow_id': 3, 'flow_size': 1}),
rel(node_lst[2], "CONF_TO", node_lst[4], {'flow_id': 4, 'flow_size': 1}),
rel(node_lst[4], "CONF_TO", node_lst[5], {'flow_id': 4, 'flow_size': 1}),
)
开发者ID:wadaries,项目名称:Find-the-DB-for-SDN,代码行数:12,代码来源:neo4jdb.py
示例13: load
def load(csvfile,verbose = True):
graph_db = database()
if verbose:
print 'started new graph database'
# get the graph database server going.
#if you want to delete the database!
# cd /usr/local/Cellar/neo4j/1.9.4/libexec/data
# os.command(rm -R graph_db)
# this will store in usr/local/Cellar/neo4j/community-1.9.2-unix/libexec/data
#make sure graph DB initialized
print 'Graph Version: ' + str(graph_db.neo4j_version)
csvfile = open(csvfile)
reader = csv.reader(csvfile,delimiter=',')
nodes = {} # keep track of nodes already in graph_db.
def get_or_create_node(graph_db, name):
if name not in nodes:
nodes[name], = graph_db.create(node(name=name)) #make the node if it doesn't exist
return nodes[name] #return the node
print 'Loading graph into database...'
for row in reader:
parent = get_or_create_node(graph_db, row[0])
child = get_or_create_node(graph_db, row[1])
parent_child, = graph_db.create(rel(parent, "--", child))
print 'Loaded graph into database'
pickle.dump(nodes, open("nodes.p", "wb" ) )
开发者ID:pombredanne,项目名称:OpenBayes,代码行数:27,代码来源:grow.py
示例14: createRelationships
def createRelationships():
global relationships
graph = Graph('http://localhost:7474/db/data')
for r in relationships:
NodeA = graph.find_one(r["start"]["collection"],property_key = "_id", property_value = str(r["start"]["_id"]))
NodeB = graph.find_one(r["end"]["collection"],property_key = "_id", property_value = str(r["end"]["_id"]))
graph.create(rel(NodeA,r["name"],NodeB))
开发者ID:davidmeza1,项目名称:KA_Interns,代码行数:7,代码来源:Scraper3.py
示例15: test_can_cast_3_tuple
def test_can_cast_3_tuple():
casted = rel(("Alice", "KNOWS", "Bob"))
assert isinstance(casted, neo4j.Relationship)
assert not casted.bound
assert casted.start_node == neo4j.Node("Alice")
assert casted.type == "KNOWS"
assert casted.end_node == neo4j.Node("Bob")
开发者ID:EricEllett,项目名称:py2neo,代码行数:7,代码来源:neo4j_rel_cast_test.py
示例16: create_db
def create_db(usercol, refcol, start, end):
'''
try to generate relationships using a different example from the fundamentals page
'''
graph_db = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")
rowlist = []
#nodes first
for i in range(11, 100):
rowlist.append (node(user=usercol[i]))
rowlist.append (node(ref = refcol[i]))
#relationships second
for i in range(11, 100):
rowlist.append(rel(start[i], "RECOMMENDED", end[i]))
incubate = graph_db.create(*rowlist) #asterisk expands the list & might work better?
#gives an error Incomplete Read if you try to do the whole thing at once, but
#looks like you can do this in pieces in order to get the whole thing (?)
#not sure if this is really necessary, should try +/- the format=pretty part
neo4j._add_header('X-Stream', 'true;format=pretty')
开发者ID:szeitlin,项目名称:data-incubator,代码行数:26,代码来源:find_relationships.py
示例17: test_can_cast_3_tuple
def test_can_cast_3_tuple():
casted = rel(("Alice", "KNOWS", "Bob"))
assert isinstance(casted, neo4j.Relationship)
assert casted.is_abstract
assert casted.start_node == "Alice"
assert casted.type == "KNOWS"
assert casted.end_node == "Bob"
开发者ID:bambata,项目名称:py2neo,代码行数:7,代码来源:neo4j_rel_cast_test.py
示例18: process_single_file_data
def process_single_file_data(jsonArray):
data = json.loads(jsonArray)
issueevents = filter(is_issueevent, data)
for ie in issueevents:
# print ie
eventType = ie["type"]
repoId = ie["repo"]["id"]
repoName = ie["repo"]["name"]
issueId = ie["payload"]["issue"]["id"]
issueTitle = ie["payload"]["issue"]["title"]
issueAction = ie["payload"]["action"]
issueCreatedAt = ie["payload"]["issue"]["created_at"]
# print eventType
# print "repository:", repoId, repoName
# print "issue:", issueId, issueAction, issueCreatedAt
#remove null value and non-primitive values as properties cannot contain nested objects
issueProperties = top_level_properties(ie['payload']['issue'])
# print issueProperties
# print issueProperties["id"], issueProperties['action']
repoNode = db.get_or_create_indexed_node(index_name="issueevents", key=repoId, value=repoName, properties=top_level_properties(ie['repo']))
repoNode.add_labels("REPOSITORY")
issueNode = db.get_or_create_indexed_node(index_name="issueevents", key=issueId, value=issueTitle, properties=issueProperties)
issueNode.add_labels("ISSUE")
db.create(rel(repoNode, ("ISSUE_" + issueAction, {"issue_created_at": issueCreatedAt, "issue_action":issueAction}), issueNode))
print "created relationship: " + "ISSUE_" + str(issueAction) + "\tbetween reposirotyNode: " + str(repoId) + "\t and IssueNode: " + str(issueId)
开发者ID:vaishaksuresh,项目名称:cmpe226nosql,代码行数:30,代码来源:insert_issueevents.py
示例19: titan_insert
def titan_insert():
start = datetime.now()
die_hard = graph_db.create(
node(name="Bruce Willis"),
node(name="John McClane"),
node(name="Alan Rickman"),
node(name="Hans Gruber"),
node(name="Nakatomi Plaza"),
rel(0, "PLAYS", 1),
rel(2, "PLAYS", 3),
rel(1, "VISITS", 4),
rel(3, "STEALS_FROM", 4),
rel(1, "KILLS", 3),
)
stop = datetime.now()
return stop - start
开发者ID:dominika101303,项目名称:AnDIP,代码行数:16,代码来源:neoStressTests.py
示例20: register
def register(self, username, email, password):
u = user.get_or_create("username", username, {
"username": username, "email": email, "password": password,
})
graph_db.create( rel( u, "FOLLOWED", u ) )
return u
开发者ID:karoon,项目名称:twitter-flask-neo4j,代码行数:8,代码来源:models.py
注:本文中的py2neo.rel函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论