2

SHACL を使用して次の JSON-LD を検証しようとしています。

{
  "@context" : {
    "day" : {
      "@id" : "test:day"
    },
    "month" : {
      "@id" : "test:month"
    },
    "myList" : {
      "@id" : "test:myList"
    },
    "year" : {
      "@id" : "test:year"
    },
    "schema" : "http://schema.org/",
    "rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    "xsd" : "http://www.w3.org/2001/XMLSchema#",
    "test" : "http://www.test.com/ns#"
  },
  "@graph" : [ {
    "@id" : "test:MyNode",
    "@type" : "test:MyTargetClass",
    "myList" : [
      {
        "year" : "2019",
        "month" : "October",
        "day" : "29"
      },
      {
        "year" : "2018",
        "month" : "January",
        "day" : "17"
      }
    ]
  } ]
}

上記の例では、 は少なくともmyList1 つの要素を含む必要があるオブジェクトのリストであり、各要素には、、およびの 3 つのフィールドがすべて含まれている必要があります。次の TTL を使用して検証しています。yearmonthday

@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix test: <http://www.test.com/ns#> .

test:MyListShape
    a sh:NodeShape ;
    sh:closed true ;
    sh:ignoredProperties ( rdf:type ) ;
    sh:property [
        sh:path test:year ;
        sh:datatype xsd:string ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
    ] ;
    sh:property [
        sh:path test:month ;
        sh:datatype xsd:string ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
    ] ;
    sh:property [
        sh:path test:day ;
        sh:datatype xsd:string ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
    ] .

test:MyShape
    a sh:NodeShape ;
    sh:closed true ;
    sh:ignoredProperties ( rdf:type ) ;
    sh:targetClass test:MyTargetClass ;
    sh:property [
        sh:path test:myList ;
        sh:node test:MyListShape ;
        sh:minCount 1 ;
    ] .

JSON-LD を検証しようとすると、次のスニペットを含む応答が返され、データが適合しない理由が示されます。

{
  "@id" : "_:b3",
  "@type" : "http://www.w3.org/ns/shacl#ValidationResult",
  "focusNode" : "test:MyNode",
  "resultMessage" : "Property may only have 1 value, but found 2",
  "resultPath" : "test:myList",
  "resultSeverity" : "http://www.w3.org/ns/shacl#Violation",
  "sourceConstraintComponent" : "http://www.w3.org/ns/shacl#MaxCountConstraintComponent",
  "sourceShape" : "_:b4"
}

test:myListを指定していないのに、プロパティの値が 1 つだけでなければならないのはなぜsh:maxCountですか?


また、次のように変更myListしてみました。@context

"myList" : {
  "@id" : "test:myList",
  "@container" : "@list"
}

ただし、これも適合せ、次のスニペットを含む応答を返します。

{
  "@id" : "_:b0",
  "@type" : "http://www.w3.org/ns/shacl#ValidationResult",
  "focusNode" : "test:MyNode",
  "resultMessage" : "Value does not have shape test:MyListShape",
  "resultPath" : "test:myList",
  "resultSeverity" : "http://www.w3.org/ns/shacl#Violation",
  "sourceConstraintComponent" : "http://www.w3.org/ns/shacl#NodeConstraintComponent",
  "sourceShape" : "_:b2",
  "value" : "_:b1"
}

私が遭遇した別の解決策はmyList、の別のノードに保存すること@graphですが、これは私のユースケースには理想的ではありません:

{
  "@id" : "test:myListNode",
  "@type" : "test:myListNode",
  "year" : [ "2019", "2018" ],
  "month" : [ "October", "January" ],
  "day" : [ "29", "17" ]
}

したがって、SHACL を使用して、この代替ソリューションを使用せずに、オブジェクトのリストを含む JSON-LD を検証することは可能ですか?

4

1 に答える 1

0

はい、SHACL は、オブジェクトのリストを含む JSON-LD を検証できます。

PEBCAK エラーが原因で失敗しました。(コメントを参照してください。)

于 2019-10-31T15:41:05.760 に答える