因此,我的任务是将描述本体的JSON-Schema转换为SHACL。
JSON模式具有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")发布于 2021-07-04 06:37:35
所以这是我想出的一个解决方案。它使用dash vocabulary首先确保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)
"""
]https://stackoverflow.com/questions/68202190
复制相似问题