[英]Use SHACL to validate a date within a certain range
如何使用 SHACL 验证日期是否在特定范围内? 我尝试使用 minInclusive、maxInclusive、minExclusive、maxExcluse 和 lessThan,但似乎没有任何效果。 我正在使用带有这些数据的 SHACL Playground。
@prefix dash: <http://datashapes.org/dash#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ex: <http://example.com/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
ex:QueryParameterShape
a sh:NodeShape ;
sh:targetClass ex:QueryParameter ;
sh:property [
sh:path ex:peildatum ;
sh:datatype xsd:date ;
sh:lessThan "2022-01-01"^^xsd:date ;
sh:maxCount 0 ;
sh:name "peildatum" ;
] .
[
{
"@context": { "@vocab": "http://example.com/" },
"@id": "http://example.com/query_variable_1",
"@type": "QueryParameter",
"peildatum": [
{
"@value": "2022-05-01",
"@type": "http://www.w3.org/2001/XMLSchema#date"
}
]
},
{
"@context": { "@vocab": "http://example.com/" },
"@id": "http://example.com/query_variable_2",
"@type": "QueryParameter",
"peildatum": [
{
"@value": "2021-05-01",
"@type": "http://www.w3.org/2001/XMLSchema#date"
}
]
}
]
验证报告指出:
[
a sh:ValidationResult ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:MaxCountConstraintComponent ;
sh:sourceShape _:n3790 ;
sh:focusNode ex:query_variable_1 ;
sh:resultPath ex:peildatum ;
sh:resultMessage "More than 0 values" ;
] .
[
a sh:ValidationResult ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:MaxCountConstraintComponent ;
sh:sourceShape _:n3790 ;
sh:focusNode ex:query_variable_2 ;
sh:resultPath ex:peildatum ;
sh:resultMessage "More than 0 values" ;
] .
我添加了 maxCount 0 限制以查看验证报告是否有效。 是的,确实如此。 但是对日期的限制不起作用。
有任何想法吗?
sh:lessThan 用于一对属性之间,例如 ex:birthDate sh:lessThan sh:deathDate。 使用 sh:minInclusive 等与特定值进行比较。
https://www.w3.org/TR/shacl/#core-components-range
话虽如此,SHACL Playground 已经有 5 年没有维护了,并且在处理 < 操作(包括 sh:minInclusive)方面存在已知限制,因此您不应依赖它。 还有很多其他可用的开源库。
为了完整起见,正确的形状图应该是:
@prefix dash: <http://datashapes.org/dash#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ex: <http://example.com/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
ex:QueryParameterShape
a sh:NodeShape ;
sh:targetClass ex:QueryParameter ;
sh:property [
sh:path ex:peildatum ;
sh:datatype xsd:date ;
sh:maxInclusive "2021-12-31"^^xsd:date ;
sh:name "peildatum" ;
] .
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.