Rdf SPARQL查询排除不相交类的效率
我正在开发一个本体来建模制造系统中的关系。我把它分解成了一个类似的菜肴方案:Rdf SPARQL查询排除不相交类的效率,rdf,sparql,jena,owl,Rdf,Sparql,Jena,Owl,我正在开发一个本体来建模制造系统中的关系。我把它分解成了一个类似的菜肴方案: ex:potatoes rdf:type owl:Class . ex:fish rdf:type owl:Class . ex:beef rdf:type owl:Class . ex:rice rdf:type owl:Class ; owl:disjointWith
ex:potatoes rdf:type owl:Class .
ex:fish rdf:type owl:Class .
ex:beef rdf:type owl:Class .
ex:rice rdf:type owl:Class ;
owl:disjointWith ex:potatoes .
ex:chicken rdf:type owl:Class ;
owl:disjointWith ex:fish .
ex:pork rdf:type owl:Class ;
owl:disjointWith ex:beef .
ex:dish1 rdf:type owl:Class ;
rdfs:subClassOf ex:dishes ;
owl:unionOf ( ex:pork ex:potatoes ) .
ex:dish2 rdf:type owl:Class ;
rdfs:subClassOf ex:dishes ;
owl:unionOf ( ex:rice ex:chicken ) .
ex:dish3 rdf:type owl:Class ;
rdfs:subClassOf ex:dishes ;
owl:unionOf ( ex:fish ex:potatoes ) .
ex:dish4 rdf:type owl:Class ;
rdfs:subClassOf ex:dishes ;
owl:unionOf ( ex:beef ex:rice ) .
所以我有一些间断类,我想这样询问模型:如果有人说他想要米饭和鸡肉,排除所有包含间断类的菜(这里是鱼和土豆)。经过一些研究后,我得出如下结论:
"PREFIX ex: <http://example.org/>"+
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"+
"PREFIX owl: <http://www.w3.org/2002/07/owl#>"+
"PREFIX list: <http://jena.hpl.hp.com/ARQ/list#>"+
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"+
"SELECT ?x "+
"WHERE {"+
"?x rdfs:subClassOf ex:dishes. "+
"FILTER (!isBlank(?x))"+
"FILTER NOT EXISTS { "+
"?x rdfs:subClassOf ?y ."+
"?y rdfs:subClassOf ex:dishes ."+
"FILTER (?x!=?y)"+
"}"+
"FILTER NOT EXISTS {"+
"?z rdfs:subClassOf ?x ." +
"?z owl:disjointWith ex:chicken . }" +
"FILTER NOT EXISTS {"+
"?z rdfs:subClassOf ?x ." +
"?z owl:disjointWith ex:rice . }" +
"}";
有没有更有效的方法?看起来不必要,很复杂。并且必须添加带有“过滤器不存在”的整个块{
?z rdfs:子类?x。
?z猫头鹰:与ex:chicken分离。}每次?
有什么建议吗?我对数据做了一些修改,使一些表示更直接,并且没有对OWL语义的混淆。但是,它直接类似于您正在使用的表示,所以您应该能够更改属性并进行此工作。首先,这是数据。您有一些成分,某些成分与其他成分不相容。(不相容意味着不相容,但不相容并不意味着不相容。毕竟,鸡肉和大米是明显不同的东西,因此是不相交的类别,但这并不意味着它们作为成分不相容。) 如果你真的关心空间,你甚至可以把这两条线结合起来
?dish :ingredients/rdf:rest*/rdf:first ?ingredient .
?ingredient :incompatibleWith ?incompatibleIngredient .
进入
我认为这有点难理解,因为它隐含了列表中的值(你通过以下:配料/rdf:rest*/rdf:first)是菜中的一种配料。没有人有任何想法?你的本体论有点奇怪。当你说
ex:dish1…owl:unionOf(例如:猪肉ex:土豆)
,你是说dish1是猪肉和土豆的结合。这意味着,如果某个东西是猪肉,那么它就是dish1,如果某个东西是土豆,那么它就是dish1。这意味着,例如,如果某个东西是土豆,那么它就是dish1,但根据同样的推理,它就是dish3。因此,煮熟的土豆将被归类为dish1和dish3。这真的是你想说的吗?我使用这个本体论只是为了建立关系,里面不会有任何个人。好的,实际情况如下:我有一条有很多机器的生产线,每台机器都可能处于某种状态(运行、停止等).为了了解机器处于何种状态,我可以测量特征。如果我测量“土豆”和“猪肉”,我知道它的状态x。如果我只测量“猪肉”,它可能处于状态x或状态y,需要进一步分析。有些特征是间断的。如果我测量“鸡肉”,它肯定不是状态z。希望这是可以理解的。欣赏谢谢你的帮助!事实上,我不确定这对我来说有多清楚。在你描述的情况下,听起来你会有一个类“MachineCondition”,成员“Running”、“Stopped”等等,你会想要一些其他类“Machine”、“StoppedMachine”(Machine的子类和(hasCondition值Stopped))“还有一些其他的公理可以帮助你推断出一台机器属于哪个机器的子类。例如,((机器和(加热温度为int[…知道这是一台停止的机器,你就可以推断这是一台停止的机器。非常感谢你的帮助!因此,在你的陈述中,我不需要耶拿的OWLReasoner,我想这更容易:).但为了澄清您上面的最后一条评论,如果我将您的:CompatibleWith与owl:disjointWith和unionOf进行更改,则该查询的干净版本将不起作用,还是我错了?您也需要更改SPARQL查询中的属性,但它应该可以正常工作。我只更改了属性,因为它们实际上不符合OWL语义。但是SPARQL是一种RDF查询语言,对OWL构造没有任何特殊作用。只要在数据和查询中使用它们,您仍然可以使用OWL:disjointWith和OWL:unionOf。我明白了,是的,它确实有效:)我使用了OWL,因为我认为unionOf()中的类are子类可能很有用,owl:disjointWith因此我只需将其添加到其中一个类中,并且它可以以两种方式工作。仍然需要学习很多技术。嘿@Joshua Taylor
,你能告诉我如何从你的注释(:dish1 a:Dish;:配料(:猪肉:土豆))添加属性吗在Jena中直接使用owl:unionOf?类似于“dish1.addProperty(owl.unionOf,…);”?到目前为止,我在ttl文件中有它,但现在我想直接在我的应用程序中修改它
@prefix : <urn:ex:>
# Incompatibities
:rice :incompatibleWith :potatoes .
:potatoes :incompatibleWith :rice .
:chicken :incompatibleWith :fish .
:fish :incompatibleWith :chicken .
:beef :incompatibleWith :pork .
:pork :incompatibleWith :beef .
# Ingredients
:dish1 a :Dish ; :ingredients (:pork :potatoes) .
:dish2 a :Dish ; :ingredients (:rice :chicken) .
:dish3 a :Dish ; :ingredients (:fish :potatoes) .
:dish4 a :Dish ; :ingredients (:beef :rice) .
?dish :ingredients/rdf:rest*/rdf:first ?ingredient .
?ingredient :incompatibleWith ?incompatibleIngredient .
?dish :ingredients/rdf:rest*/rdf:first/:incompatibleWith ?incompatibleIngredient .