我正在构建一个智能家居本体。我现在有一个这样的类层次结构:
我想给“RoomStatus”的子类下定义。例如,我想定义当室温在 18-22 摄氏度范围内且湿度在 40-50% 范围内时,房间处于温和状态。我尝试在 Protege 中使用类表达式编辑器,但它不起作用。
如何实现这个定义? 提前致谢!
Hatim 的回答 可能对您有用,但我认为最好不要在不必要时使用等效类公理,并避免将温和状态与特定温度和湿度联系起来。毕竟,Room 的温和状态与 Sauna 的温和状态是非常不同的。
我建议使用通用类公理来表示:
如果房间的温度和湿度在指定范围内,则房间处于温和状态。
作为一个类公理,那就是:
Room and (hasTemperature some integer[≥18,≤22]) and (hasHumidity some integer[≥40,≤50]) subClassOf (hasStatus value Mild_Status)
这几乎就是您可以在 Protege 中编写的内容:
这是具有该公理的本体(在 RDF/XML 和 TTL 中):
@prefix : <https://stackoverflow.com/q/29228328/1281433/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
: a owl:Ontology .
:Room a owl:Class .
:Status a owl:Class .
:Mild_Status a owl:NamedIndividual , :Status .
:hasStatus a owl:ObjectProperty .
:hasTemperature a owl:DatatypeProperty .
:hasHumidity a owl:DatatypeProperty .
[ a owl:Class ;
rdfs:subClassOf [ a owl:Restriction ;
owl:hasValue :Mild_Status ;
owl:onProperty :hasStatus
] ;
owl:intersectionOf ( :Room _:b2 _:b3 )
] .
_:b3 a owl:Restriction ;
owl:onProperty :hasTemperature ;
owl:someValuesFrom [ a rdfs:Datatype ;
owl:onDatatype xsd:integer ;
owl:withRestrictions ( _:b0 _:b4 )
] .
_:b0 xsd:minInclusive 18 .
_:b4 xsd:maxInclusive 22 .
_:b2 a owl:Restriction ;
owl:onProperty :hasHumidity ;
owl:someValuesFrom [ a rdfs:Datatype ;
owl:onDatatype xsd:integer ;
owl:withRestrictions ( _:b5 _:b1 )
] .
_:b1 xsd:minInclusive 40 .
_:b5 xsd:maxInclusive 50 .
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns="https://stackoverflow.com/q/29228328/1281433/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="https://stackoverflow.com/q/29228328/1281433/"/>
<owl:Class rdf:about="https://stackoverflow.com/q/29228328/1281433/Room"/>
<owl:Class rdf:about="https://stackoverflow.com/q/29228328/1281433/Status"/>
<owl:Class>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty>
<owl:ObjectProperty rdf:about="https://stackoverflow.com/q/29228328/1281433/hasStatus"/>
</owl:onProperty>
<owl:hasValue>
<owl:NamedIndividual rdf:about="https://stackoverflow.com/q/29228328/1281433/Mild_Status">
<rdf:type rdf:resource="https://stackoverflow.com/q/29228328/1281433/Status"/>
</owl:NamedIndividual>
</owl:hasValue>
</owl:Restriction>
</rdfs:subClassOf>
<owl:intersectionOf rdf:parseType="Collection">
<owl:Class rdf:about="https://stackoverflow.com/q/29228328/1281433/Room"/>
<owl:Restriction>
<owl:onProperty>
<owl:DatatypeProperty rdf:about="https://stackoverflow.com/q/29228328/1281433/hasHumidity"/>
</owl:onProperty>
<owl:someValuesFrom>
<rdfs:Datatype>
<owl:onDatatype rdf:resource="http://www.w3.org/2001/XMLSchema#integer"/>
<owl:withRestrictions rdf:parseType="Collection">
<rdf:Description>
<xsd:maxInclusive rdf:datatype="http://www.w3.org/2001/XMLSchema#integer"
>50</xsd:maxInclusive>
</rdf:Description>
<rdf:Description>
<xsd:minInclusive rdf:datatype="http://www.w3.org/2001/XMLSchema#integer"
>40</xsd:minInclusive>
</rdf:Description>
</owl:withRestrictions>
</rdfs:Datatype>
</owl:someValuesFrom>
</owl:Restriction>
<owl:Restriction>
<owl:onProperty>
<owl:DatatypeProperty rdf:about="https://stackoverflow.com/q/29228328/1281433/hasTemperature"/>
</owl:onProperty>
<owl:someValuesFrom>
<rdfs:Datatype>
<owl:onDatatype rdf:resource="http://www.w3.org/2001/XMLSchema#integer"/>
<owl:withRestrictions rdf:parseType="Collection">
<rdf:Description>
<xsd:minInclusive rdf:datatype="http://www.w3.org/2001/XMLSchema#integer"
>18</xsd:minInclusive>
</rdf:Description>
<rdf:Description>
<xsd:maxInclusive rdf:datatype="http://www.w3.org/2001/XMLSchema#integer"
>22</xsd:maxInclusive>
</rdf:Description>
</owl:withRestrictions>
</rdfs:Datatype>
</owl:someValuesFrom>
</owl:Restriction>
</owl:intersectionOf>
</owl:Class>
</rdf:RDF>
您可以使用 Protege 的类表达式编辑器来完成,但是需要遵循一些步骤:
您创建了#Mild_status 并将其设为#RoomStatus 的子类(正如我在您的编辑器中看到的那样)
您必须定义两个数据属性(#centigrade 和#humidity)的域和范围,例如,将 Class #RoomStatus 作为域,将 xml 数据类型整数作为范围。这一切都可以用 Protege 来完成。
最后,使用类表达式编辑器:你必须断言 #Mild_status 等同于:
RoomStatus
and (centigrade some integer[> 18])
and (centigrade some integer[< 22])
and (humidity some integer[> 40])
and (humidity some integer[<50])
如果你想使用这个表达式进行实例检索推理:你必须知道并不是所有的推理器都支持数据范围推理。 Pellet 支持这种表达式,但我认为 Fact++ 不支持。
这个模型在捕获域中的关键元素方面做得很好,但它有一个常见的错误:在实例可以做得更好的时候过度使用类和子类。
让我们看看测量。我推断您的意思不是进行测量(一个动作),而是要测量的方面,例如火警的状态。我会将 Measurement 重命名为 MeasurementType,然后将 Measurement 的子类表示为 MeasurementType 的实例。
:_MeasurementType_FireAlarmReading a :MeasurementType, owl:NamedIndividual .
:_MeasurementType_GasReading a :MeasurementType, owl:NamedIndividual .
等
MeasurementType 是一个类别类,它的实例定义了放置测量值的特定类别。
实际测量是一个事件,有开始和结束时间。每个实例都通过“isCategorizedBy”属性与测量类型相关。
:_Measurement_gas_reading_2023-04-30T13-18-33 a :Measurement ;
:startDateTime '2023-04-30T13:18:33'^^xsd:dateTime ;
:endDateTime '2023-04-30T13:18:39'^^xsd:dateTime ;
:isCategorizedBy :_MeasurementType_GasReading ;
:hasMagnitude [ reference to a magnitude object that handles the numeric value and an appropriate unit of measure]
.
这种模式使得以后添加其他类型的测量变得容易,而无需引入新的子类。您只需添加一个新的 MeasurementType 实例,例如
:_MeasurementType_Radon_Level a :MeasurementType, owl:NamedIndividual .
最后,我建议您考虑将您的模型基于“要点”上层本体,它提供了许多有用的基类和属性,您可以扩展这些基类和属性来为您的领域建模。 https://www.semanticarts.com/gist/