- if r['type'] == rdfsNS['Resource']:
- if node.is_literal():
- return resource_error.format(str(node), space)
- continue
- seen.add(str(r['type'].uri))
- if node.is_literal():
- # literal is a generic type.
- nodetype = node.literal_value['datatype']
- if nodetype is None:
- # lets default to string
- nodetype = xsdNS['string'].uri
- if r['type'] == rdfsNS['Literal']:
- pass
- elif nodetype != r['type'].uri:
- return type_error.format(
- str(node), nodetype, r['type'])
- # check that node is the expetected class type
- check = RDF.Statement(node, rdfNS['type'], r['type'])
- if self.model.contains_statement(check):
- return
-
- # need the seen check, because we're surpressing checking
- # rdfs:Resource types
- if len(seen) > 0:
- return errmsg + ",".join(seen)
-
+ expected_type = r['type']
+
+ if isinstance(node, Literal):
+ if expected_type == RDFS['Literal']:
+ return []
+ elif node.datatype == expected_type:
+ return []
+ else:
+ # not currently handling type hierarchy.
+ # a integer could pass a range of decimal for instance.
+ errors.append(
+ "Type error: {} was type {}, expected {}".format(
+ str(node),
+ str(node.datatype),
+ str(expected_type)))
+ elif expected_type == RDFS['Resource']:
+ if isinstance(node, Literal):
+ errors.append(resource_error.format(str(node), space))
+ else:
+ return []
+ else:
+ check = (node, RDF['type'], expected_type)
+ if check not in self.model:
+ errors.append(errmsg + str(node) + ' was not a ' + str(expected_type))
+ else:
+ return []
+
+ return errors
+ ### End nested function