首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有超类继承的SHACL封闭形状

具有超类继承的SHACL封闭形状
EN

Stack Overflow用户
提问于 2022-01-20 11:14:10
回答 1查看 168关注 0票数 1

例如,在Java中,我可以通过将一个类声明为final来关闭它。然而,它仍将继承它的超类:

代码语言:javascript
复制
public abstract class Super {
    final boolean test = true;
}
代码语言:javascript
复制
public final class Sub extends Super
{
    public static void main(String[] args) {System.out.println(new Sub().test);}
}

然而,在SHACL中,这似乎不起作用:

代码语言:javascript
复制
@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.
代码语言:javascript
复制
 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中有使用封闭形状的方法吗?

EN

回答 1

Stack Overflow用户

发布于 2022-01-22 00:12:16

官方sh:closed不处理继承。但是它可以用SHACL-SPARQL表示,pySHACL似乎理解它,所以您可以使用

https://datashapes.org/constraints.html#ClosedByTypesConstraintComponent

对此,只需使用owl:导入破折号形状图。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70785194

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档