Skip to content

Commit

Permalink
Do not duplicate symmetric self-edges
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickkwang committed Aug 17, 2021
1 parent 2f90641 commit c3b6b4a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion binder/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ async def lookup(
if any(
is_symmetric(predicate)
for predicate in qedge.get("predicates", [])
):
) and qedge["subject"] != qedge["object"]:
symmetric_qedge = copy.deepcopy(qedge)
symmetric_qedge["subject"], symmetric_qedge["object"] = symmetric_qedge["object"], symmetric_qedge["subject"]

Expand Down
30 changes: 30 additions & 0 deletions tests/test_bugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,33 @@ async def test_ignored_key(connection: aiosqlite.Connection):
}
kgraph, results = await kp.get_results(message["query_graph"])
assert results


@pytest.mark.asyncio
async def test_self_edge(connection: aiosqlite.Connection):
"""Test self-edge."""
await add_data_from_string(
connection,
data="""
MONDO:0005148(( category biolink:Disease ))
MONDO:0005148<-- predicate biolink:related_to --MONDO:0005148
""",
)
kp = KnowledgeProvider(connection)
message = {
"query_graph": {
"nodes": {
"n0": {
"ids": ["MONDO:0005148"],
},
},
"edges": {
"e01": {
"subject": "n0",
"object": "n0",
},
},
}
}
kgraph, results = await kp.get_results(message["query_graph"])
assert len(results) == 1

0 comments on commit c3b6b4a

Please sign in to comment.