В чем разница между этими графами фигур, которые используют sh: или? - PullRequest
1 голос
/ 20 апреля 2020

У меня есть следующий график данных.

@prefix hr: <http://learningsparql.com/ns/humanResources#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sch: <http://schema.org/> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

hr:Another a rdfs:Class .

hr:Employee a rdfs:Class ;
    rdfs:label "model" ;
    rdfs:comment "a good employee" .

hr:Longer a hr:Employee ;
    rdfs:label "model" ;
    rdfs:comment "a good employee" .

hr:freestanding a rdf:Property ;
    sch:rangeIncludes sch:Text .

hr:missing rdfs:comment "some comment about missing" .

hr:name a rdf:Property ;
    sch:domainIncludes hr:Employee .

hr:nosuper a rdf:Property ;
    sch:domainIncludes hr:Uncreated ;
    sch:rangeIncludes sch:Text .

hr:randomtype a hr:invalidtype ;
    rdfs:label "some label about randomtype" ;
    rdfs:comment "some comment about randomtype" .

hr:typo a rdfs:Classs ;
    rdfs:label "some label about typo" ;
    rdfs:comment "some comment about typo" .

Я пытаюсь понять разницу между этими двумя графиками формы, которые, как мне кажется (неправильно!) Должны возвращать один и тот же результат ... ошибки проверки для hr: опечатка, hr: randomtype и hr: missing, поскольку отсутствует путь свойства rdf: type к rdfs: Class или rdf: Property.

Следующий график формы создает ожидаемые ошибки проверки.

(A) - хорошие результаты

            @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
            @prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
            @prefix sch:  <http://schema.org/> .
            @prefix sh:   <http://www.w3.org/ns/shacl#> .
            @prefix ex:   <http://example.org/> .

            ex:ClassShape
                a sh:NodeShape ;

                sh:property [
                    sh:path [ sh:zeroOrMorePath rdf:type ];
                    sh:nodeKind sh:IRI ;
                    sh:hasValue rdfs:Class;
                    sh:message "class" ;
                ] .

            ex:PropertyShape
                a sh:NodeShape ;

                sh:property [
                    sh:path [ sh:zeroOrMorePath rdf:type ];
                    sh:nodeKind sh:IRI ;
                    sh:hasValue rdf:Property;
                    sh:message "property" ;
                ] .

            ex:ClassOrProperty
                a sh:NodeShape ;
                sh:target [
                    a sh:SPARQLTarget ;
                    sh:select   """
                                SELECT ?this
                                WHERE {
                                    ?this ?p ?o .
                                }
                                """ ;
                ] ;

                sh:or (
                    ex:ClassShape
                    ex:PropertyShape
                );
            .            

Хорошие и ожидаемые ошибки проверки, производимые (A):

Validation Report
Conforms: False
Results (3):
Constraint Violation in OrConstraintComponent (http://www.w3.org/ns/shacl#OrConstraintComponent):
    Severity: sh:Violation
    Source Shape: ex:ClassOrProperty
    Focus Node: hr:randomtype
    Value Node: hr:randomtype
Constraint Violation in OrConstraintComponent (http://www.w3.org/ns/shacl#OrConstraintComponent):
    Severity: sh:Violation
    Source Shape: ex:ClassOrProperty
    Focus Node: hr:typo
    Value Node: hr:typo
Constraint Violation in OrConstraintComponent (http://www.w3.org/ns/shacl#OrConstraintComponent):
    Severity: sh:Violation
    Source Shape: ex:ClassOrProperty
    Focus Node: hr:missing
    Value Node: hr:missing

Однако этот график формы:

(B) - плохие результаты

                    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
                    @prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
                    @prefix sch:  <http://schema.org/> .
                    @prefix sh:   <http://www.w3.org/ns/shacl#> .
                    @prefix ex:  <http://example.org/> .

                    ex:ClassOrProperty
                        a sh:NodeShape ;
                        sh:target [
                            a sh:SPARQLTarget ;
                            sh:select   """
                                        SELECT ?this
                                        WHERE {
                                            ?this ?p ?o .
                                        }
                                        """ ;
                        ] ;

                        sh:property [
                            sh:path     [sh:zeroOrMorePath rdf:type] ;
                            sh:nodeKind sh:IRI ;
                            sh:or (
                                [ sh:hasValue rdfs:Class;   ]
                                [ sh:hasValue rdf:Property; ]
                            )
                        ];
                    .

не приводит только к ожидаемым ошибкам проверки. Я получаю:

Validation Report
Conforms: False
Results (12):
Constraint Violation in OrConstraintComponent (http://www.w3.org/ns/shacl#OrConstraintComponent):
    Severity: sh:Violation
    Source Shape: [ sh:nodeKind sh:IRI ; sh:or ( [ sh:hasValue rdfs:Class ] [ sh:hasValue rdf:Property ] ) ; sh:path [ sh:zeroOrMorePath rdf:type ] ]
    Focus Node: hr:freestanding
    Value Node: hr:freestanding
    Result Path: [ sh:zeroOrMorePath rdf:type ]
Constraint Violation in OrConstraintComponent (http://www.w3.org/ns/shacl#OrConstraintComponent):
    Severity: sh:Violation
    Source Shape: [ sh:nodeKind sh:IRI ; sh:or ( [ sh:hasValue rdfs:Class ] [ sh:hasValue rdf:Property ] ) ; sh:path [ sh:zeroOrMorePath rdf:type ] ]
    Focus Node: hr:name
    Value Node: hr:name
    Result Path: [ sh:zeroOrMorePath rdf:type ]
Constraint Violation in OrConstraintComponent (http://www.w3.org/ns/shacl#OrConstraintComponent):
    Severity: sh:Violation
    Source Shape: [ sh:nodeKind sh:IRI ; sh:or ( [ sh:hasValue rdfs:Class ] [ sh:hasValue rdf:Property ] ) ; sh:path [ sh:zeroOrMorePath rdf:type ] ]
    Focus Node: hr:Another
    Value Node: hr:Another
    Result Path: [ sh:zeroOrMorePath rdf:type ]
Constraint Violation in OrConstraintComponent (http://www.w3.org/ns/shacl#OrConstraintComponent):
    Severity: sh:Violation
    Source Shape: [ sh:nodeKind sh:IRI ; sh:or ( [ sh:hasValue rdfs:Class ] [ sh:hasValue rdf:Property ] ) ; sh:path [ sh:zeroOrMorePath rdf:type ] ]
    Focus Node: hr:nosuper
    Value Node: hr:nosuper
    Result Path: [ sh:zeroOrMorePath rdf:type ]
Constraint Violation in OrConstraintComponent (http://www.w3.org/ns/shacl#OrConstraintComponent):
    Severity: sh:Violation
    Source Shape: [ sh:nodeKind sh:IRI ; sh:or ( [ sh:hasValue rdfs:Class ] [ sh:hasValue rdf:Property ] ) ; sh:path [ sh:zeroOrMorePath rdf:type ] ]
    Focus Node: hr:Employee
    Value Node: hr:Employee
    Result Path: [ sh:zeroOrMorePath rdf:type ]
Constraint Violation in OrConstraintComponent (http://www.w3.org/ns/shacl#OrConstraintComponent):
    Severity: sh:Violation
    Source Shape: [ sh:nodeKind sh:IRI ; sh:or ( [ sh:hasValue rdfs:Class ] [ sh:hasValue rdf:Property ] ) ; sh:path [ sh:zeroOrMorePath rdf:type ] ]
    Focus Node: hr:randomtype
    Value Node: hr:randomtype
    Result Path: [ sh:zeroOrMorePath rdf:type ]
Constraint Violation in OrConstraintComponent (http://www.w3.org/ns/shacl#OrConstraintComponent):
    Severity: sh:Violation
    Source Shape: [ sh:nodeKind sh:IRI ; sh:or ( [ sh:hasValue rdfs:Class ] [ sh:hasValue rdf:Property ] ) ; sh:path [ sh:zeroOrMorePath rdf:type ] ]
    Focus Node: hr:randomtype
    Value Node: hr:invalidtype
    Result Path: [ sh:zeroOrMorePath rdf:type ]
Constraint Violation in OrConstraintComponent (http://www.w3.org/ns/shacl#OrConstraintComponent):
    Severity: sh:Violation
    Source Shape: [ sh:nodeKind sh:IRI ; sh:or ( [ sh:hasValue rdfs:Class ] [ sh:hasValue rdf:Property ] ) ; sh:path [ sh:zeroOrMorePath rdf:type ] ]
    Focus Node: hr:typo
    Value Node: hr:typo
    Result Path: [ sh:zeroOrMorePath rdf:type ]
Constraint Violation in OrConstraintComponent (http://www.w3.org/ns/shacl#OrConstraintComponent):
    Severity: sh:Violation
    Source Shape: [ sh:nodeKind sh:IRI ; sh:or ( [ sh:hasValue rdfs:Class ] [ sh:hasValue rdf:Property ] ) ; sh:path [ sh:zeroOrMorePath rdf:type ] ]
    Focus Node: hr:typo
    Value Node: rdfs:Classs
    Result Path: [ sh:zeroOrMorePath rdf:type ]
Constraint Violation in OrConstraintComponent (http://www.w3.org/ns/shacl#OrConstraintComponent):
    Severity: sh:Violation
    Source Shape: [ sh:nodeKind sh:IRI ; sh:or ( [ sh:hasValue rdfs:Class ] [ sh:hasValue rdf:Property ] ) ; sh:path [ sh:zeroOrMorePath rdf:type ] ]
    Focus Node: hr:missing
    Value Node: hr:missing
    Result Path: [ sh:zeroOrMorePath rdf:type ]
Constraint Violation in OrConstraintComponent (http://www.w3.org/ns/shacl#OrConstraintComponent):
    Severity: sh:Violation
    Source Shape: [ sh:nodeKind sh:IRI ; sh:or ( [ sh:hasValue rdfs:Class ] [ sh:hasValue rdf:Property ] ) ; sh:path [ sh:zeroOrMorePath rdf:type ] ]
    Focus Node: hr:Longer
    Value Node: hr:Employee
    Result Path: [ sh:zeroOrMorePath rdf:type ]
Constraint Violation in OrConstraintComponent (http://www.w3.org/ns/shacl#OrConstraintComponent):
    Severity: sh:Violation
    Source Shape: [ sh:nodeKind sh:IRI ; sh:or ( [ sh:hasValue rdfs:Class ] [ sh:hasValue rdf:Property ] ) ; sh:path [ sh:zeroOrMorePath rdf:type ] ]
    Focus Node: hr:Longer
    Value Node: hr:Longer
    Result Path: [ sh:zeroOrMorePath rdf:type ]

Почему результаты отличаются?

Причина, по которой мне больше нравится (B), чем (A), заключается в том, что он был бы более кратким, если бы работал.

Оба pySHACL и TopBraid SHACL API shaclvalidate. sh согласен с результатами.

1 Ответ

1 голос
/ 22 апреля 2020

Важно понимать, как работают пути свойств. Путь используется для достижения значений. При использовании sh:path [sh:zeroOrMorePath rdf:path] и рассмотрении узла hr:Longer он достигнет трех значений - (0) hr:Longer, (1) hr:Employee и (2) rdfs:Class.

. твердо помните, что происходит в (B) и почему это не работает, можно полностью объяснить.

Оба (A) и (B) имеют одинаковое определение цели и будут возвращать одинаковые узлы фокуса , Это:

hr:Another 
hr:Employee
hr:Longer   
hr:freestanding
hr:missing
hr:name      
hr:nosuper
hr:randomtype
hr:typo      

Кроме того, общим для обоих (A) и (B) является sh:path [sh:zeroOrMorePath rdf:type] ;. Например, при рассмотрении узла hr:Longer он будет выдавать три значения, каждое из которых, возможно, потребуется проверить. Эти три значения: (0) hr:Longer, (1) hr:Employee и (2) rdfs:Class.

Для (B), когда он учитывает hr:Longer и передает испускаемое значение hr:Longer на sh:or он видит, что это не rdfs:Class или rdf:Property. Произошла ошибка проверки, потому что ни одно из sh:or не было выполнено.

Чтобы заставить (B) работать, необходимо изменить два предложения в sh:or на [ sh:path [sh:zeroOrMorePath rdf:type] ; sh:hasValue rdfs:Class; ] и [ sh:path [sh:zeroOrMorePath rdf:type] ; sh:hasValue rdf:Property; ]. В этом случае, когда hr:Longer передается в sh:or, каждое предложение проверяет весь путь, а sh:hasValue требует только, чтобы одно из трех значений, выданных путем, совпадало.

(B) - Рабочая

@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix sch:  <http://schema.org/> .
@prefix sh:   <http://www.w3.org/ns/shacl#> .
@prefix ex:  <http://example.org/> .

ex:ClassOrProperty
    a sh:NodeShape ;
    sh:target [
        a sh:SPARQLTarget ;
        sh:select   """
                    SELECT ?this
                    WHERE {
                        ?this ?p ?o .
                    }
                    """ ;
    ] ;

    sh:property [
        sh:path     [sh:zeroOrMorePath rdf:type] ;
        sh:nodeKind sh:IRI ;
        sh:or (
            [ sh:path [sh:zeroOrMorePath rdf:type] ; sh:hasValue rdfs:Class;   ]
            [ sh:path [sh:zeroOrMorePath rdf:type] ; sh:hasValue rdf:Property; ]
        )
    ];
.

Теперь, учитывая (A), каждый фокусный узел передается в ex:PropertyShape и ex:ClassShape. Если он проверяется по одной из фигур, он будет проверяться. Обе формы похожи в том, что они используют путь sh:path [ sh:zeroOrMorePath rdf:type ];. Поскольку они используют sh:hasValue, только одно из выданных значений для пути должно совпадать. Снова рассмотрим hr:Longer, поскольку путь будет выдавать значение rdfs:Class, он проверяется по ex:ClassShape, и ошибка проверки не генерируется.

...