blake-regalia / graphy.js

A collection of RDF libraries for JavaScript
https://graphy.link/
ISC License
161 stars 3 forks source link

Error: A relative or prefixed node must include a ':' character. #54

Closed tpluscode closed 2 years ago

tpluscode commented 2 years ago

I'm seeing an error when trying to pretty-serialise the graph below using c4 terms in turtle. I cannot exactly place it but the problem is somewhere with the RDF List at the end

I think that the triples are correct, coming from a SHACL engine. Can you

_:report <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/shacl#ValidationReport> .
_:report <http://www.w3.org/ns/shacl#result> _:b81775 .
_:report <http://www.w3.org/ns/shacl#conforms> "false"^^<http://www.w3.org/2001/XMLSchema#boolean> .
_:b81775 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/shacl#ValidationResult> .
_:b81775 <http://www.w3.org/ns/shacl#resultSeverity> <http://www.w3.org/ns/shacl#Violation> .
_:b81775 <http://www.w3.org/ns/shacl#sourceConstraintComponent> <http://www.w3.org/ns/shacl#NodeConstraintComponent> .
_:b81775 <http://www.w3.org/ns/shacl#sourceShape> _:b77389 .
_:b81775 <http://www.w3.org/ns/shacl#focusNode> <https://jmk.lndo.site/park/buses/2020#696> .
_:b81775 <http://www.w3.org/ns/shacl#resultPath> <https://jmk.org.pl/vocab#insurance> .
_:b81775 <http://www.w3.org/ns/shacl#resultMessage> "Value does not have shape Blank node b77390" .
_:b81775 <http://www.w3.org/ns/shacl#detail> _:b81773 .
_:b81775 <http://www.w3.org/ns/shacl#detail> _:b81774 .
_:b81775 <http://www.w3.org/ns/shacl#value> _:b79599 .
_:b77389 <http://www.w3.org/ns/shacl#path> <https://jmk.org.pl/vocab#insurance> .
_:b77389 <http://www.w3.org/ns/shacl#maxCount> "1"^^<http://www.w3.org/2001/XMLSchema#integer> .
_:b77389 <http://www.w3.org/ns/shacl#minCount> "1"^^<http://www.w3.org/2001/XMLSchema#integer> .
_:b77389 <http://www.w3.org/ns/shacl#node> _:b77390 .
_:b81773 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/shacl#ValidationResult> .
_:b81773 <http://www.w3.org/ns/shacl#resultSeverity> <http://www.w3.org/ns/shacl#Violation> .
_:b81773 <http://www.w3.org/ns/shacl#sourceConstraintComponent> <http://www.w3.org/ns/shacl#HasValueConstraintComponent> .
_:b81773 <http://www.w3.org/ns/shacl#sourceShape> _:b77391 .
_:b81773 <http://www.w3.org/ns/shacl#focusNode> _:b79599 .
_:b81773 <http://www.w3.org/ns/shacl#resultPath> _:b77392 .
_:b81773 <http://www.w3.org/ns/shacl#resultMessage> "Missing expected value 2020-11-10" .
_:b81774 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/shacl#ValidationResult> .
_:b81774 <http://www.w3.org/ns/shacl#resultSeverity> <http://www.w3.org/ns/shacl#Violation> .
_:b81774 <http://www.w3.org/ns/shacl#sourceConstraintComponent> <http://www.w3.org/ns/shacl#HasValueConstraintComponent> .
_:b81774 <http://www.w3.org/ns/shacl#sourceShape> _:b77394 .
_:b81774 <http://www.w3.org/ns/shacl#focusNode> _:b79599 .
_:b81774 <http://www.w3.org/ns/shacl#resultPath> _:b77395 .
_:b81774 <http://www.w3.org/ns/shacl#resultMessage> "Missing expected value 2021-11-09" .
_:b77390 <http://www.w3.org/ns/shacl#property> _:b77391 .
_:b77390 <http://www.w3.org/ns/shacl#property> _:b77394 .
_:b77391 <http://www.w3.org/ns/shacl#path> _:b77392 .
_:b77391 <http://www.w3.org/ns/shacl#maxCount> "1"^^<http://www.w3.org/2001/XMLSchema#integer> .
_:b77391 <http://www.w3.org/ns/shacl#hasValue> "2020-11-10"^^<http://www.w3.org/2001/XMLSchema#date> .
_:b77392 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://www.w3.org/2006/time#hasBeginning> .
_:b77392 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b77393 .
_:b77394 <http://www.w3.org/ns/shacl#path> _:b77395 .
_:b77394 <http://www.w3.org/ns/shacl#maxCount> "1"^^<http://www.w3.org/2001/XMLSchema#integer> .
_:b77394 <http://www.w3.org/ns/shacl#hasValue> "2021-11-09"^^<http://www.w3.org/2001/XMLSchema#date> .
_:b77395 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://www.w3.org/2006/time#hasEnd> .
_:b77395 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b77396 .
_:b77393 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://www.w3.org/2006/time#inXSDDate> .
_:b77393 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
_:b77396 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://www.w3.org/2006/time#inXSDDate> .
_:b77396 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .

Here's the full stack

Error: A relative or prefixed node must include a ':' character. 
Invalid concise-term string for node: '0'
    at Object.c1_prefixed_node (/Volumes/Home/projects/github/data-mazes/vehicle-park-import/node_modules/@graphy/core.data.factory/main.js:1438:28)
    at Object.c1_node_explicit (/Volumes/Home/projects/github/data-mazes/vehicle-park-import/node_modules/@graphy/core.data.factory/main.js:1428:25)
    at Object.c1_named_node (/Volumes/Home/projects/github/data-mazes/vehicle-park-import/node_modules/@graphy/core.data.factory/main.js:1413:18)
    at Turtle_Writer._serialize_c3 (/Volumes/Home/projects/github/data-mazes/vehicle-park-import/node_modules/@graphy/content.ttl.write/main.js:270:32)
    at Turtle_Writer._serialize_c4 (/Volumes/Home/projects/github/data-mazes/vehicle-park-import/node_modules/@graphy/core.class.writable/main.js:244:20)
    at Turtle_Writer.serialize (/Volumes/Home/projects/github/data-mazes/vehicle-park-import/node_modules/@graphy/core.class.scribable/main.js:273:27)
    at Turtle_Writer._transform (/Volumes/Home/projects/github/data-mazes/vehicle-park-import/node_modules/@graphy/core.class.scribable/main.js:173:19)

And this is the c4 JSON I pass to the serializer

{
  "*": {
    "_:report": {
      "a": [
        "sh:ValidationReport"
      ],
      "sh:result": [
        {
          "a": [
            "sh:ValidationResult"
          ],
          "sh:resultSeverity": [
            "sh:Violation"
          ],
          "sh:sourceConstraintComponent": [
            "sh:NodeConstraintComponent"
          ],
          "sh:sourceShape": [
            {
              "sh:path": [
                "jmk:insurance"
              ],
              "sh:maxCount": [
                1
              ],
              "sh:minCount": [
                1
              ],
              "sh:node": [
                {
                  "sh:property": [
                    "_:b77400",
                    {
                      "sh:path": [
                        [
                          "time:hasBeginning",
                          "time:inXSDDate"
                        ]
                      ],
                      "sh:maxCount": [
                        1
                      ],
                      "sh:hasValue": [
                        "^xsd:date\"2020-11-10"
                      ]
                    }
                  ]
                }
              ]
            }
          ],
          "sh:focusNode": [
            ">https://jmk.lndo.site/park/buses/2020#696"
          ],
          "sh:resultPath": [
            "jmk:insurance"
          ],
          "sh:resultMessage": [
            "\"Value does not have shape Blank node b77396"
          ],
          "sh:detail": [
            {
              "a": [
                "sh:ValidationResult"
              ],
              "sh:resultSeverity": [
                "sh:Violation"
              ],
              "sh:sourceConstraintComponent": [
                "sh:HasValueConstraintComponent"
              ],
              "sh:sourceShape": [
                "_:b77400"
              ],
              "sh:focusNode": [
                "_:b78982"
              ],
              "sh:resultPath": [
                "_:b77401"
              ],
              "sh:resultMessage": [
                "\"Missing expected value 2021-11-09"
              ]
            }
          ],
          "sh:value": [
            "_:b78982"
          ]
        }
      ],
      "sh:conforms": [
        false
      ]
    },
    "_:b77400": {
      "sh:path": [
        "_:b77401"
      ],
      "sh:maxCount": [
        1
      ],
      "sh:hasValue": [
        "^xsd:date\"2021-11-09"
      ]
    },
    "_:b77401": [
      "time:hasEnd",
      "time:inXSDDate"
    ]
  }
}
blake-regalia commented 2 years ago

It looks like the struct for the last blank node does not have full triples?

{
    "_:b77401": [
      "time:hasEnd",
      "time:inXSDDate"
    ]
}

Should be something like this instead i think?

{

    "_:b77401": {
      "time:hasEnd": "^xsd:date\"2021-01-01",
      "time:inXSDDate":  "^xsd:date\"2021-11-09"
    }
}
tpluscode commented 2 years ago

Thanks for taking your time to look at this.

The _: b77401 node should in fact be a list [] :sh:resultPath ( time:hasEnd time:inXSDDate )

blake-regalia commented 2 years ago

Oh I see. Yes for collections, a nested array will do the trick:

{
  "_:b77401": {
    "sh:resultPath": [  // this array is for different objects
      [  // this array creates a collection
        "time:hasEnd",
        "inXSDDate",
      ],
    ],
}
blake-regalia commented 2 years ago

did this work?

tpluscode commented 2 years ago

Sorry, haven't had the chance to try yet. Let me do that now

tpluscode commented 2 years ago

From your advice I figured that list nodes shared by multiple subjects are the problem. When extracted to a "top-level" node, the first rdf:first/rdf:rest must be broken up. Not unlike you'd type in turtle

ex:foo ex:list _:list .
ex:bar ex:list _:list .
ex:baz ex:list _:list .

_:list rdf:first "a" ; ref:rest ( "b" ) .

And so, the hash must reflect that:

{
  "*": {
    "_:list": {
      "rdf:first": [ "\"a" ],
      "rdf:rest": [
        [ "\"b" ]
      ]
    },
    "ex:foo": { "ex:list": [ "_:list"] },
    "ex:bar": { "ex:list": [ "_:list"] },
    "ex:baz": { "ex:list": [ "_:list"] }
  }
}

This appears to be correct. Please let me know if you think otherwise or feel free to close.

Thanks!

blake-regalia commented 2 years ago

Ah, I see. Makes sense 👍