1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
import pytest
from rdflib import OWL, RDF, RDFS, Graph, Namespace
from rdflib.extras.infixowl import ClassNamespaceFactory, Individual, Property, some
EXNS = Namespace("http://example.org/vocab/")
EXCL = ClassNamespaceFactory(EXNS)
@pytest.fixture(scope="function")
def graph():
g = Graph(identifier=EXNS.context0)
g.bind("ex", EXNS)
Individual.factoryGraph = g
yield g
del g
def test_logic_structuring(graph):
isPartOf = Property(EXNS.isPartOf) # noqa: N806
graph.add((isPartOf.identifier, RDF.type, OWL.TransitiveProperty))
hasLocation = Property(EXNS.hasLocation, subPropertyOf=[isPartOf]) # noqa: N806
graph.add((hasLocation.identifier, RDFS.subPropertyOf, isPartOf.identifier))
leg = EXCL.Leg
knee = EXCL.Knee
joint = EXCL.Joint
kneeJoint = EXCL.KneeJoint # noqa: N806
legStructure = EXCL.LegStructure # noqa: N806
kneeJoint.equivalentClass = [joint & (isPartOf @ some @ knee)]
structure = EXCL.Structure
legStructure.equivalentClass = [structure & (isPartOf @ some @ leg)]
structure += leg
structure += joint
locatedInLeg = hasLocation @ some @ leg # noqa: N806
locatedInLeg += knee
assert graph.serialize(format="ttl") == (
"@prefix ex: <http://example.org/vocab/> .\n"
"@prefix owl: <http://www.w3.org/2002/07/owl#> .\n"
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n"
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n"
"\n"
"ex:KneeJoint a owl:Class ;\n"
" owl:equivalentClass [ a owl:Class ;\n"
" owl:intersectionOf ( ex:Joint [ a owl:Restriction ;\n"
" owl:onProperty ex:isPartOf ;\n"
" owl:someValuesFrom ex:Knee ] ) ] .\n"
"\n"
"ex:LegStructure a owl:Class ;\n"
" owl:equivalentClass [ a owl:Class ;\n"
" owl:intersectionOf ( ex:Structure [ a owl:Restriction ;\n"
" owl:onProperty ex:isPartOf ;\n"
" owl:someValuesFrom ex:Leg ] ) ] .\n"
"\n"
"ex:Joint a owl:Class ;\n"
" rdfs:subClassOf ex:Structure .\n"
"\n"
"ex:Knee a owl:Class ;\n"
" rdfs:subClassOf [ a owl:Restriction ;\n"
" owl:onProperty ex:hasLocation ;\n"
" owl:someValuesFrom ex:Leg ] .\n"
"\n"
"ex:hasLocation a owl:ObjectProperty ;\n"
" rdfs:subPropertyOf ex:isPartOf .\n"
"\n"
"ex:Leg a owl:Class ;\n"
" rdfs:subClassOf ex:Structure .\n"
"\n"
"ex:Structure a owl:Class .\n"
"\n"
"ex:isPartOf a owl:ObjectProperty,\n"
" owl:TransitiveProperty .\n"
"\n"
)
|