TopQuadrant / shacl

SHACL API in Java based on Apache Jena
Apache License 2.0
217 stars 61 forks source link

shacl conversion: malformed lists #92

Closed VladimirAlexiev closed 9 months ago

VladimirAlexiev commented 4 years ago

Hi @HolgerKnublauch !

@yasengmarinov has written a command-line convertor (that we plan to release shortly)

  private void compactToNormal() throws IOException {
    SHACLCReader shaclcReader = new SHACLCReader();
    StringWriter writer = new StringWriter();
    OutputStream os = new WriterOutputStream(writer, Charset.defaultCharset());
    shaclcReader.read(
        readFile(inputFile), BASE, TURTLE, StreamRDFWriter.getWriterStream(os, TURTLE), null);
    Model model = ModelFactory.createDefaultModel();
    model.read(new StringReader(writer.toString()), BASE, "TTL");
    RDFDataMgr.write(getOutputStream(), model, RDFFormat.TURTLE_PRETTY);
  }

  private void normalToCompact() throws IOException {
    SHACLCWriter shaclcWriter = new SHACLCWriter();
    shaclcWriter.write(
        getOutputStream(), RDFDataMgr.loadGraph(inputFile, TURTLE), new PrefixMapStd(), BASE, null);
  }

I'm trying it on https://github.com/w3c/data-shapes/blob/gh-pages/shacl-compact-syntax/tests/valid/complex1.shaclc and we get different results.

Yours:

            sh:property [
                sh:path ex:postalCode ;
                sh:or ( [ sh:datatype xsd:integer ] [ sh:datatype xsd:string ] ) ;
                sh:minCount 1 ;
                sh:maxCount 1 ;
                sh:maxLength 5 ;
            ] ;

Ours:

                                             [ sh:property  [ sh:maxCount  1 ;
                                                              sh:minCount  1 ;
                                                              sh:path      ex:postalCode
                                                            ] ;
 ...  ...  ...
[ rdf:first _:b0 ; rdf:rest ( [ sh:datatype  xsd:string ]
                            ) ] .
_:b1    rdf:first  _:b0 ;
        rdf:rest   _:b2 .

Are we making some mistake? Given #91 and comparing to the tests above, it seems there is some regression in the latest version 1.3.2 ?

HolgerKnublauch commented 4 years ago

I could not reproduce a problem with that file and still get the same output as in the test case. I also don't recognize recent changes to our code base or the SHACLC parser code base online. The example you pasted is incomplete, unfortunately, e.g. I wonder what happened to the sh:maxLength triple.

It's an open source project, so my suggestion is you try walk through the code with a debugger, e.g. breakpointing at SHACLCReader.parsePropertyOr to see where it produces what looks like detached bnodes.

VladimirAlexiev commented 4 years ago

@HolgerKnublauch thanks for the input! Can you point to the code you use to do the conversion?

The example you pasted is incomplete, unfortunately, e.g. I wonder what happened to the sh:maxLength triple

Yes, it's missing, and sh:datatype xsd:integer is missing, the sh:or is missing and its list is disconnected.

Here's another symptom: this SHACLC

PREFIX : <http://example.org/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

shapeClass :Project {
  :hasEvent @:ProjectOpenEvent [1..1].
}

shapeClass :ProjectOpenEvent {
  :hasDate xsd:date [1..1].
}

produces this SHACL where the second shape is missing:

:ProjectOpenEvent  a   rdfs:Class , sh:NodeShape ;
        sh:property  []  .

:Project  a            rdfs:Class , sh:NodeShape ;
        sh:property  [ sh:maxCount  1 ;
                       sh:minCount  1 ;
                       sh:node      :ProjectOpenEvent ;
                       sh:path      :hasEvent
                     ] .

@yasengmarinov can you spend some time to debug this?

HolgerKnublauch commented 9 months ago

Closing old issue