danaivach / hmas-java

A library for handling resources in Hypermedia Multi-Agent Systems based on the HyperAgents ontologies.
1 stars 2 forks source link

Define `ListSpecification` for SHACL shapes of `rdf:List` individuals #12

Closed danaivach closed 1 month ago

danaivach commented 2 months ago

Using QualifiedValueSpecification for specifying SHACL shapes of rdf:List individuals is hard to use and error-prone, considering the frequency in which such shapes are used.

Example definition with the current version:

    IntegerSpecification memberSpec = new IntegerSpecification.Builder()
            .addSemanticType("http://example.org/ExampleFirstSpecification")
            .setRequired(true)
            .build();

    ValueSpecification nilSpec = new ValueSpecification.Builder()
            .addSemanticType("http://example.org/ExampleRestSpecification")
            .setValueAsString("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil")
            .setRequired(true)
            .build();

    QualifiedValueSpecification listSpecLast = new QualifiedValueSpecification.Builder()
            .setIRIAsString("http://example.org/restListShape")
            .addSemanticType("http://example.org/ExampleListSpecification")
            .addRequiredSemanticType("http://www.w3.org/1999/02/22-rdf-syntax-ns#List")
            .addRequiredSemanticType("https://saref.etsi.org/core/State")
            .setRequired(true)
            .addPropertySpecification("http://www.w3.org/1999/02/22-rdf-syntax-ns#first", memberSpec)
            .addPropertySpecification("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest", nilSpec)
            .build();

    QualifiedValueSpecification listSpec =  new QualifiedValueSpecification.Builder()
            .setIRIAsString("http://example.org/listShape")
            .addSemanticType("http://example.org/ExampleListSpecification")
            .addRequiredSemanticType("http://www.w3.org/1999/02/22-rdf-syntax-ns#List")
            .addRequiredSemanticType("https://saref.etsi.org/core/State")
            .setRequired(true)
            .addPropertySpecification("http://www.w3.org/1999/02/22-rdf-syntax-ns#first", memberSpec)
            .addPropertySpecification("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest", listSpecLast)
            .build();

Example produced SHACL shape with the current version:

ex:listShape a sh:Shape, ex:ExampleListSpecification;
  sh:class saref:State, rdf:List;
  sh:property [
      sh:qualifiedValueShape ex:restListShape;
      sh:qualifiedMinCount "1"^^xs:int;
      sh:qualifiedMaxCount "1"^^xs:int;
      sh:path rdf:rest
    ], [ a sh:Shape, ex:ExampleFirstSpecification;
      sh:datatype xs:int;
      sh:minCount "1"^^xs:int;
      sh:maxCount "1"^^xs:int;
      sh:path rdf:first
    ] .

ex:restListShape a sh:Shape, ex:ExampleListSpecification;
  sh:class saref:State, rdf:List;
  sh:property [ a sh:Shape, ex:ExampleRestSpecification;
      sh:hasValue rdf:nil;
      sh:datatype xs:anyURI;
      sh:minCount "1"^^xs:int;
      sh:maxCount "1"^^xs:int;
      sh:path rdf:rest
    ], [ a sh:Shape, ex:ExampleFirstSpecification;
      sh:datatype xs:int;
      sh:minCount "1"^^xs:int;
      sh:maxCount "1"^^xs:int;
      sh:path rdf:first
    ] .
danaivach commented 1 month ago

Closed by https://github.com/danaivach/hmas-interaction/pull/11