使用SHACL来验证具有最多一个值的属性的属性。

huangapple go评论55阅读模式
英文:

Using shacl to validate a property that has at most one value in its properties

问题

我正在尝试基于我们组织正在开发的本体(用荷兰语编写)创建一个基于SHACL的验证规则:https://wegenenverkeer.data.vlaanderen.be/

所描述的对象具有属性(属性),这些属性具有指定的数据类型。数据类型可以是原始的(如字符串或小数)或复杂的,这意味着属性本身将具有属性(嵌套属性)。例如:资产对象A将具有一个属性assetId,它是一个复杂数据类型DtcIdentificator,其中包含两个属性。我已成功创建了一个SHACL,通过创建多个形状并将它们嵌套来验证对象。

现在我遇到了我们所称的联合数据类型的问题。这些是一种特殊类型的复杂数据类型。它们仍然是嵌套的数据类型:具有联合数据类型的属性将具有多个属性,但只有其中一个属性可以具有值。如果属性具有2个具有值的属性,则它是无效的。我如何在SHACL中创建这样的约束?

示例(用荷兰语):https://wegenenverkeer.data.vlaanderen.be/doc/implementatiemodel/union-datatypes/#Afmeting%20verkeersbord
交通标志(Verkeersbord,请参见https://wegenenverkeer.data.vlaanderen.be/doc/implementatiemodel/signalisatie/#Verkeersbord)可以具有数据类型DtuAfmetingVerkeersbord的属性afmeting(大小)。
如果存在这种类型的资产A,我可以将其大小定义为(在点表示法中):

A.afmeting.rond.waarde = 700

-或-

A.afmeting.driehoekig.waarde = 400

这两种使用afmeting属性的方式都是有效的,然而,如果它们都用于同一个对象,这将变得无效,因为A.afmeting只能有一个属性具有值。

我尝试在SHACL中使用联合约束,但很快发现这与我们所称的“联合数据类型”无关。

英文:

I'm trying to create a shacl based on the ontology that my organization is developing (in dutch): https://wegenenverkeer.data.vlaanderen.be/

The objects described have attributes (properties), that have a specified datatype. The datatype can a primitive (like string or decimal) or complex, which means the property will have properties itself (nested properties). For example: an asset object A will have an attribute assetId which is a complex datatype DtcIdentificator, which consists of two properties itself. I have succesfully created a shacl that validates objects by creating multiple shapes and nesting them.

I now run into the problem of what we call union datatypes. These are a special kind of complex datatypes. They are still nested datatypes: the attribute with the union datatypes will have multiple properties but only exactly zero or one of those properties may have a value. If the attribute has 2 properties with values, it is invalid. How can I create such a constraint in shacl?

Example (in dutch): https://wegenenverkeer.data.vlaanderen.be/doc/implementatiemodel/union-datatypes/#Afmeting%20verkeersbord
A traffic sign (Verkeersbord, see https://wegenenverkeer.data.vlaanderen.be/doc/implementatiemodel/signalisatie/#Verkeersbord) can have a property afmeting (size) of the datatype DtuAfmetingVerkeersbord.
If an asset A of this type would exist, I could define its size as (in dotnotation):

A.afmeting.rond.waarde = 700

-or-

A.afmeting.driehoekig.waarde = 400

Both are valid ways of using the afmeting property, however, if they are both used for the same object, this becomes invalid, as only one property of A.afmeting may have a value.

I have tried using the union constraint in shacl, but soon found out that that has nothing to do with what we call "union datatypes"

答案1

得分: 1

我认为你遇到困难的原因是因为这种问题通常有不同的建模方式。基本上,你有不同类型的交通标志,这些标志可以有测量值。根据你描述的模型,A.afmeting.rond.waarde 通过一个属性捕获了两个概念:(a) 类型和 (b) 大小。根据你的问题,这似乎是你的意图。然而,通常解决这种问题的方式并不是这样的。

一个更直观的设计是让交通标志具有2个不同的属性:(a) 类型和 (b) 测量值。交通标志的类型可以是achthoekig、driehoekig等。然后,你可以使用SHACL来检查交通标志是否具有交通标志的这两个属性中的一个或者都没有。

英文:

I think the reason you are struggling is because this kind of problem is usually modelled differently. Basically you have different types of Traffic signs and these signs can have measurements. With the model as you described, A.afmeting.rond.waarde captures 2 ideas using 1 property: (a) the type and (b) the size. From your question, this seems to be the intend. However, this is usually not how this kind of problem is addressed.

A more intuitive design is for Traffic sign to have 2 different properties: (a) type and (b) a measurement. The Traffic sign types are achthoekig, driehoekig, etc. Then you can use SHACL to check that a traffic sign has either both or no properties for a traffic sign.

答案2

得分: 0

我已经实现了一个解决方案,使用了'或'和'和'约束的组合:

imel:DtuTestUnionTypeUnionConstraint a sh:NodeShape ;
     rdfs:comment "https://wegenenverkeer.data.vlaanderen.be/ns/implementatieelement#DtuTestUnionType的联合约束" ;
     sh:or ( [ sh:and ( [ sh:maxCount 0 ;
          sh:path imel:DtuTestUnionType.unionKwantWrd ]
          [ sh:maxCount 0 ;
          sh:path imel:DtuTestUnionType.unionString ] ) ]
     [ sh:and ( [ sh:minCount 1 ;
          sh:path imel:DtuTestUnionType.unionKwantWrd ]
          [ sh:maxCount 0 ;
          sh:path imel:DtuTestUnionType.unionString ] ) ]
     [ sh:and ( [ sh:maxCount 0 ;
          sh:path imel:DtuTestUnionType.unionKwantWrd ]
          [ sh:minCount 1 ;
          sh:path imel:DtuTestUnionType.unionString ] ) ] ) ;
     sh:targetObjectsOf imel:DtuTestUnionType .
英文:

I have implemented a solution for this, using a combination of 'or' and 'and' constraints:

imel:DtuTestUnionTypeUnionConstraint a sh:NodeShape ;
     rdfs:comment "union constraint of https://wegenenverkeer.data.vlaanderen.be/ns/implementatieelement#DtuTestUnionType" ;
     sh:or ( [ sh:and ( [ sh:maxCount 0 ;
          sh:path imel:DtuTestUnionType.unionKwantWrd ]
          [ sh:maxCount 0 ;
          sh:path imel:DtuTestUnionType.unionString ] ) ]
     [ sh:and ( [ sh:minCount 1 ;
          sh:path imel:DtuTestUnionType.unionKwantWrd ]
          [ sh:maxCount 0 ;
          sh:path imel:DtuTestUnionType.unionString ] ) ]
     [ sh:and ( [ sh:maxCount 0 ;
          sh:path imel:DtuTestUnionType.unionKwantWrd ]
          [ sh:minCount 1 ;
          sh:path imel:DtuTestUnionType.unionString ] ) ] ) ;
     sh:targetObjectsOf imel:DtuTestUnionType .

huangapple
  • 本文由 发表于 2023年1月8日 21:39:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75048197.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定