cognee/cognee/tests/utils/isolate_relationships.py
2025-11-17 22:04:30 +01:00

20 lines
729 B
Python

def isolate_relationships(source_relationships, *other_relationships):
final_relationships = []
cache = {relationship[2]: 1 for relationship in source_relationships}
duplicated_relationships = {}
for relationships in other_relationships:
for relationship in relationships:
if relationship[2] not in cache:
cache[relationship[2]] = 0
cache[relationship[2]] += 1
if cache[relationship[2]] == 2:
duplicated_relationships[relationship[2]] = True
for relationship in source_relationships:
if relationship[2] not in duplicated_relationships:
final_relationships.append(relationship)
return final_relationships