rdf - 包含和排除父类型的 SHACL 形状定义
问题描述
我有几个涉及类限制的场景。他们中的大多数我都可以开始工作,但有几个我发现有点难以弄清楚。为简单起见,我将从我试图表达的父类型限制开始。
以下将是有效形状,因为它以 ex:Cls1 为目标,使用 ex:parent 指定父级,并且父级具有 ex:P_cls{1, 2, 3} 类型之一。(在所有这些情况下,targetClass 都是 ex:Cls1)。
ex:Child1
a ex:Cls1 ;
ex:parent ex:Parent1 ;
.
ex:Parent1
a ex:Pcls1 ;
.
这将是一个无效的形状,因为必须为父级定义 ex:Pcls{1,2,3} 类型:
ex:Child1
a ex:Cls1 ;
ex:parent ex:Parent1 ;
.
ex:Parent1
a ex:P_clsInvalid_a ;
.
这个是有效的,因为它包括 ex:Pcls{1,2,3} 之一:
ex:Child1
a ex:Cls1 ;
ex:parent ex:Parent1 ;
.
ex:Parent1
a ex:P_cls2, ex:P_clsInvalid_a ;
.
第四个是无效的,因为只允许 ex:Pcls{1, 2, 3} 之一:
ex:Child1
a ex:Cls1 ;
ex:parent ex:Parent1 ;
.
ex:Parent1
a ex:P_cls1, ex:P_cls2;
.
如果我可以接受不允许的类型列表(为了维护,我宁愿声明只允许 ex:P_cls{1, 2, 3})然后以下部分有效,因为它不包括第三次使用案子:
my_sh:ParentTypeRestriction
a sh:NodeShape ;
sh:targetClass ex:Cls1 ;
sh:property[
sh:path ex:parent ;
sh:or (
[ sh:class ex:P_cls1 ]
[ sh:class ex:P_cls2 ]
[ sh:class ex:P_cls3 ]
[ sh:not [ sh:class ex:P_clsInvalid_a ] ]
) ;
sh:maxCount 1 ;
sh:message "parent type for ex:Cls1 is not in ex:P_cls{1, 2, 3}" ;
] ;
.
..我在其中列出了 sh:not 的详尽列表。如前所述,当模型发生变化时,这并不是最好的,我需要找到所有需要排除它的地方。
那么关于如何 1) 改进这种形状,或 2) 为未来添加到 rdf:type 列表中的任何想法?
非常感谢您的观看。
——斯科特
解决方案
推荐阅读
- php - 在 Windows 托管修改 web.config 文件中将所有 html 页面作为 php 处理
- python - 具有减少参数的子类型函数?
- python - 删除包含严格和特定值/int/字符串的行?
- python - 是否有一个功能可以检查我是否在 Python 的任何屏幕上按下了某些东西?
- python - 如何在 python 脚本中提升到 root 权限?
- python - 如何使用 Flask 和 SQLAlchemy 在数据库中存储 API 请求
- mysql - 尝试使用 DataGrip 连接 MySQL 实例时如何修复导致异常的服务器时区?
- r - 如何使用应用于多列数据的条件创建新变量?
- ruby-on-rails - Heroku 错误:“密钥必须是 16 个字节”,但我输入的密钥是 16 个字节
- android - 如何仅在插入一些新记录后删除 Android SQLite 数据库上的先前记录