diff --git a/tetras_extraction/macao_12/script/.vscode/extensions.json b/tetras_extraction/macao_12/script/.vscode/extensions.json index 85395aa10fee6f7c7313f1c191c5946cad24782b..54a06eae544fcbe6616acb1546e6a7dc947d3fd3 100644 --- a/tetras_extraction/macao_12/script/.vscode/extensions.json +++ b/tetras_extraction/macao_12/script/.vscode/extensions.json @@ -2,6 +2,7 @@ "recommendations": [ "detachhead.basedpyright", "ms-python.black-formatter", - "ms-python.isort" + "ms-python.isort", + "gruntfuggly.todo-tree" ] } \ No newline at end of file diff --git a/tetras_extraction/macao_12/script/templates/debug.rq b/tetras_extraction/macao_12/script/templates/debug.rq new file mode 100644 index 0000000000000000000000000000000000000000..761f04ae3413f545aa957633b8a1ee5f7aec9080 --- /dev/null +++ b/tetras_extraction/macao_12/script/templates/debug.rq @@ -0,0 +1,10 @@ +PREFIX : <http://www.semanticweb.org/eliott/ontologies/2024/4/macao/> +PREFIX mt: <http://www.semanticweb.org/eliott/ontologies/2024/4/macao/template/> + +template mt:debug(?subj) { + group { ?type " " } +} +where { + ?subj a ?type + FILTER(STRSTARTS(?type, :)) +} \ No newline at end of file diff --git a/tetras_extraction/macao_12/script/templates/functions.rq b/tetras_extraction/macao_12/script/templates/functions.rq index ca58bcbcdb6ba15c9b9091070fd5346cdab29b4c..c9bb946d215eeb738512fbe4db7e437954f0473d 100644 --- a/tetras_extraction/macao_12/script/templates/functions.rq +++ b/tetras_extraction/macao_12/script/templates/functions.rq @@ -2,14 +2,28 @@ PREFIX : <http://www.semanticweb.org/eliott/ontologies/2024/4/macao/> PREFIX mt: <http://www.semanticweb.org/eliott/ontologies/2024/4/macao/template/> PREFIX st: <http://ns.inria.fr/sparql-template/> +# The global empty template used to define functions. template st:profile {} where {} +# This special function is called for every node (blank, URI, literal) +# used in any template. function st:process(?x) { - # Format literals as text without quotes - if (isLiteral(?x), st:format("%s", ?x), st:turtle(?x)) + # Format literals as text without quotes, and strip Macao prefix + # from URIs + # FIXME: literals are also trimmed in length for debug readability + if (isLiteral(?x), + # st:format("%s", ?x), + substr(?x, 0 , 40), + if (isURI(?x), + replace(?x, :, ":"), + st:turtle(?x) + ) + ) } +# JSON lines often end with a comma, and st:nl() is a newline +# with the current indent level (see the docs). function mt:sep() { st:format(",%s", st:nl()) } \ No newline at end of file diff --git a/tetras_extraction/macao_12/script/templates/main.rq b/tetras_extraction/macao_12/script/templates/main.rq deleted file mode 100644 index 856f4f46bf302cabf8acfc5158f11db12a8eeb4c..0000000000000000000000000000000000000000 --- a/tetras_extraction/macao_12/script/templates/main.rq +++ /dev/null @@ -1,16 +0,0 @@ -PREFIX : <http://www.semanticweb.org/eliott/ontologies/2024/4/macao/> -PREFIX mt: <http://www.semanticweb.org/eliott/ontologies/2024/4/macao/template/> -PREFIX st: <http://ns.inria.fr/sparql-template/> -PREFIX owl: <http://www.w3.org/2002/07/owl#> - -template { - ?id " -> " ?title -} -where { - ?subj a :ExerciceQC_QCU . - ?subj :id ?id - optional { - ?subj :titre ?title . - } -} - diff --git a/tetras_extraction/macao_12/script/templates/page.rq b/tetras_extraction/macao_12/script/templates/page.rq index bc6b037f81921874b8f4ad0b77fa638e88c51d02..dea8625455769311e2c1f0afbee19b563f8af354 100644 --- a/tetras_extraction/macao_12/script/templates/page.rq +++ b/tetras_extraction/macao_12/script/templates/page.rq @@ -3,9 +3,13 @@ PREFIX mt: <http://www.semanticweb.org/eliott/ontologies/2024/4/macao/template/> PREFIX st: <http://ns.inria.fr/sparql-template/> PREFIX owl: <http://www.w3.org/2002/07/owl#> +# Entry point of the template set. +# Generic Activity template that creates a Markdown page with Hugo front-matter, +# and calls other specific templates when necessary template { - "####### " - ?id + "####### " ?id + #FIXME: debug activity type + st:nl() st:call-template(mt:debug, ?subj) format { """ +++ diff --git a/tetras_extraction/macao_12/script/templates/qcu.rq b/tetras_extraction/macao_12/script/templates/qcu.rq index bb9aebd41fa25ec30490c88284ce5959b3345a0e..9c4eacf04db3905a69cb12d5cf461408cd900a63 100644 --- a/tetras_extraction/macao_12/script/templates/qcu.rq +++ b/tetras_extraction/macao_12/script/templates/qcu.rq @@ -2,29 +2,34 @@ PREFIX : <http://www.semanticweb.org/eliott/ontologies/2024/4/macao/> PREFIX mt: <http://www.semanticweb.org/eliott/ontologies/2024/4/macao/template/> PREFIX st: <http://ns.inria.fr/sparql-template/> +# Template for the JSON definition of QCU activities template mt:qcu(?qcu) { '"name": "' ?id '"' mt:sep() '"type": "radiogroup"' mt:sep() '"choices": [' - # box { st:call-template(mt:qcu_choices, ?qcu) } box { + # The body of the group block is instantiated for each match of + # its variables (here, one match for each choice of the QCU), + # while the rest of the template is only instantiated once. + # This is similar to a SQL 'GROUP BY every variable except these' group { - '"' ?html '"' + '"' ?choice_html '"' ; separator=mt:sep() } } ']' mt:sep() - '"correctAnswer": "' ?correct_choice '"' + '"correctAnswer": "' ?correct_choice_html '"' } where { - # ?qcu a :ExerciceQC_QCU + ?qcu a :ExerciceQC_QCU ?qcu :id ?id . optional { - ?qcu :aReponse ?cchoice . - ?cchoice :correct true - ?cchoice :text ?correct_choice . - ?qcu :aReponse ?choice . - ?choice :text ?html + ?choice :html ?choice_html + } + optional { + ?qcu :aReponse ?correct_choice . + ?correct_choice :correct true . + ?correct_choice :html ?correct_choice_html . } } diff --git a/tetras_extraction/macao_12/script/templates/qcu_choices.rq b/tetras_extraction/macao_12/script/templates/qcu_choices.rq deleted file mode 100644 index 7d2ac2d1b48ed0ee340f71f2c3a36a3a563683ac..0000000000000000000000000000000000000000 --- a/tetras_extraction/macao_12/script/templates/qcu_choices.rq +++ /dev/null @@ -1,14 +0,0 @@ -PREFIX : <http://www.semanticweb.org/eliott/ontologies/2024/4/macao/> -PREFIX mt: <http://www.semanticweb.org/eliott/ontologies/2024/4/macao/template/> -PREFIX st: <http://ns.inria.fr/sparql-template/> - -template mt:qcu_choices(?qcu) { - group { - '"' ?html '"' - ; separator=mt:sep() - } -} -where { - ?qcu :aReponse ?choice . - ?choice :text ?html -}