Debian Codegraph @

FaCT++.Python/examples/test-object-cardinality.py

raw symbols SCIP
1 #
2 # pyfactxx - Python interface to FaCT++ reasoner
3 #
4 # Copyright (C) 2016-2018 by Artur Wroblewski <[email protected]>
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #
19
20 import pyfactxx
21
22 reasoner = pyfactxx.Reasoner()
23
24 cls_a = reasoner.concept('CLS-A')
25 cls_b = reasoner.concept('CLS-B')
26 reasoner.disjoint_concepts(cls_a, cls_b)
27
28 r = reasoner.object_role('R')
29 reasoner.set_o_domain(r, cls_a)
30 reasoner.set_o_range(r, cls_b)
31
32 c = reasoner.individual('C')
33 reasoner.instance_of(c, cls_a)
34
35 restriction_max_one_cls_b = reasoner.max_o_cardinality(1, r, cls_b)
36 reasoner.implies_concepts(cls_a, restriction_max_one_cls_b)
37
38 d = reasoner.individual('D')
39 reasoner.instance_of(d, cls_b)
40 reasoner.related_to(c, r, d)
41 print('consistent after 1st instance:', reasoner.is_consistent())
42
43 # add another individual to class C, making ontology inconsistent
44 x = reasoner.individual('X')
45 reasoner.instance_of(x, cls_b)
46 reasoner.related_to(c, r, x)
47 reasoner.different_individuals(d, x)
48 print('consistent after 2nd instance:', reasoner.is_consistent())
49
50 # vim: sw=4:et:ai