Skip to content

Commit

Permalink
Merge pull request #84 from IIIF/adding_annopage_support
Browse files Browse the repository at this point in the history
Adding annopage support
  • Loading branch information
glenrobson authored Dec 12, 2019
2 parents 8924308 + 8f94de2 commit 55d217c
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 77 deletions.
19 changes: 19 additions & 0 deletions fixtures/3/annoPage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"@context": "http://iiif.io/api/presentation/3/context.json",
"id": "https://preview.iiif.io/cookbook/0068-newspaper/recipe/0068-newspaper/newspaper_issue_1-anno_p1.json",
"type": "AnnotationPage",
"items": [
{
"id": "https://data.europeana.eu/annotation/9200355/BibliographicResource_3000096302513/20b3b1f4cb15f062e53fd50d584d66ff",
"type": "Annotation",
"motivation": "supplementing",
"body": {
"type": "TextualBody",
"format": "text/plain",
"language": "de",
"value": "84"
},
"target": "https://iiif.europeana.eu/presentation/9200355/BibliographicResource_3000096302513/canvas/p1#xywh=182,476,59,43"
}
]
}
24 changes: 24 additions & 0 deletions fixtures/3/anno_pointselector.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"@context": "http://iiif.io/api/presentation/3/context.json",
"id": "https://preview.iiif.io/cookbook/0103-poetry/recipe/0103-poetry-reading-annotations/annotations.json",
"type": "AnnotationPage",
"items": [
{
"id": "https://preview.iiif.io/cookbook/0103-poetry/recipe/0103-poetry-reading-annotations/canvas/annotation1",
"type": "Annotation",
"motivation": "commenting",
"body": {
"type": "TextualBody",
"value": "breath",
"format": "text/plain"
},
"target": {
"source": "https://preview.iiif.io/cookbook/0103-poetry/recipe/0103-poetry-reading-annotations/canvas/1",
"selector": {
"type": "PointSelector",
"t": 27.660653
}
}
}
]
}
83 changes: 57 additions & 26 deletions schema/iiif_3_0.json
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@
"type": "object",
"properties": {
"id": { "$ref": "#/types/id" },
"@context": {},
"type": {
"type": "string",
"pattern": "^AnnotationPage$"
Expand Down Expand Up @@ -709,15 +710,65 @@
]
},
"target": {
"type": "string",
"format": "uri",
"pattern": "^http.*$"
"oneOf": [
{ "$ref": "#/classes/annoTarget" },
{
"type": "array",
"items": {
"$ref": "#/classes/annoTarget"
}
}
]
}
},
"required": ["target", "type"]
}
]
},
"annoTarget": {
"oneOf": [
{
"type": "string",
"format": "uri",
"pattern": "^http.*$"
},
{
"$ref": "#/classes/specificResource"
}
]
},
"specificResource": {
"type": "object",
"properties": {
"id": { "$ref": "#/types/id" },
"type": {
"type": "string",
"pattern": "^SpecificResource$"
},
"format": { "$ref": "#/types/format" },
"accessibility": { "type": "string"},
"source": { "$ref": "#/types/id" },
"selector": { "$ref": "#/classes/annoSelector" }
},
"required": ["source", "selector"]
},
"annoSelector": {
"oneOf": [
{
"type": "string",
"format": "uri",
"pattern": "^http.*$"
},
{
"type": "object",
"properties": {
"type": { "type": "string" },
"t": { "$ref": "#/types/duration" }
},
"required": ["type"]
}
]
},
"range": {
"allOf": [
{ "$ref": "#/types/class" },
Expand All @@ -734,28 +785,7 @@
"items": {
"oneOf": [
{
"type": "object",
"properties": {
"type": {
"type": "string",
"pattern": "^SpecificResource$"
},
"source": {
"type": "string"
},
"selector": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"value": {
"type": "string"
}
}
}
},
"required": ["source", "selector"]
"$ref": "#/classes/specificResource"
},
{
"allOf": [
Expand Down Expand Up @@ -789,7 +819,8 @@
{
"oneOf": [
{ "$ref": "#/classes/manifest" },
{ "$ref": "#/classes/collection" }
{ "$ref": "#/classes/collection" },
{ "$ref": "#/classes/annotationPage" }
]
}
]
Expand Down
56 changes: 6 additions & 50 deletions schema/schemavalidator.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def validate(data, version, url):
if 'is not valid under any of the given schemas' not in subErr.message:
subErrorMessages.append(subErr.message)
errorsJson.append({
'title': 'Error {} of {}.\n Message: Failed to process submission due to many errors'.format(errorCount, len(errors)),
'title': 'Error {} of {}.\n Message: Failed to process submission due too many errors'.format(errorCount, len(errors)),
'detail': 'This error is likely due to other listed errors. Fix those errors first.',
'description': "{}".format(subErrorMessages),
'path': '',
Expand Down Expand Up @@ -107,8 +107,8 @@ def validate(data, version, url):
}

if __name__ == '__main__':
if len(sys.argv) != 3:
print ('Usage:\n\t{} manifest schema'.format(sys.argv[0]))
if len(sys.argv) != 2:
print ('Usage:\n\t{} manifest'.format(sys.argv[0]))
exit(-1)
with open(sys.argv[1]) as json_file:
print ('Loading: {}'.format(sys.argv[1]))
Expand All @@ -118,50 +118,6 @@ def validate(data, version, url):
print ('Failed to load JSON due to: {}'.format(err))
exit(-1)

with open(sys.argv[2]) as schema_file:
print ('Loading schema: {}\n'.format(sys.argv[2]))
try:
schema = json.load(schema_file)
except ValueError as err:
print ('Failed to load schema due to JSON error: {}'.format(err))
exit(-1)

try:
validator = Draft7Validator(schema)
results = validator.iter_errors(iiif_json)
except SchemaError as err:
print('Problem with the supplied schema:\n')
print(err)

errors = sorted(results, key=lambda e: e.path)
if errors:
print('Validation Failed')
errorCount = 1
for err in errors:
print('Error {} of {}.\n Message: {}'.format(errorCount, len(errors), err.message))
if 'title' in err.schema:
print (' Test message: {}'.format(err.schema['title']))
if 'description' in err.schema:
print (' Test description: {}'.format(err.schema['description']))
print('\n Path for error: {}'.format(printPath(err.path, err.message)))
context = err.instance
for key in context:
if isinstance(context[key], list):
context[key] = '[ ... ]'
elif isinstance(context[key], dict):
context[key] = '{ ... }'

print (json.dumps(err.instance, indent=4))
errorCount += 1

# Return:
# infojson = {
# 'received': data,
# 'okay': okay,
# 'warnings': warnings,
# 'error': str(err),
# 'url': url
# }

else:
print ('Passed Validation!')
result = validate(json.dumps(iiif_json), '3.0', sys.argv[1])
for error in result['errorList']:
print (error['title'])
4 changes: 3 additions & 1 deletion tests/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ def test07_check_manifest3(self):
'fixtures/3/choice.json',
'fixtures/3/collection.json',
'fixtures/3/collection_of_collections.json',
'fixtures/3/version2image.json'
'fixtures/3/version2image.json',
'fixtures/3/annoPage.json',
'fixtures/3/anno_pointselector.json'
]:
with open(good, 'r') as fh:
data = fh.read()
Expand Down

0 comments on commit 55d217c

Please sign in to comment.