[英]Use SHACL to validate a date within a certain range
How can I use SHACL to validate if a date lies within a certain range?如何使用 SHACL 验证日期是否在特定范围内? I tried using minInclusive, maxInclusive, minExclusive, maxExcluse and lessThan, but nothing seems to work.
我尝试使用 minInclusive、maxInclusive、minExclusive、maxExcluse 和 lessThan,但似乎没有任何效果。 I am using the SHACL Playground with this data.
我正在使用带有这些数据的 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"
}
]
}
]
The validation report states:验证报告指出:
[
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" ;
] .
I added the maxCount 0 restriction to see if the validation report works at all.我添加了 maxCount 0 限制以查看验证报告是否有效。 And yes, it does.
是的,确实如此。 But the restriction on the date does not work.
但是对日期的限制不起作用。
Any ideas?有任何想法吗?
sh:lessThan is used between a pair of properties, eg ex:birthDate sh:lessThan sh:deathDate. sh:lessThan 用于一对属性之间,例如 ex:birthDate sh:lessThan sh:deathDate。 Use sh:minInclusive etc to compare with specific values.
使用 sh:minInclusive 等与特定值进行比较。
https://www.w3.org/TR/shacl/#core-components-range https://www.w3.org/TR/shacl/#core-components-range
Having said this, the SHACL Playground hasn't been maintained for 5 years and has known limitations with the handling of < operations including sh:minInclusive, so you should not rely on it.话虽如此,SHACL Playground 已经有 5 年没有维护了,并且在处理 < 操作(包括 sh:minInclusive)方面存在已知限制,因此您不应依赖它。 There are plenty of other open source libraries available.
还有很多其他可用的开源库。
Just to be complete, the correct shapes graph should be:为了完整起见,正确的形状图应该是:
@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.