Skip to content

Commit

Permalink
implemented vectorized annotation validation
Browse files Browse the repository at this point in the history
  • Loading branch information
bmcfee committed Sep 6, 2017
1 parent 852ed8d commit f44a275
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
6 changes: 3 additions & 3 deletions jams/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,12 +763,12 @@ def validate(self, strict=True):
valid = super(Annotation, self).validate(strict=strict)

# Get the schema for this annotation
ann_schema = schema.namespace(self.namespace)
ann_schema = schema.namespace_array(self.namespace)

try:
# validate each record in the frame
for rec in self.data:
jsonschema.validate(serialize_obj(rec), ann_schema)
data_ser = [serialize_obj(obs) for obs in self.data]
jsonschema.validate(data_ser, ann_schema)

except jsonschema.ValidationError as invalid:
if strict:
Expand Down
23 changes: 23 additions & 0 deletions jams/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
add_namespace
namespace
namespace_array
is_dense
values
get_dtypes
Expand Down Expand Up @@ -74,6 +75,28 @@ def namespace(ns_key):
return sch


def namespace_array(ns_key):
'''Construct a validation schema for arrays of a given namespace.
Parameters
----------
ns_key : str
Namespace key identifier
Returns
-------
schema : dict
JSON schema of `namespace` observation arrays
'''

obs_sch = namespace(ns_key)
obs_sch['title'] = 'Observation'

sch = copy.deepcopy(JAMS_SCHEMA['definitions']['SparseObservationList'])
sch['items'] = obs_sch
return sch


def is_dense(ns_key):
'''Determine whether a namespace has dense formatting.
Expand Down

0 comments on commit f44a275

Please sign in to comment.