首先,請注意,在您的OWL代碼中使用rdf:List
s意味着您將在OWL Full中,而許多reasoners被設計爲與OWL DL一起使用。你可能會這樣做,如果你是,那麼很好。如果您需要留在OWL DL中,那麼您必須使用自己的詞彙表作爲列表,例如類warp:List
和屬性warp:first
和warp:rest
,並使用它們來代替它們的RDF對應項。
無論如何,一旦你確定了你List
類和你first
和rest
屬性,你可以定義列表類型ListOfElements
只能含有一些類Element
的成員有下列限制:
ElementList⊑列表和(第一僅元件)和(休息僅元素列表)
這意味着ElementList
是:(ⅰ)List
; (ii)對first
財產的價值爲Element
;並且(iii)具有ElementList
作爲其rest
,這意味着List
中的其餘部分也必須是Element
s。無論nil
對象應該已經被聲明爲List
,但你也可能要包括:
零一個元素列表
,但這並不一定是很重要的。對於你的情況,你想要以類似的方式定義一個類TitleList
,然後聲明你的財產範圍爲TitleList
。
下面是一個例子本體只包括定義這些類型List
類和ElementList
類(在人類可讀的龜):
@prefix : <http://stackoverflow.com/a/19480798/1281433/code#> .
@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#> .
:rest a owl:ObjectProperty ;
rdfs:domain :List ;
rdfs:range :List .
:List a owl:Class .
:nil a owl:NamedIndividual , :ElementList , :List .
:ElementList a owl:Class ;
rdfs:subClassOf [ a owl:Class ;
owl:intersectionOf (:List [ a owl:Restriction ;
owl:allValuesFrom :Element ;
owl:onProperty :first
] [ a owl:Restriction ;
owl:allValuesFrom :ElementList ;
owl:onProperty :rest
])
] .
:Element a owl:Class .
:first a owl:ObjectProperty ;
rdfs:domain :List .
<http://stackoverflow.com/a/19480798/1281433/code>
a owl:Ontology .
[ a owl:Axiom ;
rdfs:comment "It's probably a good idea to specify that nil is an ElementList. This could also be inferred, though, if there is a nil-terminated List that is known to be an ElementList." ;
owl:annotatedProperty rdf:type ;
owl:annotatedSource :nil ;
owl:annotatedTarget :ElementList
] .
對於完全一般性的,我已經定義新新List
類,first
和rest
屬性,以及個人nil
,但是如果OWL Full與您同行,那麼您可以使用rdf:List
等。爲了完整起見,RDF/XML中存在相同的本體:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns="http://stackoverflow.com/a/19480798/1281433/code#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="http://stackoverflow.com/a/19480798/1281433/code"/>
<owl:Class rdf:about="http://stackoverflow.com/a/19480798/1281433/code#List"/>
<owl:Class rdf:about="http://stackoverflow.com/a/19480798/1281433/code#ElementList">
<rdfs:subClassOf>
<owl:Class>
<owl:intersectionOf rdf:parseType="Collection">
<owl:Class rdf:about="http://stackoverflow.com/a/19480798/1281433/code#List"/>
<owl:Restriction>
<owl:onProperty>
<owl:ObjectProperty rdf:about="http://stackoverflow.com/a/19480798/1281433/code#first"/>
</owl:onProperty>
<owl:allValuesFrom>
<owl:Class rdf:about="http://stackoverflow.com/a/19480798/1281433/code#Element"/>
</owl:allValuesFrom>
</owl:Restriction>
<owl:Restriction>
<owl:onProperty>
<owl:ObjectProperty rdf:about="http://stackoverflow.com/a/19480798/1281433/code#rest"/>
</owl:onProperty>
<owl:allValuesFrom rdf:resource="http://stackoverflow.com/a/19480798/1281433/code#ElementList"/>
</owl:Restriction>
</owl:intersectionOf>
</owl:Class>
</rdfs:subClassOf>
</owl:Class>
<owl:ObjectProperty rdf:about="http://stackoverflow.com/a/19480798/1281433/code#rest">
<rdfs:range rdf:resource="http://stackoverflow.com/a/19480798/1281433/code#List"/>
<rdfs:domain rdf:resource="http://stackoverflow.com/a/19480798/1281433/code#List"/>
</owl:ObjectProperty>
<owl:ObjectProperty rdf:about="http://stackoverflow.com/a/19480798/1281433/code#first">
<rdfs:domain rdf:resource="http://stackoverflow.com/a/19480798/1281433/code#List"/>
</owl:ObjectProperty>
<owl:Axiom>
<rdfs:comment>It's probably a good idea to specify that nil is an ElementList. This could also be inferred, though, if there is a nil-terminated List that is known to be an ElementList.</rdfs:comment>
<owl:annotatedTarget rdf:resource="http://stackoverflow.com/a/19480798/1281433/code#ElementList"/>
<owl:annotatedSource>
<owl:NamedIndividual rdf:about="http://stackoverflow.com/a/19480798/1281433/code#nil">
<rdf:type rdf:resource="http://stackoverflow.com/a/19480798/1281433/code#ElementList"/>
<rdf:type rdf:resource="http://stackoverflow.com/a/19480798/1281433/code#List"/>
</owl:NamedIndividual>
</owl:annotatedSource>
<owl:annotatedProperty rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#type"/>
</owl:Axiom>
</rdf:RDF>
謝謝約書亞!這是針對JSON-LD web服務的,大多數客戶端根本不關心RDF位,所以我目前不關心reasoners。 – warp
@warp是的,如果你不關心reasoners,這應該適合你。 (儘管如果你不使用推理器,只是簡單地說明某個列表是,例如,IntegerList不會讓你得到每個成員都是Integer的結果;但是你需要一個推理器)。對於你,請考慮[接受它](http://meta.stackexchange.com/q/5234/225437)。如果沒有,我們可以做些什麼來改善它? :) –