Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_can_join_paths(graph):
a = Node(name="Alice")
b = Node(name="Bob")
c = Node(name="Carol")
d = Node(name="Dave")
path1 = Path(a, "KNOWS", b)
path2 = Path(c, "KNOWS", d)
path = Path(path1, "KNOWS", path2)
assert list(path) == [
Relationship(a, 'KNOWS', b),
Relationship(b, 'KNOWS', c),
Relationship(c, 'KNOWS', d),
]
def test_can_join_paths(graph):
a = Node(name="Alice")
b = Node(name="Bob")
c = Node(name="Carol")
d = Node(name="Dave")
path1 = Path(a, "KNOWS", b)
path2 = Path(c, "KNOWS", d)
path = Path(path1, "KNOWS", path2)
assert list(path) == [
Relationship(a, 'KNOWS', b),
Relationship(b, 'KNOWS', c),
Relationship(c, 'KNOWS', d),
]
def test_can_create_nodes_and_relationship_1(graph):
graph.delete_all()
with graph.begin() as tx:
a = Node("Person", name="Alice")
b = Node("Person", name="Bob")
tx.create(a)
tx.create(b)
tx.process()
r = Relationship(a, "KNOWS", b, since=1999)
tx.create(r)
assert a.graph == graph
assert a.identity is not None
assert b.graph == graph
assert b.identity is not None
assert r.graph == graph
assert r.identity is not None
assert r.start_node == a
assert r.end_node == b
assert len(graph.nodes) == 2
assert len(graph.relationships) == 1
def test_can_create_nodes_and_relationship_4(graph):
graph.delete_all()
with graph.begin() as tx:
a = Node()
b = Node()
c = Node()
ab = Relationship(a, "TO", b)
bc = Relationship(b, "TO", c)
ca = Relationship(c, "TO", a)
tx.create(ab | bc | ca)
assert a.graph == graph
assert a.identity is not None
assert b.graph == graph
assert b.identity is not None
assert c.graph == graph
assert c.identity is not None
assert ab.graph == graph
assert ab.identity is not None
assert ab.start_node == a
assert ab.end_node == b
assert bc.graph == graph
assert bc.identity is not None
assert bc.start_node == b
assert bc.end_node == c
assert ca.graph == graph
u = node_list[i]
d1 = video_data[i]
for j in range(i + 1, l):
v = node_list[j]
d2 = video_data[j]
# Channel relation
if d1["snippet"]["channelId"] == d2["snippet"]["channelId"]:
tx.create(Relationship(u, "SameChannel", v))
tx.create(Relationship(v, "SameChannel", u))
tx.create(Relationship(u, "HasChannel", channels[d1["snippet"]["channelId"]]))
tx.create(Relationship(v, "HasChannel", channels[d1["snippet"]["channelId"]]))
# Common tag relation
common_tags = commonTagCount(d1["snippet"], d2["snippet"])
if common_tags > 0:
tx.create(Relationship(u, "CommonTags", v, weight=common_tags))
tx.create(Relationship(v, "CommonTags", u, weight=common_tags))
# Common description relation
common_desc = commonDescription(d1["snippet"], d2["snippet"])
if common_desc > 0:
tx.create(Relationship(u, "CommonDesc", v, weight=common_desc))
tx.create(Relationship(v, "CommonDesc", u, weight=common_desc))
tx.commit()
print("Creating edges . . . {}%".format(int(i * 100 / l)), end="\r")
sys.stdout.flush()
print("Creating edges . . . Done!")
def get_relation_on_graph(relation, graph):
rel = relation.type.name.encode("utf-8")
src_node = get_node_on_graph(relation.src, graph)
dst_node = get_node_on_graph(relation.dst, graph)
r = None
if src_node and dst_node and rel:
r, = graph.create_unique(Relationship(src_node, rel, dst_node ))
if r:
properties = {}
for p in relation.properties.all():
properties[p.key.name] = p.value
properties["subcluster"] = None
sc = []
for s in relation.subcluster.all():
if s.name not in sc:
sc.append(s.name)
if sc:
properties["subcluster"] = sc
properties["cluster"] = None
cluster = []
for s in relation.subcluster.all():
master = masters[0]
# check the parent pid only if the ROR is set
parents = self.irodsu.getMetadata(absolutePath, 'PPID')
if parents and len(parents) > 0:
parent = parents[0]
else:
return False
po = self._createPointer('unknown', master)
re_is_replica_of_po = Relationship(re, "IS_REPLICA_OF", po)
re_is_replica_of_po.properties["relation"] = 'ROR'
self.graph.create_unique(re_is_replica_of_po)
logger.debug('Created relation: ' + str(re_is_replica_of_po))
if parent:
po = self._createPointer('unknown', parent)
re_is_replica_of_po = Relationship(re, "IS_REPLICA_OF", po)
re_is_replica_of_po.properties["relation"] = 'PPID'
self.graph.create_unique(re_is_replica_of_po)
logger.debug('Created relation: ' + str(re_is_replica_of_po))
return True
type_.name,
source.properties['name'],
dest.properties['name'],
properties
)
s = self.get(
source.properties['name'],
collection=source.collection,
db_convert=False
)
d = self.get(
dest.properties['name'],
collection=dest.collection,
db_convert=False
)
r = py2neo.Relationship(s, type_.name, d, **properties)
self._r.create(r)
return r
def create_recommendation(user_id, label):
user_node = get_user_node(user_id)
label_node = get_label_node(label)
graph.create(Relationship(
label_node,
REL_TYPE,
user_node,
))
graph.create(Relationship(
user_node,
REL_TYPE,
label_node,
))
stringList = nxNode[1]['strings']
for stringData in stringList:
strRefAddress = stringData[0]
theString = stringData[1]
# TODO think about string attributes to store, e.g. entropy, len
try:
# create string node or merge if string already exists, add relationship
stringNode = py2neo.Node("STRING", string=theString)
# TODO try this using Subgraph class, less interaction with DB server
neoGraph.merge(stringNode)
stringRel = py2neo.Relationship(functionNode, "references_string", stringNode, address=strRefAddress)
neoGraph.create(stringRel)
except:
print "ERROR with this string %s" % theString
callsList = nxNode[1]['calls']
for callData in callsList:
callRefAddress = callData[0]
callApiName = callData[1]
# create API node or merge if API already exists, add relationship
apiNode = py2neo.Node("API", apiname=callApiName)
neoGraph.merge(apiNode)
apiRel = py2neo.Relationship(functionNode, "calls_api", apiNode, address=callRefAddress)