def get_related(self, a, relationship_name): related = set() relationship = Relationship.get(relationship_name) for n in self.g.neighbors(a): if dict(self.g.edge_attr.get((a, n), [])).get("relationship") == relationship: related.add(n) inverted_relationship = relationship.invert() for n in self.g.incidents(a): if dict(self.g.edge_attr.get((a, a), [])).get("relationship") == inverted_relationship: related.add(n) return related
def get_related(self, a, relationship_name): related = set() relationship = Relationship.get(relationship_name) for n in self.g.neighbors(a): if dict(self.g.edge_attr.get( (a, n), [])).get("relationship") == relationship: related.add(n) inverted_relationship = relationship.invert() for n in self.g.incidents(a): if dict(self.g.edge_attr.get( (a, a), [])).get("relationship") == inverted_relationship: related.add(n) return related
def relate(self, a: Thing, relationship_name: str, b: Thing): relationship = Relationship.get(relationship_name) self.g.add_edge((b, a), attrs=[("relationship", relationship)])
def test_relationshps_are_singletons(self): r0 = Relationship.get("xxx") r1 = Relationship.get("xxx") self.assertTrue(r0 == r1)
def test_some_relationships_can_be_inberted(self): r0 = Relationship.get("above") r1 = Relationship.get("below") self.assertEqual(r0.invert(), r1)