Может ли SHACL проверять JSON-LD, содержащий список объектов? - PullRequest
2 голосов
/ 29 октября 2019

Я хочу проверить следующий JSON-LD с помощью SHACL:

{
  "@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"
      }
    ]
  } ]
}

В приведенном выше примере myList - это список объектов, который должен содержать как минимум один элемент, каждый из которых должен содержать все три поля: year, month и day. Для его проверки используется следующий TTL:

@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, который содержит список объектов без использования этого альтернативного решения?

1 Ответ

0 голосов
/ 31 октября 2019

Да, SHACL может проверять JSON-LD, содержащий список объектов.

Ошибка PEBCAK вызвала сбой. (См. Комментарии.)

Вопрос, вероятно, следует удалить.

...