Sparql 这些使用sh:or的形状图之间有什么区别?
我有下面的数据图表Sparql 这些使用sh:or的形状图之间有什么区别?,sparql,rdf,turtle-rdf,shacl,Sparql,Rdf,Turtle Rdf,Shacl,我有下面的数据图表 @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/> . @p
@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" .
但是,此形状图:
(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; ]
)
];
.
为什么结果不同
我之所以喜欢(B)而不是(A),是因为如果它起作用的话,它会更简洁
两者都同意结果。了解属性路径的工作原理非常重要。路径用于到达值。当使用
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:zerormorepath-rdf:type]代码>。例如,当考虑节点hr:Longer
时,它将发出三个值,每个值可能需要检查。这三个值是(0)hr:Longer
,(1)hr:Employee
,以及(2)rdfs:Class
对于(B),当它考虑hr:Longer
并将发出的值hr:Longer
传递给sh:或,它看到它既不是rdfs:Class
也不是rdf:Property
。由于未满足sh:或
的任何一个子句,因此发出验证错误
为了使(B)有效,需要将sh:or
中的两个子句更改为[sh:path[sh:zerormorepath-rdf:type];sh:hasValue-rdfs:Class;]
和[sh:path[sh:zerormorepath-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; ]
)
];
.
@前缀rdfs:。
@前缀rdf:。
@前缀sch:。
@前缀sh:。
@前缀ex:。
例:类别或属性
阿什:NodeShape;
sh:目标[
sh:SPARQLTarget;
sh:选择“”
选择这个
在哪里{
这是邮政局。
}
""" ;
] ;
sh:物业[
sh:path[sh:zeroOrMorePath rdf:type];
sh:nodeKind sh:IRI;
sh:或者(
[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
。如果它针对其中一个形状进行验证,它将进行验证。这两种形状的相似之处在于它们都使用pathsh:path[sh:zeroOrMorePath-rdf:type]代码>。因为它们使用的是sh:hasValue
,所以只需匹配路径的一个发出值。再次考虑hr:Longer
,因为路径将发出值rdfs:Class
,它将根据ex:ClassShape
进行验证,并且不会生成验证错误
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 ]
hr:Another
hr:Employee
hr:Longer
hr:freestanding
hr:missing
hr:name
hr:nosuper
hr:randomtype
hr:typo
@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; ]
)
];
.