Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
 def relate(self, a: Thing, relationship_name: str, b: Thing):
     relationship = Relationship.get(relationship_name)
     self.g.add_edge((b, a), attrs=[("relationship", relationship)])
Ejemplo n.º 4
0
 def relate(self, a: Thing, relationship_name: str, b: Thing):
     relationship = Relationship.get(relationship_name)
     self.g.add_edge((b, a), attrs=[("relationship", relationship)])
Ejemplo n.º 5
0
 def test_relationshps_are_singletons(self):
     r0 = Relationship.get("xxx")
     r1 = Relationship.get("xxx")
     self.assertTrue(r0 == r1)
Ejemplo n.º 6
0
 def test_some_relationships_can_be_inberted(self):
     r0 = Relationship.get("above")
     r1 = Relationship.get("below")
     self.assertEqual(r0.invert(), r1)