例如,在Java中,我可以通过将一个类声明为final来关闭它。然而,它仍将继承它的超类:
public abstract class Super {
final boolean test = true;
}public final class Sub extends Super
{
public static void main(String[] args) {System.out.println(new Sub().test);}
}然而,在SHACL中,这似乎不起作用:
@prefix : <http://test.ex/>.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix owl: <http://www.w3.org/2002/07/owl#>.
@prefix sh:<http://www.w3.org/ns/shacl#>.
:Super a owl:Class.
:Sub a owl:Class;
rdfs:subClassOf :Super.
:Sub1 a :Sub;
:exampleProperty :TestObject.
:SuperShape a sh:NodeShape;
sh:targetClass :Super;
sh:property [sh:path :exampleProperty].
:SubShape a sh:NodeShape;
sh:targetClass :Sub;
sh:ignoredProperties ( rdf:type );
sh:closed true. pyshacl -s test.ttl test.ttl
Validation Report
Conforms: False
Results (1):
Constraint Violation in ClosedConstraintComponent (http://www.w3.org/ns/shacl#ClosedConstraintComponent):
Severity: sh:Violation
Source Shape: :SubShape
Focus Node: :Sub1
Value Node: :TestObject
Result Path: :exampleProperty
Message: Node :Sub1 is closed. It cannot have value: :TestObject在带有继承的SHACL中有使用封闭形状的方法吗?
发布于 2022-01-22 00:12:16
官方sh:closed不处理继承。但是它可以用SHACL-SPARQL表示,pySHACL似乎理解它,所以您可以使用
https://datashapes.org/constraints.html#ClosedByTypesConstraintComponent
对此,只需使用owl:导入破折号形状图。
https://stackoverflow.com/questions/70785194
复制相似问题