def test_can_slice_path(self): path = neo4j.Path( {"name": "Alice"}, "KNOWS", {"name": "Bob"}, "KNOWS", {"name": "Carol"}, "KNOWS", {"name": "Dave"}, "KNOWS", {"name": "Eve"}, "KNOWS", {"name": "Frank"}, ) assert len(path) == 5 assert path[0] == neo4j.Path({"name": "Alice"}, "KNOWS", {"name": "Bob"}) assert path[1] == neo4j.Path({"name": "Bob"}, "KNOWS", {"name": "Carol"}) assert path[2] == neo4j.Path({"name": "Carol"}, "KNOWS", {"name": "Dave"}) assert path[-1] == neo4j.Path({"name": "Eve"}, "KNOWS", {"name": "Frank"}) assert path[0:2] == neo4j.Path({"name": "Alice"}, "KNOWS", {"name": "Bob"}, "KNOWS", {"name": "Carol"}) assert path[3:5] == neo4j.Path({"name": "Dave"}, "KNOWS", {"name": "Eve"}, "KNOWS", {"name": "Frank"}) assert path[:] == neo4j.Path({"name": "Alice"}, "KNOWS", {"name": "Bob"}, "KNOWS", {"name": "Carol"}, "KNOWS", {"name": "Dave"}, "KNOWS", {"name": "Eve"}, "KNOWS", {"name": "Frank"})
def write_edges_to_db(db, node, list, category, relationship, is_forward): if list is None: return for item in list: item = extract_title(item).strip().lower().encode() if len(item) == 0: continue new_node = db.get_or_create_indexed_node("NameIndex", category, item, {category: item}) new_node.add_labels(category.title()) path = neo4j.Path(node, relationship, new_node) if is_forward else neo4j.Path( new_node, relationship, new_node) path.get_or_create(db)
def test_path_representation(self): path = neo4j.Path({"name": "Alice"}, "KNOWS", {"name": "Bob"}) #print(str(path)) assert str(path) == '({"name":"Alice"})-[:"KNOWS"]->({"name":"Bob"})' #print(repr(path)) assert repr(path) == ("Path(node(**{'name': 'Alice'}), " "('KNOWS', *(), **{}), " "node(**{'name': 'Bob'}))")
def test_can_join_paths(self): path1 = neo4j.Path({"name": "Alice"}, "KNOWS", {"name": "Bob"}) path2 = neo4j.Path({"name": "Carol"}, "KNOWS", {"name": "Dave"}) path = neo4j.Path.join(path1, "KNOWS", path2) assert list(iter(path)) == [ ({ 'name': 'Alice' }, 'KNOWS', { 'name': 'Bob' }), ({ 'name': 'Bob' }, 'KNOWS', { 'name': 'Carol' }), ({ 'name': 'Carol' }, 'KNOWS', { 'name': 'Dave' }), ]
def test_can_create_path(self): graph_db = neo4j.GraphDatabaseService() path = neo4j.Path({"name": "Alice"}, "KNOWS", {"name": "Bob"}) assert path.nodes[0] == {"name": "Alice"} assert path._relationships[0]._type == "KNOWS" assert path.nodes[1] == {"name": "Bob"} path = path.create(graph_db) assert isinstance(path.nodes[0], neo4j.Node) assert path.nodes[0]["name"] == "Alice" assert isinstance(path.relationships[0], neo4j.Relationship) assert path._relationships[0]._type == "KNOWS" assert isinstance(path.nodes[1], neo4j.Node) assert path.nodes[1]["name"] == "Bob"
def test_can_create_path(self): path = neo4j.Path({"name": "Alice"}, "KNOWS", {"name": "Bob"}) assert len(path) == 1 assert path.nodes[0]["name"] == "Alice" assert path._relationships[0]._type == "KNOWS" assert path.nodes[-1]["name"] == "Bob" path = neo4j.Path.join(path, "KNOWS", {"name": "Carol"}) assert len(path) == 2 assert path.nodes[0]["name"] == "Alice" assert path._relationships[0]._type == "KNOWS" assert path.nodes[1]["name"] == "Bob" path = neo4j.Path.join({"name": "Zach"}, "KNOWS", path) assert len(path) == 3 assert path.nodes[0]["name"] == "Zach" assert path._relationships[0]._type == "KNOWS" assert path.nodes[1]["name"] == "Alice" assert path._relationships[1]._type == "KNOWS" assert path.nodes[2]["name"] == "Bob"
from py2neo import neo4j, node graph_db = neo4j.GraphDatabaseService(neo4j.DEFAULT_URI) modifier_types = node('ModifierTypes') ability_modifier = node('AbilityModifier') neo4j.Path(ability_modifier, 'IS', modifier_types) alchemical_bonus = node('AlchemicalBonus') neo4j.Path(alchemical_bonus, 'IS', modifier_types) armor_bonus = node('ArmorBonus') neo4j.Path(armor_bonus, 'IS', modifier_types)
def test_can_iterate_path(self): path = neo4j.Path( {"name": "Alice"}, "KNOWS", {"name": "Bob"}, "KNOWS", {"name": "Carol"}, "KNOWS", {"name": "Dave"}, "KNOWS", {"name": "Eve"}, "KNOWS", {"name": "Frank"}, ) assert list(iter(path)) == [ ({ 'name': 'Alice' }, 'KNOWS', { 'name': 'Bob' }), ({ 'name': 'Bob' }, 'KNOWS', { 'name': 'Carol' }), ({ 'name': 'Carol' }, 'KNOWS', { 'name': 'Dave' }), ({ 'name': 'Dave' }, 'KNOWS', { 'name': 'Eve' }), ({ 'name': 'Eve' }, 'KNOWS', { 'name': 'Frank' }), ] assert list(enumerate(path)) == [(0, ({ 'name': 'Alice' }, 'KNOWS', { 'name': 'Bob' })), (1, ({ 'name': 'Bob' }, 'KNOWS', { 'name': 'Carol' })), (2, ({ 'name': 'Carol' }, 'KNOWS', { 'name': 'Dave' })), (3, ({ 'name': 'Dave' }, 'KNOWS', { 'name': 'Eve' })), (4, ({ 'name': 'Eve' }, 'KNOWS', { 'name': 'Frank' }))]