From efdf67db17848c1680fcb803a56a693bf655d5c3 Mon Sep 17 00:00:00 2001 From: Laurens Weijs Date: Tue, 23 Jul 2024 09:29:51 +0200 Subject: [PATCH 1/5] Add argparse --- README.md | 2 +- scripts/validate | 37 ++++++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index a43762be..dfa243f5 100644 --- a/README.md +++ b/README.md @@ -80,5 +80,5 @@ kubectl apply -k infra/ ## Validate schema of YAML ```sh -./scripts/validate schemas/base.schema.json tests/sample-decision-tree-complex.yaml +./scripts/validate --schema_file schemas/base.schema.json --yaml_file tests/sample-decision-tree-complex.yaml ``` diff --git a/scripts/validate b/scripts/validate index e29f3bc1..b571ab01 100755 --- a/scripts/validate +++ b/scripts/validate @@ -2,24 +2,35 @@ import json import sys +import argparse import jsonschema import yaml from jsonschema import validate +# Argument parsing +parser = argparse.ArgumentParser() +parser.add_argument("--schema_file", help="file location of the JSON schema file to check the YAML against", + type=str) +parser.add_argument("--yaml_file", help="file location of te YAML file to check the schema against", + type=str) + +args = parser.parse_args() + + # Load the JSON schema -with open(sys.argv[1], "r") as schema_file: +with open(args.schema_file, "r") as schema_file: schema = json.load(schema_file) -for f in sys.argv[2:]: - # Load the YAML file - with open(f, "r") as yaml_file: - data = yaml.safe_load(yaml_file) - - # Validate the data - try: - validate(instance=data, schema=schema) - print(f"Validation of '{f}' successful.") - except jsonschema.exceptions.ValidationError as err: - print(f"Validation error in '{f}': {err.message}") - sys.exit(1) +# Load the YAML file +f = args.yaml_file +with open(f, "r") as yaml_file: + data = yaml.safe_load(yaml_file) + +# Validate the data +try: + validate(instance=data, schema=schema) + print("Validation of '{f}' successful.".format(f=f)) +except jsonschema.exceptions.ValidationError as err: + print("Validation error in '{f}': {err.message}".format(f=f, err=err)) + sys.exit(1) From 2e4047013c2a64e879bf2dc51fb83df937dee68f Mon Sep 17 00:00:00 2001 From: Laurens Weijs Date: Tue, 23 Jul 2024 09:30:18 +0200 Subject: [PATCH 2/5] Linting --- scripts/validate | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/validate b/scripts/validate index b571ab01..d6eb9b01 100755 --- a/scripts/validate +++ b/scripts/validate @@ -14,10 +14,8 @@ parser.add_argument("--schema_file", help="file location of the JSON schema file type=str) parser.add_argument("--yaml_file", help="file location of te YAML file to check the schema against", type=str) - args = parser.parse_args() - # Load the JSON schema with open(args.schema_file, "r") as schema_file: schema = json.load(schema_file) From daf18e27968d683f10249f9337fd0d913ef6565a Mon Sep 17 00:00:00 2001 From: Laurens Weijs Date: Tue, 23 Jul 2024 10:37:33 +0200 Subject: [PATCH 3/5] Add subresult in schema and extend on example --- schemas/base.schema.json | 3 +++ tests/sample-decision-tree-complex.yaml | 2 ++ 2 files changed, 5 insertions(+) diff --git a/schemas/base.schema.json b/schemas/base.schema.json index fdad9a9e..c3e99e56 100644 --- a/schemas/base.schema.json +++ b/schemas/base.schema.json @@ -88,6 +88,9 @@ "result": { "$ref": "#/$defs/Result" }, + "subresult": { + "$ref": "#/$defs/Result" + }, "answerComment": { "$ref": "#/$defs/AnswerComment" }, diff --git a/tests/sample-decision-tree-complex.yaml b/tests/sample-decision-tree-complex.yaml index e9fad830..dbe96322 100644 --- a/tests/sample-decision-tree-complex.yaml +++ b/tests/sample-decision-tree-complex.yaml @@ -10,6 +10,8 @@ questions: - answer: Ja labels: - "Wel een algoritme" + - "Hoog risico AI" + subresult: "Het is eeen algoritme en een hoog risico AI systeem" nextQuestionId: '1.0' - answer: Nee labels: From 8be3621a7e0d306e855bc34d059c0f75dc24ba39 Mon Sep 17 00:00:00 2001 From: Laurens Weijs Date: Tue, 23 Jul 2024 13:33:33 +0200 Subject: [PATCH 4/5] Add more fields for Question from demand --- schemas/base.schema.json | 30 +++++++++++++++++++++++++ tests/sample-decision-tree-complex.yaml | 3 +++ 2 files changed, 33 insertions(+) diff --git a/schemas/base.schema.json b/schemas/base.schema.json index c3e99e56..42549452 100644 --- a/schemas/base.schema.json +++ b/schemas/base.schema.json @@ -36,6 +36,18 @@ "type": "string", "uniqueItems": true }, + "Source": { + "id": "#/$defs/Source", + "type": "string" + }, + "SourceURL": { + "id": "#/$defs/SourceURL", + "type": "string" + }, + "Description": { + "id": "#/$defs/Description", + "type": "string" + }, "AnswerComment": { "id": "#/$defs/AnswerComment", "type": "string" @@ -143,6 +155,15 @@ "question": { "$ref": "#/$defs/Question" }, + "source": { + "$ref": "#/$defs/Source" + }, + "source_url": { + "$ref": "#/$defs/SourceURL" + }, + "description": { + "$ref": "#/$defs/Description" + }, "questionType": { "type": "string", "enum": ["MultipleChoice"] @@ -167,6 +188,15 @@ "question": { "$ref": "#/$defs/Question" }, + "source": { + "$ref": "#/$defs/Source" + }, + "source_url": { + "$ref": "#/$defs/SourceURL" + }, + "description": { + "$ref": "#/$defs/Description" + }, "questionType": { "type": "string", "enum": ["SingleChoice"] diff --git a/tests/sample-decision-tree-complex.yaml b/tests/sample-decision-tree-complex.yaml index dbe96322..4a947dc8 100644 --- a/tests/sample-decision-tree-complex.yaml +++ b/tests/sample-decision-tree-complex.yaml @@ -6,6 +6,9 @@ questions: - questionId: '0' question: "Is het een algoritme?" questionType: SingleChoice + source: "AI Wetgeving MinBZK" + source_url: "https://minbzk.nl/AI_wetgeving/" + description: "Een klein test beschrijving" answers: - answer: Ja labels: From 5572b870ad0c4d6c5497d61c6a5a47d1345d2900 Mon Sep 17 00:00:00 2001 From: Laurens Weijs Date: Tue, 23 Jul 2024 16:37:54 +0200 Subject: [PATCH 5/5] Add Conclusion Object --- schemas/base.schema.json | 44 +++++++++++++++++++++++++ tests/sample-decision-tree-complex.yaml | 24 +++++--------- 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/schemas/base.schema.json b/schemas/base.schema.json index 42549452..eba9ea5f 100644 --- a/schemas/base.schema.json +++ b/schemas/base.schema.json @@ -60,6 +60,18 @@ "id": "#/$defs/If", "type": "string" }, + "ConclusionId": { + "id": "#/$defs/ConclusionId", + "type": "string" + }, + "ConclusionComment": { + "id": "#/$defs/ConclusionComment", + "type": "string" + }, + "Obligation": { + "id": "#/$defs/Obligation", + "type": "string" + }, "Default": { "id": "#/$defs/Default", "type": "string" @@ -142,6 +154,9 @@ }, { "$ref": "#/$defs/SingleChoiceQuestion" + }, + { + "$ref": "#/$defs/Conclusion" } ] }, @@ -211,6 +226,35 @@ } }, "required": ["questionId", "question", "questionType", "answers"] + }, + "Conclusion": { + "id": "#/$defs/Conclusion", + "type": "object", + "properties": { + "conclusionId": { + "$ref": "#/$defs/ConclusionId" + }, + "conclusion": { + "type": "string" + }, + "conclusionComment": { + "$ref": "#/$defs/ConclusionComment" + }, + "obligation": { + "$ref": "#/$defs/Obligation" + }, + "source": { + "$ref": "#/$defs/Source" + }, + "source_url": { + "$ref": "#/$defs/SourceURL" + }, + "questionType": { + "type": "string", + "enum": ["Conclusion"] + } + }, + "required": ["conclusionId", "conclusion", "obligation"] } } } diff --git a/tests/sample-decision-tree-complex.yaml b/tests/sample-decision-tree-complex.yaml index 4a947dc8..8ca5f1bc 100644 --- a/tests/sample-decision-tree-complex.yaml +++ b/tests/sample-decision-tree-complex.yaml @@ -41,21 +41,13 @@ questions: - default: '3.0' ## Resultaat dat alles oke is -- questionId: '2.0' - question: "The answer" - questionType: SingleChoice - answers: - - answer: Je antwoord is consistent, goed zo - result: Je antwoord is consistent, goed zo - - answer: Je antwoord is consistent, goed zo - result: Je antwoord is consistent, goed zo +- conclusionId: '2.0' + conclusion: "Je antwoord is consistent, goed zo" + questionType: Conclusion + obligation: "Volgens Art. 5 lid 2 ben je goed bezig" ### Resultaat dat iemand inconsistent is -- questionId: '3.0' - question: "The answer" - questionType: SingleChoice - answers: - - answer: Je antwoord is niet consistent, probeer opnieuw - result: Je antwoord is niet consistent, probeer opnieuw - - answer: Je antwoord is niet consistent, probeer opnieuw - result: Je antwoord is niet consistent, probeer opnieuw +- conclusionId: '3.0' + conclusion: "Je antwoord is niet consistent, probeer opnieuw" + questionType: Conclusion + obligation: "Volgens Art. 5 lid 2 ben je slecht bezig"