rdf - SHACL 等效于 JSON 模式“uniqueItems”
问题描述
所以我的任务是将描述本体的 JSON 模式转换为 SHACL。
JSON-Schema 具有uniqueItems
结构,顾名思义,它强制数组中的所有元素都是唯一的。出于我的目的,仅考虑 String 类型的元素。
SHACL 中是否有类似的构造?sh:disjoint
需要明确的唯一路径,因此它不适用。我正在考虑创建一个 SPARQL 约束,但由于我的实例都是匿名节点,我还不能让它工作。
编辑:添加示例
有效的 JSON:
{
"name": "Robert Lewandowski",
"mbox": "robert@bayern.de",
"contributor_id": {
"identifier": "https://orcid.org/TEST",
"type": "orcid"
},
"role": [
"ContactPerson",
"DataManager"
]
}
无效的 JSON:
{
"name": "Robert Lewandowski",
"mbox": "robert@bayern.de",
"contributor_id": {
"identifier": "https://orcid.org/TEST",
"type": "orcid"
},
"role": [
"ContactPerson",
"ContactPerson"
]
}
有效 TTL:
madmp:contributor [ foaf:mbox "robert@bayern.de" ;
foaf:name "Robert Lewandowski" ;
madmp:contributor_id [ terms:identifier "https://orcid.org/TEST" ;
madmp:identifier_type "orcid"
] ;
madmp:role ( "ContactPerson" "DataManager")
] ;
无效的 TTL:
madmp:contributor [ foaf:mbox "robert@bayern.de" ;
foaf:name "Robert Lewandowski" ;
madmp:contributor_id [ terms:identifier "https://orcid.org/TEST" ;
madmp:identifier_type "orcid"
] ;
madmp:role ( "ContactPerson" "ContactPerson")
解决方案
所以这是我想出的解决方案。它使用破折号词汇首先确保rdf:List
结构有效。然后,SPARQL 约束确保这些值是唯一的。
它可能不漂亮,但它对我有用。
sh:property [
sh:path madmp:role;
sh:name "The Role Schema";
sh:description "Type of contributor";
sh:node dash:ListShape;
sh:minCount 1 ;
sh:property [
sh:path ( [ sh:zeroOrMorePath rdf:rest ] rdf:first ) ;
sh:datatype xsd:string ;
sh:minCount 1 ;
]
];
sh:sparql [
sh:message "Contributor {?name} has role {?role} more than once ({?roleCount} times).";
sh:prefixes (madmp: rdf: foaf:);
sh:select """
PREFIX madmp: <https://w3id.org/madmp/terms#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
SELECT $this ?role ?name (COUNT(?role) AS ?roleCount)
WHERE {
$this $PATH ?contributor.
?contributor madmp:role/rdf:rest*/rdf:first ?role;
foaf:name ?name
}
GROUP BY $this ?name ?role
HAVING (?roleCount > 1)
"""
]
推荐阅读
- asp.net - 如何在 Url.Action 和模型中传递区域
- ios - 让 Swift 4.2 从之前的 Objective-C 构建中加载 Core Data Store
- gnu-parallel - GNU Parallel:如何从 gnu 并行管道接收标准输入,就好像它来自文件一样?
- sql - 重复行 - SQL Server Groupby 和 Union
- html - 无法加载轮播 - Bootstrap 4
- animation - SVG动画问题
- amazon-cloudfront - 将源/缓存行为动态添加到现有 CloudFront 发行版
- html - 范围滑块 - 如何在轨道上添加垂直线?
- laravel - CKEditor5 与 vue.js 和 laravel 的集成
- node.js - httpOnly cookie 可见