Debian Codegraph @

FaCT++.Python/coras/integration/test_coras.py

raw symbols SCIP
1 # Coras - OWL reasoning system
2 #
3 # Copyright (C) 2018 by Artur Wroblewski <[email protected]>
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #
18
19 import csv
20 import os.path
21 from functools import partial
22
23 import pytest
24
25 from pyfactxx import coras
26 from pyfactxx.coras.cli import load_and_parse
27
28 import rdflib
29
30
31 TESTS = [
32 ('foaf', '01-foaf.sq', ['foaf.rdf', 'tbl-foaf-card.n3'], '01-result.csv'),
33 ('foaf', '02-foaf.sq', ['foaf.rdf', 'tbl-foaf-card.n3'], '02-result.csv'),
34 ('foaf', '03-foaf.sq', ['foaf.rdf', '03-foaf-ex.n3'], '03-result.csv'),
35 ('zebra', '01-zebra.sq', ['zebra.n3'], '01-result.csv'),
36 ('zebra', '02-zebra.sq', ['zebra.n3'], '02-result.csv'),
37 ('tsars', '01-tsars.sq', ['tsars.rdf'], '01-result.csv'),
38 ('tsars', '02-tsars.sq', ['tsars.rdf'], '02-result.csv'),
39 ]
40
41
42 @pytest.mark.parametrize(
43 'prefix,query,ontologies,expected',
44 TESTS,
45 )
46 def test_coras(prefix, query, ontologies, expected):
47 """Test coras RDFlib interface"""
48 crs = coras.Coras()
49
50 f_path = partial(os.path.join, os.path.dirname(__file__), prefix)
51 f_open = lambda fn: open(f_path(fn))
52
53 files = (f_path(fn) for fn in ontologies)
54 load_and_parse(crs, *files)
55 crs.realise()
56
57 with f_open(expected) as f:
58 expected = list(csv.reader(f))
59
60 with f_open(query) as f:
61 sq = f.read()
62
63 result = crs.query(sq)
64 result = [[str(s) for s in row] for row in result if all(not isinstance(s, rdflib.BNode) for s in row)]
65
66 assert sorted(expected) == sorted(result)
67
68 # vim: sw=4:et:ai