forked from Pometry/Raphtory
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added node_type to indexed search * fmt
- Loading branch information
1 parent
57d744d
commit df232df
Showing
3 changed files
with
193 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
from raphtory import Graph | ||
|
||
def test_search_in_python(): | ||
g = Graph() | ||
g.add_node( | ||
1, "hamza", properties={"value": 60, "value_f": 31.3, "value_str": "abc123"} | ||
) | ||
g.add_node( | ||
2, | ||
"ben", | ||
properties={"value": 59, "value_f": 11.4, "value_str": "test test test"}, | ||
) | ||
g.add_node( | ||
3, | ||
"haaroon", | ||
properties={ | ||
"value": 199, | ||
"value_f": 52.6, | ||
"value_str": "I wanna rock right now", | ||
}, | ||
) | ||
|
||
g.add_edge( | ||
2, | ||
"haaroon", | ||
"hamza", | ||
properties={"value": 60, "value_f": 31.3, "value_str": "abc123"}, | ||
) | ||
g.add_edge( | ||
1, | ||
"ben", | ||
"hamza", | ||
properties={"value": 59, "value_f": 11.4, "value_str": "test test test"}, | ||
) | ||
g.add_edge( | ||
3, | ||
"ben", | ||
"haaroon", | ||
properties={ | ||
"value": 199, | ||
"value_f": 52.6, | ||
"value_str": "I wanna rock right now", | ||
}, | ||
) | ||
|
||
index = g.index() | ||
|
||
# Name tests | ||
assert len(index.search_nodes("name:ben")) == 1 | ||
assert len(index.search_nodes("name:ben OR name:hamza")) == 2 | ||
assert len(index.search_nodes("name:ben AND name:hamza")) == 0 | ||
assert len(index.search_nodes("name: IN [ben, hamza]")) == 2 | ||
|
||
# Property tests | ||
assert len(index.search_nodes("value:<120 OR value_f:>30")) == 3 | ||
assert len(index.search_nodes("value:[0 TO 60]")) == 2 | ||
assert len(index.search_nodes("value:[0 TO 60}")) == 1 # } == exclusive | ||
assert len(index.search_nodes("value:>59 AND value_str:abc123")) == 1 | ||
|
||
# edge tests | ||
assert len(index.search_edges("from:ben")) == 2 | ||
assert len(index.search_edges("from:ben OR from:haaroon")) == 3 | ||
assert len(index.search_edges("to:haaroon AND from:ben")) == 1 | ||
assert len(index.search_edges("to: IN [ben, hamza]")) == 2 | ||
|
||
# edge prop tests | ||
assert len(index.search_edges("value:<120 OR value_f:>30")) == 3 | ||
assert len(index.search_edges("value:[0 TO 60]")) == 2 | ||
assert len(index.search_edges("value:[0 TO 60}")) == 1 # } == exclusive | ||
assert len(index.search_edges("value:>59 AND value_str:abc123")) == 1 | ||
|
||
# Multiple history points test | ||
g = Graph() | ||
g.add_node( | ||
1, "hamza", properties={"value": 60, "value_f": 31.3, "value_str": "abc123"} | ||
) | ||
g.add_node( | ||
2, "hamza", properties={"value": 70, "value_f": 21.3, "value_str": "avc125"} | ||
) | ||
g.add_node( | ||
3, "hamza", properties={"value": 80, "value_f": 11.3, "value_str": "dsc2312"} | ||
) | ||
|
||
index = g.index() | ||
|
||
# The semantics here are that the expressions independently need to evaluate at ANY point in the lifetime of the node - hence hamza is returned even though at no point does he have both these values at the same time | ||
assert len(index.search_nodes("value:<70 AND value_f:<19.2")) == 1 | ||
|
||
g.add_node( | ||
4, "hamza", properties={"value": 100, "value_f": 11.3, "value_str": "dsc2312"} | ||
) | ||
# the graph isn't currently reindexed so this will not return hamza even though he now has a value which fits the bill | ||
assert len(index.search_nodes("value:>99")) == 0 | ||
|
||
|
||
def test_type_search(): | ||
g = Graph() | ||
ben = g.add_node(1, "ben", node_type="type_1") | ||
hamza = g.add_node(2, "hamza", node_type="type_2") | ||
indexed = g.index() | ||
assert indexed.search_nodes("node_type:type_1") == [ben] | ||
assert set(indexed.search_nodes("node_type:type_1 OR node_type:type_2")) == {hamza, ben} | ||
|
||
def test_search_with_windows(): | ||
# Window test | ||
g = Graph() | ||
g.add_node( | ||
1, "hamza", properties={"value": 60, "value_f": 31.3, "value_str": "abc123"} | ||
) | ||
g.add_node( | ||
2, "hamza", properties={"value": 70, "value_f": 21.3, "value_str": "avc125"} | ||
) | ||
g.add_node( | ||
3, "hamza", properties={"value": 80, "value_f": 11.3, "value_str": "dsc2312"} | ||
) | ||
|
||
g.add_edge( | ||
1, | ||
"haaroon", | ||
"hamza", | ||
properties={"value": 50, "value_f": 31.3, "value_str": "abc123"}, | ||
) | ||
g.add_edge( | ||
2, | ||
"haaroon", | ||
"hamza", | ||
properties={"value": 60, "value_f": 21.3, "value_str": "abddasc1223"}, | ||
) | ||
g.add_edge( | ||
3, | ||
"haaroon", | ||
"hamza", | ||
properties={"value": 70, "value_f": 11.3, "value_str": "abdsda2c123"}, | ||
) | ||
g.add_edge( | ||
4, | ||
"ben", | ||
"naomi", | ||
properties={"value": 100, "value_f": 22.3, "value_str": "ddddd"}, | ||
) | ||
|
||
w_g = g.window(1, 3) | ||
|
||
w_index = w_g.index() | ||
|
||
# Testing if windowing works - ben shouldn't be included and Hamza should only have max value of 70 | ||
assert len(w_index.search_nodes("name:ben")) == 0 | ||
assert len(w_index.search_nodes("value:70")) == 1 | ||
assert len(w_index.search_nodes("value:>80")) == 0 | ||
|
||
assert len(w_index.search_edges("from:ben")) == 0 | ||
assert len(w_index.search_edges("from:haaroon AND value:>70")) == 0 | ||
assert len(w_index.search_edges("from:haaroon AND to:hamza")) == 1 | ||
|
||
|
||
def test_search_with_subgraphs(): | ||
g = Graph() | ||
g.add_edge( | ||
2, | ||
"haaroon", | ||
"hamza", | ||
properties={"value": 60, "value_f": 31.3, "value_str": "abc123"}, | ||
) | ||
g.add_edge( | ||
1, | ||
"ben", | ||
"hamza", | ||
properties={"value": 59, "value_f": 11.4, "value_str": "test test test"}, | ||
) | ||
g.add_edge( | ||
3, | ||
"ben", | ||
"haaroon", | ||
properties={ | ||
"value": 199, | ||
"value_f": 52.6, | ||
"value_str": "I wanna rock right now", | ||
}, | ||
) | ||
g.add_edge(4, "hamza", "naomi") | ||
|
||
index = g.index() | ||
assert len(index.search_edges("from:hamza OR to:hamza")) == 3 | ||
|
||
subgraph = g.subgraph([g.node("ben"), g.node("hamza"), g.node("haaroon")]) | ||
index = subgraph.index() | ||
|
||
assert len(index.search_edges("from:hamza OR to:hamza")) == 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters