MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / populate_graph

Method populate_graph

tests/flow/test_persistency.py:24–71  ·  view source on GitHub ↗
(self, graph_name)

Source from the content-addressed store, hash-verified

22
23
24 def populate_graph(self, graph_name):
25 redis_graph = Graph(redis_con, graph_name)
26 # quick return if graph already exists
27 if redis_con.exists(graph_name):
28 return redis_graph
29
30 people = ["Roi", "Alon", "Ailon", "Boaz", "Tal", "Omri", "Ori"]
31 visits = [("Roi", "USA"), ("Alon", "Israel"), ("Ailon", "Japan"), ("Boaz", "United Kingdom")]
32 countries = ["Israel", "USA", "Japan", "United Kingdom"]
33 personNodes = {}
34 countryNodes = {}
35
36 # create nodes
37 for p in people:
38 person = Node(label="person", properties={"name": p, "height": random.randint(160, 200)})
39 redis_graph.add_node(person)
40 personNodes[p] = person
41
42 for c in countries:
43 country = Node(label="country", properties={"name": c, "population": random.randint(100, 400)})
44 redis_graph.add_node(country)
45 countryNodes[c] = country
46
47 # create edges
48 for v in visits:
49 person = v[0]
50 country = v[1]
51 edge = Edge(personNodes[person], 'visit', countryNodes[country], properties={
52 'purpose': 'pleasure'})
53 redis_graph.add_edge(edge)
54
55 redis_graph.commit()
56
57 # delete nodes, to introduce deleted entries within our datablock
58 query = """MATCH (n:person) WHERE n.name = 'Roi' or n.name = 'Ailon' DELETE n"""
59 redis_graph.query(query)
60
61 query = """MATCH (n:country) WHERE n.name = 'USA' DELETE n"""
62 redis_graph.query(query)
63
64 # create indices
65 create_node_exact_match_index(redis_graph, "person", "name", "height")
66 create_node_exact_match_index(redis_graph, "country", "name", "population")
67 create_edge_exact_match_index(redis_graph, "visit", "purpose")
68 redis_graph.query("CALL db.idx.fulltext.createNodeIndex({label: 'person', stopwords: ['A', 'B'], language: 'english'}, { field: 'text', nostem: true, weight: 2, phonetic: 'dm:en' })")
69 wait_for_indices_to_sync(redis_graph)
70
71 return redis_graph
72
73 def populate_dense_graph(self, graph_name):
74 dense_graph = Graph(redis_con, graph_name)

Callers 1

test01_save_loadMethod · 0.95

Calls 7

GraphClass · 0.85
wait_for_indices_to_syncFunction · 0.85
NodeClass · 0.50
EdgeClass · 0.50
queryMethod · 0.45

Tested by

no test coverage detected