2020from pathmapper import abspath
2121
2222from rdflib import URIRef
23- from rdflib .namespace import RDFS
23+ from rdflib .namespace import RDFS , OWL
2424
2525import errno
2626
@@ -141,18 +141,35 @@ def adjustFiles(rec, op):
141141 for d in rec :
142142 adjustFiles (d , op )
143143
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+
145150 if ontology is None :
146151 return False
147152
153+ if fmt in visited :
154+ return
155+
156+ visited .add (fmt )
157+
148158 fmt = URIRef (fmt )
149159
150160 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 ):
152163 return True
153164
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 ):
156173 return True
157174
158175 return False
@@ -162,7 +179,7 @@ def checkFormat(actualFile, inputFormats, requirements, ontology):
162179 if "format" not in af :
163180 raise validate .ValidationException ("Missing required 'format' for File %s" % af )
164181 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 () ):
166183 return
167184 raise validate .ValidationException ("Incompatible file format %s required format(s) %s" % (af ["format" ], inputFormats ))
168185
0 commit comments