Conclusie
- {{ conclusion }}
+
@@ -32,7 +32,7 @@ import { ExclamationTriangleIcon } from '@heroicons/vue/24/outline'
Verplichtingen
- {{ obligation }}
+
@@ -68,7 +68,8 @@ import { ExclamationTriangleIcon } from '@heroicons/vue/24/outline'
Contact
- Mocht u vragen of opmerkingen hebben naar aanleiding van deze beslisboom, mail dan gerust naar ai-verordening@minbzk.nl.
+ Mocht u vragen of opmerkingen hebben naar aanleiding van deze beslisboom, mail dan gerust naar
+ ai-verordening@minbzk.nl.
diff --git a/frontend/src/components/SingleQuestion.vue b/frontend/src/components/SingleQuestion.vue
index 453e33f8..0141a3c0 100644
--- a/frontend/src/components/SingleQuestion.vue
+++ b/frontend/src/components/SingleQuestion.vue
@@ -2,7 +2,6 @@
interface Props {
id: string
question: string
- definitions: { term: string; definition: string; url: string | undefined; }[] | undefined
sources: { source: string; url: string | undefined; }[] | undefined
}
defineProps()
@@ -17,21 +16,9 @@ defineProps()
>
- {{ question }}
+
-
-
-
- Definities
-
-
-
- -
- {{ item.term }}: {{ item.definition }}
-
-
-
diff --git a/frontend/src/models/DecisionTree.ts b/frontend/src/models/DecisionTree.ts
index 3da9051d..a1921bde 100644
--- a/frontend/src/models/DecisionTree.ts
+++ b/frontend/src/models/DecisionTree.ts
@@ -25,18 +25,9 @@ export const Source = t.type({
})
export type Source = t.TypeOf
-export const Definition = t.type({
- term: t.string,
- definition: t.string,
- url: t.union([t.string, t.undefined]),
- source: t.union([t.string, t.undefined])
-})
-export type Definition = t.TypeOf
-
export const Question = t.type({
questionId: t.string,
question: t.string,
- definitions: t.union([t.array(Definition), t.undefined]),
sources: t.union([t.array(Source), t.undefined]),
description: t.union([t.string, t.undefined]),
answers: t.array(Answer)
diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json
index c130bd5e..70ee067d 100644
--- a/frontend/tsconfig.json
+++ b/frontend/tsconfig.json
@@ -6,7 +6,8 @@
"allowUnusedLabels": false,
"alwaysStrict": true,
"noImplicitAny": true,
- "noImplicitReturns": true
+ "noImplicitReturns": true,
+ "resolveJsonModule": true
},
"files": [],
"references": [
diff --git a/schemas/base.schema.json b/schemas/schema_decision_tree.json
similarity index 88%
rename from schemas/base.schema.json
rename to schemas/schema_decision_tree.json
index 7e7ff306..fdfd1024 100644
--- a/schemas/base.schema.json
+++ b/schemas/schema_decision_tree.json
@@ -61,22 +61,6 @@
"id": "#/$defs/Description",
"type": "string"
},
- "Definition": {
- "id": "#/$defs/Definition",
- "type": "object",
- "properties": {
- "term": {
- "type": "string"
- },
- "definition": {
- "type": "string"
- },
- "url": {
- "type": "string"
- }
- },
- "required": ["term", "definition"]
- },
"AnswerComment": {
"id": "#/$defs/AnswerComment",
"type": "string"
@@ -199,12 +183,6 @@
"$ref": "#/$defs/Description",
"type": "string"
},
- "definitions": {
- "type": "array",
- "items": {
- "$ref": "#/$defs/Definition"
- }
- },
"questionType": {
"type": "string",
"enum": ["MultipleChoice"]
@@ -239,12 +217,6 @@
"$ref": "#/$defs/Description",
"type": "string"
},
- "definitions": {
- "type": "array",
- "items": {
- "$ref": "#/$defs/Definition"
- }
- },
"questionType": {
"type": "string",
"enum": ["SingleChoice"]
@@ -281,12 +253,6 @@
"items": {
"$ref": "#/$defs/Source"
}
- },
- "definitions": {
- "type": "array",
- "items": {
- "$ref": "#/$defs/Definition"
- }
}
},
"required": ["conclusionId", "conclusion", "obligation"]
diff --git a/schemas/schema_definitions.json b/schemas/schema_definitions.json
new file mode 100644
index 00000000..10fa72a4
--- /dev/null
+++ b/schemas/schema_definitions.json
@@ -0,0 +1,26 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "type": "object",
+ "properties": {
+ "definitions": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "term": {
+ "type": "string",
+ "description": "The term being defined."
+ },
+ "definition": {
+ "type": "string",
+ "description": "The definition of the term."
+ }
+ },
+ "required": ["term", "definition"],
+ "additionalProperties": false
+ , "minItems": 1}
+ }
+ },
+ "required": ["definitions"],
+ "additionalProperties": false
+}
diff --git a/script/inject_definitions_in_decision_tree.py b/script/inject_definitions_in_decision_tree.py
new file mode 100644
index 00000000..cbcc8991
--- /dev/null
+++ b/script/inject_definitions_in_decision_tree.py
@@ -0,0 +1,91 @@
+# !/usr/bin/env python3
+
+import yaml
+import re
+import json
+
+# Load the decision-tree.yaml file
+with open("decision-tree.yaml", "r") as file:
+ decision_tree = yaml.safe_load(file)
+
+# Load the definitions.yaml file
+with open("definitions.yaml", "r") as file:
+ definitions = yaml.safe_load(file)
+
+# Create a dictionary to lookup terms
+term_dict = {
+ definition["term"]: (
+ f"{definition['term']}"
+ )
+ for definition in definitions["definitions"]
+}
+
+pattern = re.compile(
+ "|".join(
+ [re.escape(term) for term in sorted(term_dict.keys(), key=len, reverse=True)]
+ )
+)
+
+
+def replace_terms_callback(match):
+ """
+ Callback function for replacing terms with their ... version.
+ """
+ term = match.group(0)
+ return term_dict.get(term, term)
+
+
+def replace_terms(text, term_dict):
+ """
+ Replace all occurrences of terms in the text with their corresponding wrapped terms.
+ Uses a regular expression with a callback function to ensure the longest term is replaced first.
+ """
+ return pattern.sub(replace_terms_callback, text)
+
+
+def process_question_or_conclusion(text, term_dict):
+ """
+ Process a question or conclusion, replacing terms and returning the modified text.
+ """
+ if text:
+ modified_text = replace_terms(text, term_dict)
+ return modified_text
+ return text
+
+
+# Process questions
+for q in decision_tree.get("questions", []):
+ q["question"] = process_question_or_conclusion(q.get("question", ""), term_dict)
+
+ if "description" in q:
+ q["description"] = process_question_or_conclusion(
+ q.get("description", ""), term_dict
+ )
+
+ for a in q.get("answers", []):
+ a["answer"] = process_question_or_conclusion(a.get("answer", ""), term_dict)
+
+ if "subresult" in a:
+ a["subresult"] = process_question_or_conclusion(
+ a.get("subresult", ""), term_dict
+ )
+
+ if "answerComment" in a:
+ a["answerComment"] = process_question_or_conclusion(
+ a.get("answerComment", ""), term_dict
+ )
+
+# Process conclusions
+for c in decision_tree.get("conclusions", []):
+ c["conclusion"] = process_question_or_conclusion(c.get("conclusion", ""), term_dict)
+
+ c["obligation"] = process_question_or_conclusion(c.get("obligation", ""), term_dict)
+
+ if "conclusionComment" in c:
+ c["conclusionComment"] = process_question_or_conclusion(
+ c.get("conclusionComment", ""), term_dict
+ )
+
+# Save the modified decision_tree back to a YAML file
+with open("frontend/src/assets/decision-tree.json", "w+") as file:
+ json.dump(decision_tree, file)
diff --git a/script/validate b/script/validate
index f9da6a24..d4baedbe 100755
--- a/script/validate
+++ b/script/validate
@@ -11,30 +11,43 @@ 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",
+ "--file_pairs",
+ nargs="+", # Accept multiple pairs of schema and YAML files
+ help="Pairs of schema and YAML files, in the format schema1.json:file1.yaml schema2.json:file2.yaml",
type=str,
)
+
args = parser.parse_args()
-# Load the JSON schema
-with open(args.schema_file, "r") as schema_file:
- schema = json.load(schema_file)
-
-# 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))
+
+# Function to validate a single pair
+def validate_pair(schema_file, yaml_file):
+ # Load the JSON schema
+ with open(schema_file, "r") as sf:
+ schema = json.load(sf)
+
+ # Load the YAML file
+ with open(yaml_file, "r") as yf:
+ data = yaml.safe_load(yf)
+
+ # Validate the data
+ try:
+ validate(instance=data, schema=schema)
+ print(f"Validation of '{yaml_file}' against '{schema_file}' successful.")
+ except jsonschema.exceptions.ValidationError as err:
+ print(
+ f"Validation error in '{yaml_file}' against '{schema_file}': {err.message}"
+ )
+ sys.exit(1)
+
+
+# Handle multiple file pairs if provided
+if args.file_pairs:
+ for pair in args.file_pairs:
+ schema_file, yaml_file = pair.split(":")
+ validate_pair(schema_file, yaml_file)
+else:
+ print(
+ "Error: Please provide either --schema_file and --yaml_file for a single validation, or --file_pairs for multiple validations."
+ )
sys.exit(1)