Example #1
0
    def test_remove_inv_edges(self):
        graph = Graph()
        graph.add('A', 'isa', 'B')
        graph.add('A', 'p', 'C', inverted=True)

        self.assertEqual(2, graph.number_of_edges())

        graph.remove_inverse()

        self.assertEqual(1, graph.number_of_edges())
Example #2
0
 def test_graph_is_empty(self):
     graph = Graph()
     self.assertEqual(0, graph.number_of_edges())
Example #3
0
    def test_invert_edges(self):
        graph = Graph()
        graph.add('A', 'isa', 'B')

        self.assertEqual(1, graph.number_of_edges())

        graph.apply_inverse()

        self.assertEqual(2, graph.number_of_edges())
        self.assertTrue(graph.has_edge_with_attr('A', 'isa', 'B', Attribute.INV, False))
        self.assertTrue(graph.has_edge_with_attr('B', 'isa', 'A', Attribute.INV, True))
        self.assertTrue(graph.has_edge_with_attr('B', 'isa', 'A', Attribute.QTF, Quantifier.SOME))
Example #4
0
    def test_has_edge(self):
        graph = Graph()
        graph.add('A', 'isa', 'B')
        graph.add('C', 'produce', 'D')

        self.assertTrue(graph.has_edge('A', 'isa', 'B'))
Example #5
0
    def test_nodes(self):
        graph = Graph()
        graph.add('A', 'isa', 'B')

        self.assertIn("A", graph.nodes)
        self.assertIn("B", graph.nodes)
Example #6
0
    def test_number_of_edges(self):
        graph = Graph()
        graph.add('A', 'isa', 'B')
        graph.add('C', 'produce', 'D')

        self.assertEqual(2, graph.number_of_edges())
Example #7
0
    def test_number_of_nodes(self):
        graph = Graph()
        graph.add('A', 'isa', 'B')

        self.assertEqual(2, graph.number_of_nodes())
        self.assertEqual(1, graph.number_of_edges())
Example #8
0
from nl.data.data import Examples
from nl.graph.Graph import Graph


def parse_data(graph):
    data_split = [d.split() for d in Examples]
    for d in data_split:
        if len(d) == 3:
            graph.add(d[0], d[1], d[2])
            # print(d[0], d[1], d[2])
        # 'betacell isa cell that produce insulin'
        #    0      1   2    3     4        5
        if "that" in d:
            c = d[2] + '-' + d[3] + '-' + d[4] + '-' + d[5]
            graph.add(c, d[4], d[5], definition=True)
            graph.add(c, 'isa', d[2], definition=True)
            graph.add(d[0], d[1], c, definition=True)


if __name__ == '__main__':
    graph = Graph()

    parse_data(graph)

    print(graph.edges())

    print(graph._nodes)

    graph.apply_monotonicity()