有什么方法可以验证由相同 属性 链接的不同对象类型的计数吗?
Is there any way to validate counts of different object types linked by same property?
我正在尝试验证来自标签文档的数据。每个标签(或代码)都是一个匿名节点,具有特定的 rdf:type
(以及可能的其他属性,例如 :isPresent
、rdfs:label
、:comment
)。 :Codes
通过相同的 属性 (schema:isTargetOf
) 链接到 :Documents
。
我希望能够说 "A valid Document must have at least one code of types x, y, z, and exactly one code of type k."
@prefix ex: <http://example.org/ns#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema: <http://schema.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
ex:Document
a schema:Document ;
schema:isTargetOf [ a schema:HasAuthor ;
schema:isPresent true ] ;
schema:isTargetOf [ a schema:HasImage ;
schema:isPresent true ] ;
schema:isTargetOf [ a schema:HasImage ;
schema:isPresent true ] ;
.
因此,在此示例中,有效文档必须是至少一个 HasImage 代码和一个 HasAuthor 代码的目标。
如果 属性 不同,我知道该怎么做,例如将 schema:isTargetOf 更改为 schema:has_author 或 schema:has_image.
ex:Document
a schema:Document ;
schema:has_author [ a schema:HasAuthor ;
schema:isPresent true ] ;
schema:has_image [ a schema:HasImage ;
schema:isPresent true ] ;
schema:has_image [ a schema:HasImage ;
schema:isPresent true ] ;
.
那我可以这样做:
@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 schema: <http://schema.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
schema:DocumentShape
a sh:NodeShape ;
sh:targetClass schema:Document ;
sh:property [
sh:path schema:has_author ;
sh:minCount 1 ;
sh:maxCount 1 ;
sh:message "Documents must have exactly 1 author"
] ;
sh:property [
sh:path schema:has_image;
sh:minCount 1 ;
sh:message "Must have at least one HasImage"
] ;
.
本质上,我想验证由单个 属性 链接的事物集合。
目前我正在尝试使用 shacl 规则为每种类型的代码生成特定的 属性 类型,但这感觉有点复杂,我想知道是否有更直接的方法。
如果相关,我正在使用 pyshacl。
我认为这是限定值形状的用例,请参阅 https://www.w3.org/TR/shacl/#QualifiedValueShapeConstraintComponent
尝试一些变体
schema:DocumentShape
a sh:NodeShape ;
sh:targetClass schema:Document ;
sh:property [
sh:path schema:isTargetOf ;
sh:qualifiedMinCount 1 ;
sh:qualifiedValueShape [
sh:class schema:HasAuthor ;
]
] ;
sh:property [
sh:path schema:isTargetOf ;
sh:qualifiedMinCount 1 ;
sh:qualifiedValueShape [
sh:class schema:HasImage ;
]
] .
在上面的示例中,isTargetOf 必须至少有一个 HasAuthor 类型的值和一个 HasImage 类型的值。 (它们可能是相同的值,所以可能将它与 sh:qualifiedValueShapesDisjoint and/or a sh:minCount 3 组合在一起 属性.
我正在尝试验证来自标签文档的数据。每个标签(或代码)都是一个匿名节点,具有特定的 rdf:type
(以及可能的其他属性,例如 :isPresent
、rdfs:label
、:comment
)。 :Codes
通过相同的 属性 (schema:isTargetOf
) 链接到 :Documents
。
我希望能够说 "A valid Document must have at least one code of types x, y, z, and exactly one code of type k."
@prefix ex: <http://example.org/ns#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema: <http://schema.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
ex:Document
a schema:Document ;
schema:isTargetOf [ a schema:HasAuthor ;
schema:isPresent true ] ;
schema:isTargetOf [ a schema:HasImage ;
schema:isPresent true ] ;
schema:isTargetOf [ a schema:HasImage ;
schema:isPresent true ] ;
.
因此,在此示例中,有效文档必须是至少一个 HasImage 代码和一个 HasAuthor 代码的目标。
如果 属性 不同,我知道该怎么做,例如将 schema:isTargetOf 更改为 schema:has_author 或 schema:has_image.
ex:Document
a schema:Document ;
schema:has_author [ a schema:HasAuthor ;
schema:isPresent true ] ;
schema:has_image [ a schema:HasImage ;
schema:isPresent true ] ;
schema:has_image [ a schema:HasImage ;
schema:isPresent true ] ;
.
那我可以这样做:
@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 schema: <http://schema.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
schema:DocumentShape
a sh:NodeShape ;
sh:targetClass schema:Document ;
sh:property [
sh:path schema:has_author ;
sh:minCount 1 ;
sh:maxCount 1 ;
sh:message "Documents must have exactly 1 author"
] ;
sh:property [
sh:path schema:has_image;
sh:minCount 1 ;
sh:message "Must have at least one HasImage"
] ;
.
本质上,我想验证由单个 属性 链接的事物集合。
目前我正在尝试使用 shacl 规则为每种类型的代码生成特定的 属性 类型,但这感觉有点复杂,我想知道是否有更直接的方法。
如果相关,我正在使用 pyshacl。
我认为这是限定值形状的用例,请参阅 https://www.w3.org/TR/shacl/#QualifiedValueShapeConstraintComponent
尝试一些变体
schema:DocumentShape
a sh:NodeShape ;
sh:targetClass schema:Document ;
sh:property [
sh:path schema:isTargetOf ;
sh:qualifiedMinCount 1 ;
sh:qualifiedValueShape [
sh:class schema:HasAuthor ;
]
] ;
sh:property [
sh:path schema:isTargetOf ;
sh:qualifiedMinCount 1 ;
sh:qualifiedValueShape [
sh:class schema:HasImage ;
]
] .
在上面的示例中,isTargetOf 必须至少有一个 HasAuthor 类型的值和一个 HasImage 类型的值。 (它们可能是相同的值,所以可能将它与 sh:qualifiedValueShapesDisjoint and/or a sh:minCount 3 组合在一起 属性.