20
20
from pathmapper import abspath
21
21
22
22
from rdflib import URIRef
23
- from rdflib .namespace import RDFS
23
+ from rdflib .namespace import RDFS , OWL
24
24
25
25
import errno
26
26
@@ -141,18 +141,35 @@ def adjustFiles(rec, op):
141
141
for d in rec :
142
142
adjustFiles (d , op )
143
143
144
- def formatSubclassOf (fmt , cls , ontology ):
144
+ def formatSubclassOf (fmt , cls , ontology , visited ):
145
+ """Determine if `fmt` is a subclass of `cls`."""
146
+
147
+ if URIRef (fmt ) == URIRef (cls ):
148
+ return True
149
+
145
150
if ontology is None :
146
151
return False
147
152
153
+ if fmt in visited :
154
+ return
155
+
156
+ visited .add (fmt )
157
+
148
158
fmt = URIRef (fmt )
149
159
150
160
for s ,p ,o in ontology .triples ( (fmt , RDFS .subClassOf , None ) ):
151
- if o == URIRef (cls ):
161
+ # Find parent classes of `fmt` and search upward
162
+ if formatSubclassOf (o , cls , ontology , visited ):
152
163
return True
153
164
154
- for s ,p ,o in ontology .triples ( (fmt , RDFS .subClassOf , None ) ):
155
- if formatSubclassOf (o , cls , ontology ):
165
+ for s ,p ,o in ontology .triples ( (fmt , OWL .equivalentClass , None ) ):
166
+ # Find equivalent classes of `fmt` and search horizontally
167
+ if formatSubclassOf (o , cls , ontology , visited ):
168
+ return True
169
+
170
+ for s ,p ,o in ontology .triples ( (None , OWL .equivalentClass , fmt ) ):
171
+ # Find equivalent classes of `fmt` and search horizontally
172
+ if formatSubclassOf (s , cls , ontology , visited ):
156
173
return True
157
174
158
175
return False
@@ -162,7 +179,7 @@ def checkFormat(actualFile, inputFormats, requirements, ontology):
162
179
if "format" not in af :
163
180
raise validate .ValidationException ("Missing required 'format' for File %s" % af )
164
181
for inpf in aslist (inputFormats ):
165
- if af ["format" ] == inpf or formatSubclassOf (af ["format" ], inpf , ontology ):
182
+ if af ["format" ] == inpf or formatSubclassOf (af ["format" ], inpf , ontology , set () ):
166
183
return
167
184
raise validate .ValidationException ("Incompatible file format %s required format(s) %s" % (af ["format" ], inputFormats ))
168
185
0 commit comments