这些使用sh:or的形状图之间有什么区别?

问题描述 投票:1回答:1

我有以下数据图。

@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:typo,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)的原因是,如果可行,它会更加简洁。

pySHACLTopBraid SHACL API shaclvalidate.sh都同意结果。

sparql rdf turtle-rdf shacl
1个回答
0
投票

“或”的问题是,您已将焦点“移动”到了rdf:type*的值(沿着指定的路径“移动”了),但是当您说sh:hasValue时,这将解释为rdf:type*的值中尚未指定的路径上的约束。

© www.soinside.com 2019 - 2024. All rights reserved.