简体   繁体   English

SPARQL查询以检索所有对象和属性

[英]SPARQL query to retrieve all objects and properties

Using the Wine ontology , I want to create SPARQL query so I can retrieve all wines and their properties like the table below - consider that I don't know the properties' names a priori . 使用Wine本体 ,我想创建SPARQL查询,以便我可以检索所有葡萄酒 及其属性,如下表 - 考虑我不知道属性的名称先验

vin                  | rdf:type     | vin:hasMaker      |  vin:hasSugar   | ...
==========================================================================  ...
GaryFarrellMerlot    |  vin:Merlot  | vin:Elyse         |  vin:Dry        | ...
--------------------------------------------------------------------------
ElyseZinfandel       |  vin:Elyse   | vin:GaryFarrell   |  vin:Dry        | ...
...

Can someone give me a hint? 有人能给我一个暗示吗?

-- EDIT - 编辑

It is not possible to have the query result in the format I mentioned, but I can have it this way: 查询结果不可能是我提到的格式,但我可以这样说:

vin                |   property     |  value
=================================================
GaryFarrellMerlot  |   rdf:type     |  vin:Merlot
-------------------------------------------------
GaryFarrellMerlot  |   rdf:hasMaker |  vin:Elyse
-------------------------------------------------
...

With this select (thanks cygri ): 有了这个选择(谢谢cygri ):

SELECT DISTINCT ?wine ?property ?value
WHERE { 
       ?o1 a ?class .
       ?wine a ?o1 .
       ?wine ?property ?value .
}

This will take wines instead of type of wines (Merlot -> GaryFarrellMerlot). 这将采用葡萄酒而不是葡萄酒(Merlot - > GaryFarrellMerlot)。 The only problem is it takes wine but also Winery, Regions, Flavours, etc and I wanted only wines and its properties. 唯一的问题是它需要葡萄酒,还有酒庄,地区,风味等,我只想要葡萄酒及其特性。 Besides, there's no such attribute vin:Merlot rdfs:subClassOf vin:Wine. 此外, 没有这样的属性vin:Merlot rdfs:subClassOf vin:Wine。 Any hint? 任何提示?

You can't. 你不能。 You need to know beforehand what columns you want in your query result. 您需要事先知道查询结果中需要哪些列。

Listing all properties of wines isn't very hard of course: 列出葡萄酒的所有属性当然不是很难:

SELECT DISTINCT ?property
WHERE { 
    ?wine a vin:Wine .
    ?wine ?property ?value .
}

Then you need to write some code that creates the final SPARQL query from the list of results. 然后,您需要编写一些代码,从结果列表中创建最终的SPARQL查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM