Skip to content

Commit 5fdc805

Browse files
author
Peter Amstutz
committed
Support reasoning about owl:equivalentClass when checking file formats
compatibility.
1 parent 840c7e9 commit 5fdc805

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

cwltool/process.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from pathmapper import abspath
2121

2222
from rdflib import URIRef
23-
from rdflib.namespace import RDFS
23+
from rdflib.namespace import RDFS, OWL
2424

2525
import 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

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
'rdflib >= 4.2.0',
3737
'rdflib-jsonld >= 0.3.0',
3838
'shellescape',
39-
'schema_salad == 1.5.20160126213649'
39+
'schema_salad == 1.6.20160202222448
4040
],
4141
test_suite='tests',
4242
tests_require=[],

0 commit comments

Comments
 (0)