Exemple #1
0
    def setUp(self):
        super().setUp()
        self.premise = Graph()
        for premise_document in self.test.premise_documents:
            if premise_document.type != TEST['False-Document']:
                self.premise.update(premise_document.read(self.opener))
            else:
                self.premise = False

        self.entailments = []
        for rules_uri in self.test.entailment_rules:
            entailment = self.ENTAILMENT_RULES[rules_uri]
            self.entailments.append(entailment)
        if (SIMPLE_ENTAILMENT not in self.entailments
                and SIMPLE_ENTAILMENT_LG not in self.entailments):
            self.entailments.append(SIMPLE_ENTAILMENT_LG)

        self.merged_entailment = Entailment()
        for entailment in self.entailments:
            self.merged_entailment.conditions += entailment.conditions
            self.merged_entailment.axioms |= entailment.axioms
            self.merged_entailment.rules += entailment.rules

        self.merged_entailment.axioms |= {
            (datatype, RDF.type, RDFS.Datatype)
            for datatype in self.test.datatype_support
        }

        if self.test.conclusion_document.type != TEST['False-Document']:
            self.conclusion = Graph(
                self.test.conclusion_document.read(self.opener))
        else:
            self.conclusion = False
Exemple #2
0
 def setUp(self):
     self.rule = Rule({}, {(RDF.type, RDF.type, RDF.Property)})
     self.rule_se1 = Rule({(uuu, aaa, xxx)}, {(uuu, aaa, xxx.nnn)},
                          name='se1')
     self.empty_graph = Graph()
     self.graph = Graph({(EX.a, EX.property, EX.b),
                         (EX.b, EX.property, EX.c)})
     self.context = Context()
Exemple #3
0
 def setUp(self):
     self.triples = {(URI('http://www.example.org/index.html'),
                      URI('http://purl.org/dc/elements/1.1/creator'),
                      URI('http://www.example.org/staffid/85740')),
                     (URI('http://www.example.org/staffid/85740'),
                      URI('http://xmlns.com/foaf/0.1/name'),
                      Literal("John Lennon", XSD.string))}
     self.graph = Graph(self.triples)
Exemple #4
0
 def test_not_equal_to_graph_with_different_number_of_unground_triples(self):
     graph = Graph({(URI('http://www.example.org/index.html'),
                     URI('http://purl.org/dc/elements/1.1/creator'),
                     URI('john')),
                    (URI('john'),
                     URI('http://xmlns.com/foaf/0.1/name'),
                     Literal("John Lennon", XSD.string))})
     self.assertNotEqual(self.graph, graph)        
     self.assertNotEqual(graph, self.graph)        
Exemple #5
0
 def test_not_equal_to_graph_without_valid_bijection(self):
     graph = Graph({(URI('http://www.example.org/index.html'),
                     URI('http://purl.org/dc/elements/1.1/creator'),
                     BlankNode('john')),
                    (BlankNode('john'),
                     URI('http://xmlns.com/foaf/0.1/name'),
                     Literal("John Lennon", XSD.string)),
                    (BlankNode('paul'),
                     URI('http://xmlns.com/foaf/0.1/knows'),
                     BlankNode('john'))})
     self.assertNotEqual(self.graph, graph)
     self.assertNotEqual(graph, self.graph)
Exemple #6
0
 def setUp(self):
     self.triples = {(URI('http://www.example.org/index.html'),
                      URI('http://purl.org/dc/elements/1.1/creator'),
                      BlankNode('john')),
                     (BlankNode('john'),
                      URI('http://xmlns.com/foaf/0.1/name'),
                      Literal("John Lennon", XSD.string)),
                     (BlankNode('john'),
                      URI('http://xmlns.com/foaf/0.1/knows'),
                      BlankNode('paul')),
                     (EX.a, EX.property, EX.b),
                     (EX.b, EX.property, EX.c)}
     self.bijection = {(URI('http://www.example.org/index.html'),
                        URI('http://purl.org/dc/elements/1.1/creator'),
                        BlankNode('lennon')),
                       (BlankNode('lennon'),
                        URI('http://xmlns.com/foaf/0.1/name'),
                        Literal("John Lennon", XSD.string)),
                       (BlankNode('lennon'),
                        URI('http://xmlns.com/foaf/0.1/knows'),
                        BlankNode('starr'))}
     self.graph = Graph(self.triples)
     self.subgraph = Graph(self.bijection)
Exemple #7
0
 def entails(self, s, e):
     if s >= e:
         return True
     entailed = Graph(s | self.axioms)
     context = Context()
     num_triples = -1
     while len(entailed) != num_triples:
         num_triples = len(entailed)
         for rule in self.rules:
             entailed.update(rule.apply(entailed, context))
             if len(entailed) != num_triples:
                 if e <= entailed:
                     return True
     for triple in e:
         if triple not in entailed:
             for entailed_triple in entailed:
                 pattern = Pattern(entailed_triple)
                 if pattern.matches(triple):
                     break
             else:
                 return False
     return True
Exemple #8
0
 def test_graph_with_same_triples_is_subgraph(self):
     self.assert_(Graph(self.triples) <= self.graph)
     self.assert_(self.graph <= Graph(self.triples))
Exemple #9
0
 def test_empty_graph_is_a_subgraph(self):
     self.assertTrue(Graph() <= self.graph)
     self.assertTrue(self.graph <= Graph())
Exemple #10
0
 def test_is_supergraph_of_graph_with_valid_bijection(self):
     self.assert_(self.graph >= Graph(self.bijection))
Exemple #11
0
 def test_is_not_a_strict_supergraph_of_graph_with_valid_bijection(self):
     self.assertFalse(self.graph > Graph(self.bijection))
Exemple #12
0
 def test_equal_to_graph_with_same_triples(self):
     self.assertEqual(self.graph, Graph(self.triples))
Exemple #13
0
 def test_empty_graph_is_not_a_supergraph(self):
     self.assertFalse(Graph() >= self.graph)
Exemple #14
0
 def test_apply_with_empty_antecedent_to_empty_graph_does_not_yield_consequent(
         self):
     graph = Graph(self.rule_se1.apply(self.empty_graph, self.context))
     self.assertEqual(graph, Graph())
Exemple #15
0
 def setUp(self):
     super().setUp()
     self.input_graph = Graph()
     for document in self.test.input_documents:
         self.input_graph.update(document.read(self.opener))
     self.output_graph = Graph(self.test.output_document.read(self.opener))
Exemple #16
0
 def test_empty_graphs_are_equal(self):
     self.assertEqual(self.graph, Graph())
Exemple #17
0
 def test_equal_to_graph_with_valid_bijection(self):
     graph = Graph(self.bijection)
     self.assertEqual(self.graph, graph)
     self.assertEqual(graph, self.graph)
Exemple #18
0
 def test_graph_with_same_triples_is_not_a_strict_supergraph(self):
     self.assertFalse(Graph(self.triples) > self.graph)
     self.assertFalse(self.graph > Graph(self.triples))
Exemple #19
0
 def test_empty_graph_is_a_subgraph(self):
     graph = Graph()
     self.assertTrue(graph <= self.graph)
     self.assertTrue(self.graph <= graph)
Exemple #20
0
 def test_is_supergraph_of_empty_graph(self):
     self.assert_(self.graph >= Graph())
Exemple #21
0
 def test_empty_graph_is_not_a_strict_supergraph(self):
     self.assertFalse(Graph() > self.graph)
     self.assertFalse(self.graph > Graph())
Exemple #22
0
 def test_empty_graph_is_a_subgraph(self):
     self.assert_(Graph() < self.graph)
Exemple #23
0
 def test_empty_graph_is_a_supergraph(self):
     self.assertTrue(Graph() >= self.graph)
     self.assertTrue(self.graph >= Graph())
Exemple #24
0
 def test_graph_with_valid_bijection_is_supergraph(self):
     self.assert_(Graph(self.bijection) >= self.graph)
Exemple #25
0
 def test_not_equal_to_graph_of_different_size(self):
     graph = Graph(list(self.triples)[0])
     self.assertNotEqual(self.graph, graph)
     self.assertNotEqual(graph, self.graph)
Exemple #26
0
 def graph_with_valid_bijection_is_not_a_strict_supergraph(self):
     self.assertFalse(Graph(self.bijection) > self.graph)
Exemple #27
0
 def test_apply_empty_antecedent_to_graph_yields_consequent(self):
     graph = Graph(self.rule.apply(self.graph, self.context))
     self.assertEqual(graph, Graph({(RDF.type, RDF.type, RDF.Property)}))
Exemple #28
0
 def test_graph_with_same_triples_is_supergraph(self):
     self.assert_(Graph(self.triples) >= self.graph)
     self.assert_(self.graph >= Graph(self.triples))
Exemple #29
0
 def test_apply_to_graph_yields_consequent(self):
     graph = Graph(self.rule_se1.apply(self.graph, self.context))
     self.assertEqual(
         graph,
         Graph({(EX.a, EX.property, BlankNode()),
                (EX.b, EX.property, BlankNode())}))
Exemple #30
0
 def test_empty_graph_is_not_a_strict_subgraph(self):
     self.assertFalse(Graph() < self.graph)
     self.assertFalse(self.graph < Graph())