constraints - 如何在 RDF/OWL 中为复合键建模
问题描述
我正在尝试将我当前的关系数据库转换为 RDF/OWL 三重存储。我遇到的一件事是当我有一个具有多个值的复合/复合键的桥接/连接表时。例如,我有以下内容:
Equipment (EquipmentId)
EquipmentPoints (EquipmentId, PointId, CommodityId)
Point (PointId)
我不确定我将如何对数据建模Equipment :hasPoint ...
?特定点可能是不同的商品,具体取决于它所在的设备类型。
感谢任何帮助。
解决方案
首先,也许你可以改造东西,摆脱:EquipmentPoint
s. 它们可能只是关系建模的产物。RDF 属性可能有多个值。有关更多详细信息,请参见此处。
为了清楚起见,我将稍微简化您的数据模型:
Equipment (EquipmentId)
EquipmentPoints (EquipmentId, PointId)
Point (PointId)
RDF
RDF 是无模式的,RDF 中没有约束。
您可以对事物进行建模,如另一个答案所示:
@prefix : <https://stackoverflow.com/q/51974155/7879193#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
:equipment1 rdf:type :Equipment .
:equipment2 rdf:type :Equipment .
:point1 rdf:type :Point .
:point2 rdf:type :Point .
:equipmentPoint1 rdf:type :EquipmentPoint .
:equipmentPoint2 rdf:type :EquipmentPoint .
:equipmentPoint1 :hasEquipment :equipment1 ;
:hasPoint :point1 .
:equipmentPoint2 :hasEquipment :equipment1 ;
:hasPoint :point1 . # "constraint violation"
为了定义约束,您可以使用 SHACL 之类的语言。不幸的是,SHACL 中没有复合键的核心约束组件,应该使用基于 SPARQL 的约束:
:EquipmentPointShape a sh:NodeShape ;
sh:targetClass :EquipmentPoint ;
sh:sparql [
sh:message "Violation!" ;
sh:severity sh:Violation ;
sh:select """
SELECT ?this {
?point1 ^:hasPoint ?this, ?that .
?equipment ^:hasEquipment ?this, ?that .
FILTER (?this != ?that)
}
"""
] .
猫头鹰
OWL 是为推理而设计的,而不是为约束检查而设计的。有关更多详细信息,请参阅此答案。但是,您可以使用OWL 2 keys。
首先,添加一些本体“样板”:
[] rdf:type owl:Ontology .
:Equipment rdf:type owl:Class .
:Point rdf:type owl:Class .
:EquipmentPoint rdf:type owl:Class .
:hasPoint rdf:type owl:ObjectProperty .
:hasEquipment rdf:type owl:ObjectProperty .
:equipment1 rdf:type owl:NamedIndividual .
:equipment2 rdf:type owl:NamedIndividual .
:point1 rdf:type owl:NamedIndividual .
:point2 rdf:type owl:NamedIndividual .
:equipmentPoint1 rdf:type owl:NamedIndividual .
:equipmentPoint2 rdf:type owl:NamedIndividual .
现在你有了正确的 Turtle 序列化本体。然后加:
:EquipmentPoint owl:hasKey (:hasEquipment
:hasPoint
) .
[ rdf:type owl:AllDifferent ;
owl:distinctMembers (:equipmentPoint1
:equipmentPoint2
)
] .
推理者会推断出你的本体是不一致的。
请注意,OWL 中没有唯一名称假设,并且存在开放世界假设。
删除后
[ rdf:type owl:AllDifferent ;
owl:distinctMembers (:equipmentPoint1
:equipmentPoint2
)
] .
推理者会推断
:equipmentPoint1 owl:sameAs :equipmentPoint2 .
推荐阅读
- html - 如何定位介于两者之间
- 在导航栏中?
- html5-video - .mp4 视频无法在移动设备上播放
- android - Ratingbar的最后一颗星星正在被裁剪
- java - 默认情况下登录 Tomcat 网络服务器是异步的吗?
- computational-geometry - 构建多边形的约束 alpha 形状
- c - 为什么这个快速排序算法实现代码会出现分段错误错误?
- python-asyncio - TypeError:对象 NoneType 不能在“等待”表达式中使用
- excel - 如何使用我定义的最后一行作为我的范围的一部分?
- c# - 打印任何希望类的字段名称
- jenkins - 如何在 Jenkins Job DSL 中创建可扩展的基础作业?