diff --git a/semantic-model/shacl2flink/lib/shacl_properties_to_sql.py b/semantic-model/shacl2flink/lib/shacl_properties_to_sql.py index be7c7649..eafe7cc1 100644 --- a/semantic-model/shacl2flink/lib/shacl_properties_to_sql.py +++ b/semantic-model/shacl2flink/lib/shacl_properties_to_sql.py @@ -1,6 +1,8 @@ from rdflib import Graph, Namespace import os import sys +import csv +from io import StringIO import ruamel.yaml from jinja2 import Template @@ -52,6 +54,7 @@ SELECT ?nodeshape ?targetclass ?propertypath ?mincount ?maxcount ?attributeclass ?nodekind ?minexclusive ?maxexclusive ?mininclusive ?maxinclusive ?minlength ?maxlength ?pattern ?severitycode + (GROUP_CONCAT(CONCAT('"',?in, '"'); separator=',') as ?ins) where { ?nodeshape a sh:NodeShape . ?nodeshape sh:targetClass ?targetclass . @@ -72,9 +75,12 @@ OPTIONAL { ?nodeshape sh:property [ sh:path ?propertypath ; sh:property [sh:path ngsild:hasValue ; sh:minLength ?minlength ;] ; ] } OPTIONAL { ?nodeshape sh:property [ sh:path ?propertypath ; sh:property [sh:path ngsild:hasValue ; sh:maxLength ?maxlength ;] ; ] } OPTIONAL { ?nodeshape sh:property [ sh:path ?propertypath ; sh:property [sh:path ngsild:hasValue ; sh:pattern ?pattern ;] ; ] } + OPTIONAL { ?nodeshape sh:property [ sh:path ?propertypath ; sh:property [sh:path ngsild:hasValue ; sh:in/(rdf:rest*/rdf:first)+ ?in ;] ; ] } OPTIONAL { ?nodeshape sh:property [ sh:path ?propertypath ; sh:property [sh:path ngsild:hasValue ; sh:class ?attributeclass ;] ; ] } OPTIONAL { ?nodeshape sh:property [ sh:path ?propertypath; sh:severity ?severity ; ] . ?severity iff:severityCode ?severitycode .} } +GROUP BY ?nodeshape ?targetclass ?propertypath ?mincount ?maxcount ?attributeclass ?nodekind + ?minexclusive ?maxexclusive ?mininclusive ?maxinclusive ?minlength ?maxlength ?pattern ?severitycode order by ?targetclass """ # noqa: E501 @@ -325,6 +331,28 @@ FROM A1 """ # noqa: E501 +sql_check_literal_in = """ +SELECT this AS resource, + '{{constraintname}}({{property_path}}[' || CAST( `index` AS STRING) || '])' AS event, + 'Development' AS environment, + {%- if sqlite -%} + '[SHACL Validator]' AS service, + {%- else %} + ARRAY ['SHACL Validator'] AS service, + {%- endif %} + CASE WHEN typ IS NOT NULL AND attr_typ IS NOT NULL AND val NOT IN ({% for elem in ins %}'{{ elem }}'{{ ", " if not loop.last else "" }}{% endfor %}) + THEN '{{severity}}' + ELSE 'ok' END AS severity, + 'customer' customer, + CASE WHEN typ IS NOT NULL AND attr_typ IS NOT NULL AND val NOT IN ({% for elem in ins %}'{{ elem }}'{{ ", " if not loop.last else "" }}{% endfor %}) + THEN 'Model validation for Property {{property_path}} failed for ' || this || '. Value ' || IFNULL(val, 'NULL') || ' is not allowed.' + ELSE 'All ok' END as `text` + {% if sqlite %} + ,CURRENT_TIMESTAMP + {% endif %} +FROM A1 +""" # noqa: E501 + def translate(shaclefile, knowledgefile): """ @@ -484,6 +512,11 @@ def translate(shaclefile, knowledgefile): max_length = row.maxlength.toPython() if row.maxlength is not None \ else None pattern = row.pattern.toPython() if row.pattern is not None else None + ins = row.ins.toPython() if row.ins is not None else None + if ins is not None and ins != '': + reader = csv.reader(StringIO(ins)) + parsed_list = next(reader) + ins = [element.replace("'", "\\'") for element in parsed_list] if (nodekind == sh.IRI): sql_command_yaml = Template(sql_check_property_iri_base).render( alerts_bulk_table=alerts_bulk_table, @@ -539,7 +572,6 @@ def translate(shaclefile, knowledgefile): property_class=property_class, severity=severitycode, sqlite=True) - elif (nodekind == sh.Literal): sql_command_yaml = Template(sql_check_property_iri_base).render( alerts_bulk_table=alerts_bulk_table, @@ -598,6 +630,29 @@ def translate(shaclefile, knowledgefile): severity=severitycode, minmaxname="MinExclusive", sqlite=True) + if ins is not None and len(ins) != 0: + sql_command_yaml += "\nUNION ALL" + sql_command_sqlite += "\nUNION ALL" + sql_command_yaml += \ + Template(sql_check_literal_in).render( + alerts_bulk_table=alerts_bulk_table, + target_class=target_class, + property_path=property_path, + property_class=property_class, + severity=severitycode, + sqlite=False, + constraintname="InConstraintComponent", + ins=ins) + sql_command_sqlite += \ + Template(sql_check_literal_in).render( + alerts_bulk_table=alerts_bulk_table, + target_class=target_class, + property_path=property_path, + property_class=property_class, + severity=severitycode, + sqlite=True, + constraintname="InConstraintComponent", + ins=ins) if max_exclusive is not None: sql_command_yaml += "\nUNION ALL" sql_command_sqlite += "\nUNION ALL" diff --git a/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model1.jsonld_result b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model1.jsonld_result index f8ff2e3a..802f0b95 100644 --- a/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model1.jsonld_result +++ b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model1.jsonld_result @@ -3,7 +3,10 @@ 'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter)','warning' 'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece)','ok' 'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/state)','ok' +'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/stringState)','ok' 'urn:plasmacutter:1','DatatypeConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','warning' +'urn:plasmacutter:1','InConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter)','ok' 'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece)','ok' 'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' diff --git a/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model10.jsonld b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model10.jsonld new file mode 100644 index 00000000..f9205e58 --- /dev/null +++ b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model10.jsonld @@ -0,0 +1,48 @@ +[ + { + "@context": "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld", + "id": "urn:plasmacutter:1", + "type": "https://industry-fusion.com/types/v0.9/plasmacutter", + "https://industry-fusion.com/types/v0.9/state": { + "type": "Property", + "value": { + "@id": "https://industry-fusion.com/types/v0.9/state_OFF" + } + }, + "https://industry-fusion.com/types/v0.9/stringState": { + "type": "Property", + "value": "T\"ST" + }, + "https://industry-fusion.com/types/v0.9/hasWorkpiece": { + "type": "Relationship", + "https://uri.etsi.org/ngsi-ld/hasObject": "urn:workpiece:1" + }, + "https://industry-fusion.com/types/v0.9/hasFilter": { + "type": "Relationship", + "object": "urn:filter:1" + } + }, + { + "@context": "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld", + "id": "urn:filter:1", + "type": "https://industry-fusion.com/types/v0.9/filter", + "https://industry-fusion.com/types/v0.9/state": { + "type": "Property", + "value": { + "@id": "https://industry-fusion.com/types/v0.9/state_PREPARING" + } + }, + "https://industry-fusion.com/types/v0.9/stringState": { + "type": "Property", + "value": "t1,t2" + }, + "https://industry-fusion.com/types/v0.9/strength": { + "type": "Property", + "value": 0.5 + }, + "https://industry-fusion.com/types/v0.9/hasCartridge": { + "type": "Relationship", + "https://uri.etsi.org/ngsi-ld/hasObject": "urn:filterCartridge:1" + } + } +] \ No newline at end of file diff --git a/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model10.jsonld_result b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model10.jsonld_result new file mode 100644 index 00000000..cb488abb --- /dev/null +++ b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model10.jsonld_result @@ -0,0 +1,24 @@ +'urn:filter:1','ClassConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge[0])','warning' +'urn:filter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge)','ok' +'urn:filter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/state)','ok' +'urn:filter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/stringState)','ok' +'urn:filter:1','DatatypeConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:filter:1','InConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' +'urn:filter:1','MaxInclusiveConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' +'urn:filter:1','MinInclusiveConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' +'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge)','warning' +'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' +'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' +'urn:plasmacutter:1','ClassConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter[0])','ok' +'urn:plasmacutter:1','ClassConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece[0])','warning' +'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter)','ok' +'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece)','ok' +'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/state)','ok' +'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/stringState)','ok' +'urn:plasmacutter:1','DatatypeConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:plasmacutter:1','InConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','warning' +'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter)','ok' +'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece)','warning' +'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' diff --git a/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model2.jsonld_result b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model2.jsonld_result index 8e4b96e4..3ffdd005 100644 --- a/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model2.jsonld_result +++ b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model2.jsonld_result @@ -3,7 +3,10 @@ 'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter)','ok' 'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece)','ok' 'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/state)','ok' +'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/stringState)','ok' 'urn:plasmacutter:1','DatatypeConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:plasmacutter:1','InConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter)','ok' 'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece)','ok' 'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' diff --git a/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model3.jsonld_result b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model3.jsonld_result index 273ae062..46212c92 100644 --- a/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model3.jsonld_result +++ b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model3.jsonld_result @@ -1,18 +1,24 @@ 'urn:filter:1','ClassConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge[0])','warning' 'urn:filter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge)','ok' 'urn:filter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/state)','ok' +'urn:filter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/stringState)','ok' 'urn:filter:1','DatatypeConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:filter:1','InConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:filter:1','MaxInclusiveConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' 'urn:filter:1','MinInclusiveConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' 'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge)','ok' 'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' 'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' +'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:plasmacutter:1','ClassConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter[0])','ok' 'urn:plasmacutter:1','ClassConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece[0])','warning' 'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter)','ok' 'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece)','ok' 'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/state)','ok' +'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/stringState)','ok' 'urn:plasmacutter:1','DatatypeConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:plasmacutter:1','InConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter)','ok' 'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece)','ok' 'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' diff --git a/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model4.jsonld_result b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model4.jsonld_result index 20226e42..95e59e5b 100644 --- a/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model4.jsonld_result +++ b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model4.jsonld_result @@ -1,21 +1,27 @@ 'urn:filter:1','ClassConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge[0])','warning' 'urn:filter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge)','ok' 'urn:filter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/state)','ok' +'urn:filter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/stringState)','ok' 'urn:filter:1','DatatypeConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:filter:1','InConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:filter:1','MaxInclusiveConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' 'urn:filter:1','MinInclusiveConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' 'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge)','ok' 'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' 'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' +'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:plasmacutter:1','ClassConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter[0])','ok' 'urn:plasmacutter:1','ClassConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece[0])','ok' 'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter)','ok' 'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece)','ok' 'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/state)','ok' +'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/stringState)','ok' 'urn:plasmacutter:1','DatatypeConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:plasmacutter:1','InConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter)','ok' 'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece)','ok' 'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:workpiece:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/material)','ok' 'urn:workpiece:1','CountConstraintComponent(https://schema.org/depth)','ok' 'urn:workpiece:1','MaxInclusiveConstraintComponent(https://schema.org/depth[0])','ok' diff --git a/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model5.jsonld_result b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model5.jsonld_result index eea04484..bf375d6f 100644 --- a/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model5.jsonld_result +++ b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model5.jsonld_result @@ -1,12 +1,15 @@ 'urn:filter:1','ClassConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge[0])','ok' 'urn:filter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge)','ok' 'urn:filter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/state)','ok' +'urn:filter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/stringState)','ok' 'urn:filter:1','DatatypeConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:filter:1','InConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:filter:1','MaxInclusiveConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' 'urn:filter:1','MinInclusiveConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' 'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge)','ok' 'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' 'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' +'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:filterCartridge:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/inUseFrom)','ok' 'urn:filterCartridge:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/inUseUntil)','ok' 'urn:filterCartridge:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/wasteClass)','ok' @@ -19,10 +22,13 @@ 'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter)','ok' 'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece)','ok' 'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/state)','ok' +'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/stringState)','ok' 'urn:plasmacutter:1','DatatypeConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:plasmacutter:1','InConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter)','ok' 'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece)','ok' 'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:workpiece:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/material)','ok' 'urn:workpiece:1','CountConstraintComponent(https://schema.org/depth)','ok' 'urn:workpiece:1','MaxInclusiveConstraintComponent(https://schema.org/depth[0])','warning' diff --git a/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model6.jsonld_result b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model6.jsonld_result index f8bac4a0..09422f80 100644 --- a/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model6.jsonld_result +++ b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model6.jsonld_result @@ -1,12 +1,15 @@ 'urn:filter:1','ClassConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge[0])','ok' 'urn:filter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge)','ok' 'urn:filter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/state)','ok' +'urn:filter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/stringState)','ok' 'urn:filter:1','DatatypeConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:filter:1','InConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:filter:1','MaxInclusiveConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' 'urn:filter:1','MinInclusiveConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' 'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge)','ok' 'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' 'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' +'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:filterCartridge:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/inUseFrom)','ok' 'urn:filterCartridge:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/inUseUntil)','ok' 'urn:filterCartridge:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/wasteClass)','ok' @@ -19,10 +22,13 @@ 'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter)','ok' 'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece)','ok' 'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/state)','ok' +'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/stringState)','ok' 'urn:plasmacutter:1','DatatypeConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:plasmacutter:1','InConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter)','ok' 'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece)','ok' 'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:workpiece:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/material)','ok' 'urn:workpiece:1','CountConstraintComponent(https://schema.org/depth)','ok' 'urn:workpiece:1','MaxInclusiveConstraintComponent(https://schema.org/depth[0])','warning' diff --git a/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model7.jsonld_result b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model7.jsonld_result index 6eba3fe0..d0e86e4f 100644 --- a/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model7.jsonld_result +++ b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model7.jsonld_result @@ -1,21 +1,27 @@ 'urn:filter:1','ClassConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge[0])','ok' 'urn:filter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge)','ok' 'urn:filter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/state)','ok' +'urn:filter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/stringState)','ok' 'urn:filter:1','DatatypeConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:filter:1','InConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:filter:1','MaxInclusiveConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' 'urn:filter:1','MinInclusiveConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' 'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge)','ok' 'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' 'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' +'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:filter:2','ClassConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge[0])','warning' 'urn:filter:2','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge)','ok' 'urn:filter:2','CountConstraintComponent(https://industry-fusion.com/types/v0.9/state)','ok' +'urn:filter:2','CountConstraintComponent(https://industry-fusion.com/types/v0.9/stringState)','ok' 'urn:filter:2','DatatypeConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:filter:2','InConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:filter:2','MaxInclusiveConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' 'urn:filter:2','MinInclusiveConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' 'urn:filter:2','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge)','ok' 'urn:filter:2','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' 'urn:filter:2','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' +'urn:filter:2','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:filterCartridge:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/inUseFrom)','ok' 'urn:filterCartridge:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/inUseUntil)','ok' 'urn:filterCartridge:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/wasteClass)','ok' @@ -28,19 +34,25 @@ 'urn:lasercutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter)','ok' 'urn:lasercutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece)','ok' 'urn:lasercutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/state)','ok' +'urn:lasercutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/stringState)','ok' 'urn:lasercutter:1','DatatypeConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:lasercutter:1','InConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:lasercutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter)','ok' 'urn:lasercutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece)','ok' 'urn:lasercutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:lasercutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:plasmacutter:1','ClassConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter[0])','ok' 'urn:plasmacutter:1','ClassConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece[0])','ok' 'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter)','ok' 'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece)','ok' 'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/state)','ok' +'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/stringState)','ok' 'urn:plasmacutter:1','DatatypeConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:plasmacutter:1','InConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter)','ok' 'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece)','ok' 'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:workpiece:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/material)','ok' 'urn:workpiece:1','CountConstraintComponent(https://schema.org/depth)','ok' 'urn:workpiece:1','MaxInclusiveConstraintComponent(https://schema.org/depth[0])','warning' diff --git a/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model8.jsonld_result b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model8.jsonld_result index dbd73ad9..db7692b3 100644 --- a/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model8.jsonld_result +++ b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model8.jsonld_result @@ -1,18 +1,24 @@ 'urn:filter:1','ClassConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge[0])','warning' 'urn:filter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge)','ok' 'urn:filter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/state)','ok' +'urn:filter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/stringState)','ok' 'urn:filter:1','DatatypeConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:filter:1','InConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:filter:1','MaxInclusiveConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' 'urn:filter:1','MinInclusiveConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' 'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge)','warning' 'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' 'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' +'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:plasmacutter:1','ClassConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter[0])','ok' 'urn:plasmacutter:1','ClassConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece[0])','warning' 'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter)','ok' 'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece)','ok' 'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/state)','ok' +'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/stringState)','ok' 'urn:plasmacutter:1','DatatypeConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:plasmacutter:1','InConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' 'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter)','ok' 'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece)','warning' 'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' diff --git a/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model9.jsonld b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model9.jsonld new file mode 100644 index 00000000..90fc4a61 --- /dev/null +++ b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model9.jsonld @@ -0,0 +1,48 @@ +[ + { + "@context": "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld", + "id": "urn:plasmacutter:1", + "type": "https://industry-fusion.com/types/v0.9/plasmacutter", + "https://industry-fusion.com/types/v0.9/state": { + "type": "Property", + "value": { + "@id": "https://industry-fusion.com/types/v0.9/state_OFF" + } + }, + "https://industry-fusion.com/types/v0.9/stringState": { + "type": "Property", + "value": "OFF" + }, + "https://industry-fusion.com/types/v0.9/hasWorkpiece": { + "type": "Relationship", + "https://uri.etsi.org/ngsi-ld/hasObject": "urn:workpiece:1" + }, + "https://industry-fusion.com/types/v0.9/hasFilter": { + "type": "Relationship", + "object": "urn:filter:1" + } + }, + { + "@context": "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld", + "id": "urn:filter:1", + "type": "https://industry-fusion.com/types/v0.9/filter", + "https://industry-fusion.com/types/v0.9/state": { + "type": "Property", + "value": { + "@id": "https://industry-fusion.com/types/v0.9/state_PREPARING" + } + }, + "https://industry-fusion.com/types/v0.9/stringState": { + "type": "Property", + "value": "ON" + }, + "https://industry-fusion.com/types/v0.9/strength": { + "type": "Property", + "value": 0.5 + }, + "https://industry-fusion.com/types/v0.9/hasCartridge": { + "type": "Relationship", + "https://uri.etsi.org/ngsi-ld/hasObject": "urn:filterCartridge:1" + } + } +] \ No newline at end of file diff --git a/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model9.jsonld_result b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model9.jsonld_result new file mode 100644 index 00000000..db7692b3 --- /dev/null +++ b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/model9.jsonld_result @@ -0,0 +1,24 @@ +'urn:filter:1','ClassConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge[0])','warning' +'urn:filter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge)','ok' +'urn:filter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/state)','ok' +'urn:filter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/stringState)','ok' +'urn:filter:1','DatatypeConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:filter:1','InConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' +'urn:filter:1','MaxInclusiveConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' +'urn:filter:1','MinInclusiveConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' +'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasCartridge)','warning' +'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/strength[0])','ok' +'urn:filter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' +'urn:plasmacutter:1','ClassConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter[0])','ok' +'urn:plasmacutter:1','ClassConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece[0])','warning' +'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter)','ok' +'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece)','ok' +'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/state)','ok' +'urn:plasmacutter:1','CountConstraintComponent(https://industry-fusion.com/types/v0.9/stringState)','ok' +'urn:plasmacutter:1','DatatypeConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:plasmacutter:1','InConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' +'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasFilter)','ok' +'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/hasWorkpiece)','warning' +'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/state[0])','ok' +'urn:plasmacutter:1','NodeKindConstraintComponent(https://industry-fusion.com/types/v0.9/stringState[0])','ok' diff --git a/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/shacl.ttl b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/shacl.ttl index 195fd93c..8873de65 100644 --- a/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/shacl.ttl +++ b/semantic-model/shacl2flink/tests/sql-tests/kms-constraints/test1/shacl.ttl @@ -30,6 +30,25 @@ iff:MachineShape sh:minCount 1 ; ] ; ] ; + sh:property [ + sh:path ; + sh:order 2 ; + sh:nodeKind sh:BlankNode; + sh:minCount 0 ; + sh:maxCount 1 ; + sh:property [ + sh:path ; + sh:nodeKind sh:Literal; + sh:in ("ON" "OFF" "t1,t2"); + sh:minCount 1 ; + sh:maxCount 1 ; + ] ; + sh:property [ + sh:path rdf:type ; + sh:hasValue ; + sh:minCount 1 ; + ] ; + ] ; . diff --git a/semantic-model/shacl2flink/tests/test_lib_shacl_properties_to_sql.py b/semantic-model/shacl2flink/tests/test_lib_shacl_properties_to_sql.py index 53aa4c7e..67b33f21 100644 --- a/semantic-model/shacl2flink/tests/test_lib_shacl_properties_to_sql.py +++ b/semantic-model/shacl2flink/tests/test_lib_shacl_properties_to_sql.py @@ -64,6 +64,8 @@ def identity(klass): maxlength.toPython.return_value = None pattern = MagicMock() pattern.toPython.return_value = 'pattern' + ins = MagicMock() + ins.toPython.return_value = '"SHIN1","SHIN2"' g.__iadd__.return_value.query.return_value = [Bunch()] g.__iadd__.return_value.query.return_value[0].targetclass = targetclass g.__iadd__.return_value.query.return_value[0].propertypath = propertypath @@ -81,6 +83,7 @@ def identity(klass): g.__iadd__.return_value.query.return_value[0].minlength = minlength g.__iadd__.return_value.query.return_value[0].maxlength = maxlength g.__iadd__.return_value.query.return_value[0].pattern = pattern + g.__iadd__.return_value.query.return_value[0].ins = ins sqlite, (statementsets, tables, views) = \ lib.shacl_properties_to_sql.translate('kms/shacl.ttl', 'kms/knowledge.ttl') @@ -91,13 +94,15 @@ def identity(klass): 'attributeclass-view'] assert len(statementsets) == 2 lower_sqlite = sqlite.lower() - assert lower_sqlite.count('select') == 12 + assert lower_sqlite.count('select') == 13 assert lower_sqlite.count(' < 4') == 4 assert lower_sqlite.count(' < 3') == 3 assert lower_sqlite.count(' <= 2') == 3 assert lower_sqlite.count(' > 0') == 3 assert lower_sqlite.count(' >= 1') == 3 assert lower_sqlite.count("regexp 'pattern'") == 2 + assert lower_sqlite.count("('shin1', 'shin2')") == 2 + assert lower_sqlite.count("inconstraintcomponent") == 1 targetclass = MagicMock() targetclass.toPython.return_value = 'targetclass' @@ -143,6 +148,7 @@ def identity(klass): g.__iadd__.return_value.query.return_value[0].minlength = minlength g.__iadd__.return_value.query.return_value[0].maxlength = maxlength g.__iadd__.return_value.query.return_value[0].pattern = None + g.__iadd__.return_value.query.return_value[0].ins = None sqlite, (statementsets, tables, views) = \ lib.shacl_properties_to_sql.translate('kms/shacl.ttl', 'kms/knowledge.ttl')