From b6f00385ab02a34b616afd2cab21c3d38dc0c6bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Sat, 19 Aug 2017 21:55:48 +0200 Subject: [PATCH] Fixed test for failed validation Note that the schema currently supports both string and object analysis in the "analysis" field of a result. --- docs/bad-examples/plugins/noplugins.json | 4 +- .../results/example-analysis-as-id-FAIL.json | 3 +- .../results/example-analysis-mixed-ids.json | 78 +++++++++++++++++++ docs/examples/results/example-suggestion.json | 5 +- senpy/schemas/plugins.json | 1 + tests/test_schemas.py | 3 +- 6 files changed, 85 insertions(+), 9 deletions(-) create mode 100644 docs/examples/results/example-analysis-mixed-ids.json diff --git a/docs/bad-examples/plugins/noplugins.json b/docs/bad-examples/plugins/noplugins.json index 9b50fb4..58f3a4d 100644 --- a/docs/bad-examples/plugins/noplugins.json +++ b/docs/bad-examples/plugins/noplugins.json @@ -1,4 +1,4 @@ { - "plugins": [ - ] + "@type": "plugins", + "plugins": {} } diff --git a/docs/bad-examples/results/example-analysis-as-id-FAIL.json b/docs/bad-examples/results/example-analysis-as-id-FAIL.json index a24e565..f3dcc5b 100644 --- a/docs/bad-examples/results/example-analysis-as-id-FAIL.json +++ b/docs/bad-examples/results/example-analysis-as-id-FAIL.json @@ -8,8 +8,7 @@ "me:EmotionAnalysis1", "me:NER1", { - "@type": "analysis", - "@id": "wrong" + "description": "missing @id and @type" } ], "entries": [ diff --git a/docs/examples/results/example-analysis-mixed-ids.json b/docs/examples/results/example-analysis-mixed-ids.json new file mode 100644 index 0000000..46c1465 --- /dev/null +++ b/docs/examples/results/example-analysis-mixed-ids.json @@ -0,0 +1,78 @@ +{ + "@context": "http://mixedemotions-project.eu/ns/context.jsonld", + "@id": "me:Result1", + "@type": "results", + "analysis": [ + "me:SAnalysis1", + "me:SgAnalysis1", + "me:EmotionAnalysis1", + "me:NER1", + { + "@type": "analysis", + "@id": "anonymous" + } + ], + "entries": [ + { + "@id": "http://micro.blog/status1", + "@type": [ + "nif:RFC5147String", + "nif:Context" + ], + "nif:isString": "Dear Microsoft, put your Windows Phone on your newest #open technology program. You'll be awesome. #opensource", + "entities": [ + { + "@id": "http://micro.blog/status1#char=5,13", + "nif:beginIndex": 5, + "nif:endIndex": 13, + "nif:anchorOf": "Microsoft", + "me:references": "http://dbpedia.org/page/Microsoft", + "prov:wasGeneratedBy": "me:NER1" + }, + { + "@id": "http://micro.blog/status1#char=25,37", + "nif:beginIndex": 25, + "nif:endIndex": 37, + "nif:anchorOf": "Windows Phone", + "me:references": "http://dbpedia.org/page/Windows_Phone", + "prov:wasGeneratedBy": "me:NER1" + } + ], + "suggestions": [ + { + "@id": "http://micro.blog/status1#char=16,77", + "nif:beginIndex": 16, + "nif:endIndex": 77, + "nif:anchorOf": "put your Windows Phone on your newest #open technology program", + "prov:wasGeneratedBy": "me:SgAnalysis1" + } + ], + "sentiments": [ + { + "@id": "http://micro.blog/status1#char=80,97", + "nif:beginIndex": 80, + "nif:endIndex": 97, + "nif:anchorOf": "You'll be awesome.", + "marl:hasPolarity": "marl:Positive", + "marl:polarityValue": 0.9, + "prov:wasGeneratedBy": "me:SAnalysis1" + } + ], + "emotions": [ + { + "@id": "http://micro.blog/status1#char=0,109", + "nif:anchorOf": "Dear Microsoft, put your Windows Phone on your newest #open technology program. You'll be awesome. #opensource", + "prov:wasGeneratedBy": "me:EAnalysis1", + "onyx:hasEmotion": [ + { + "onyx:hasEmotionCategory": "wna:liking" + }, + { + "onyx:hasEmotionCategory": "wna:excitement" + } + ] + } + ] + } + ] +} diff --git a/docs/examples/results/example-suggestion.json b/docs/examples/results/example-suggestion.json index be585bb..e209f03 100644 --- a/docs/examples/results/example-suggestion.json +++ b/docs/examples/results/example-suggestion.json @@ -3,10 +3,7 @@ "@id": "me:Result1", "@type": "results", "analysis": [ - { - "@id": "me:SgAnalysis1", - "@type": "me:SuggestionAnalysis" - } + "me:SgAnalysis1" ], "entries": [ { diff --git a/senpy/schemas/plugins.json b/senpy/schemas/plugins.json index 7cafd9b..df2aa3b 100644 --- a/senpy/schemas/plugins.json +++ b/senpy/schemas/plugins.json @@ -3,6 +3,7 @@ "allOf": [ {"$ref": "response.json"}, { + "required": ["plugins"], "properties": { "plugins": { "type": "array", diff --git a/tests/test_schemas.py b/tests/test_schemas.py index 1ddfdb8..44c6b1e 100644 --- a/tests/test_schemas.py +++ b/tests/test_schemas.py @@ -34,7 +34,8 @@ def do_create_(jsfile, success): except (AssertionError, ValidationError, KeyError) as ex: if success: raise - + return + assert success return do_expected