Beispiel #1
0
    def test_graph_combined_as_expected(self):

        person = Thing('V123', 'person', 'entity')
        employment = Thing('V567', 'employment', 'relation')
        grakn_graph_a = nx.MultiDiGraph()
        grakn_graph_a.add_node(person)
        grakn_graph_a.add_node(employment)
        grakn_graph_a.add_edge(employment, person, type='employee')

        person_b = Thing('V123', 'person', 'entity')
        name = Thing('V1234', 'name', 'attribute', value_type='string', value='Bob')
        grakn_graph_b = nx.MultiDiGraph()
        grakn_graph_b.add_node(person_b)
        grakn_graph_b.add_node(name)
        grakn_graph_b.add_edge(person_b, name, type='has')

        combined_graph = combine_2_graphs(grakn_graph_a, grakn_graph_b)

        person_ex = Thing('V123', 'person', 'entity')
        employment_ex = Thing('V567', 'employment', 'relation')
        name_ex = Thing('V1234', 'name', 'attribute', value_type='string', value='Bob')
        expected_combined_graph = nx.MultiDiGraph()
        expected_combined_graph.add_node(person_ex)
        expected_combined_graph.add_node(name_ex)
        expected_combined_graph.add_node(employment_ex)
        expected_combined_graph.add_edge(employment_ex, person_ex, type='employee')
        expected_combined_graph.add_edge(person_ex, name_ex, type='has')

        self.assertGraphsEqual(expected_combined_graph, combined_graph)
Beispiel #2
0
    def test_when_graph_node_properties_are_mismatched_exception_is_raised(
            self):
        person_a = Thing('V123', 'person', 'entity')
        name_a = Thing('V1234',
                       'name',
                       'attribute',
                       data_type='string',
                       value='Bob')
        grakn_graph_a = nx.MultiDiGraph(name='a')
        grakn_graph_a.add_node(person_a, input=1, solution=1)
        grakn_graph_a.add_node(name_a, input=1, solution=1)
        grakn_graph_a.add_edge(person_a,
                               name_a,
                               type='has',
                               input=0,
                               solution=1)

        person_b = Thing('V123', 'person', 'entity')
        name_b = Thing('V1234',
                       'name',
                       'attribute',
                       data_type='string',
                       value='Bob')
        grakn_graph_b = nx.MultiDiGraph(name='b')
        grakn_graph_b.add_node(person_b, input=1, solution=1)
        grakn_graph_b.add_node(name_b, input=0, solution=1)
        grakn_graph_b.add_edge(person_b,
                               name_b,
                               type='has',
                               input=0,
                               solution=1)

        with self.assertRaises(ValueError) as context:
            combine_2_graphs(grakn_graph_a, grakn_graph_b)

        self.assertEqual(
            ('Found non-matching node properties for node <name, V1234: Bob> '
             'between graphs a and b:\n'
             'In graph a: {\'input\': 1, \'solution\': 1}\n'
             'In graph b: {\'input\': 0, \'solution\': 1}'),
            str(context.exception))