相同的sparql没有返回相同的结果

时间:2013-11-16 20:26:07

标签: python rdf sparql owl rdflib

我使用两个不同的客户端使用相同的sparql语句,但两者都没有返回相同的结果。 owl文件采用rdf语法,可以访问here。 这是sparql语句:

PREFIX wo:<http://purl.org/ontology/wo/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?individual where { ?individual rdf:type wo:Class }

我正在使用top braid和以下python程序:

>>> import rdflib
>>> import rdfextras
>>> rdfextras.registerplugins()
>>> g=rdflib.Graph()
>>> g.parse("index.owl")
<Graph identifier=N39ccd52985014f15b2fea90c3ffaedca (<class 'rdflib.graph.Graph'>)>
>>> PREFIX = "PREFIX wo:<http://purl.org/ontology/wo/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
>>> query = "select ?individual where { ?individual rdf:type wo:Class }"
>>> query = PREFIX + query
>>> result_set = g.query(query)
>>> len(result_set)
0

返回0

1 个答案:

答案 0 :(得分:0)

此查询构造一个图形,其中包含wo:Class用作主题,谓词或对象的所有三元组:

PREFIX wo: <http://purl.org/ontology/wo/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
construct { ?s ?p ?o } 
where { 
  { ?s ?p wo:Class . bind( wo:Class as ?o ) } union
  { ?s wo:Class ?o . bind( wo:Class as ?p ) } union
  { wo:Class ?p ?o . bind( wo:Class as ?s ) }
}

我制作了你的数据的本地副本,我得到的结果是(在Turtle中):

@prefix vs:    <http://www.w3.org/2003/06/sw-vocab-status/ns#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix wo:    <http://purl.org/ontology/wo/> .
@prefix owl:   <http://www.w3.org/2002/07/owl#> .

wo:Class  a              owl:Class ;
        rdfs:comment     "A class is a scientific way to group related organisms together, some examples of classes being jellyfish, reptiles and sea urchins. Classes are big groups and contain within them smaller groupings called orders, families, genera and species."@en ;
        rdfs:label       "Class"@en ;
        rdfs:seeAlso     <http://www.bbc.co.uk/nature/class> , <http://en.wikipedia.org/wiki/Class_%28biology%29> ;
        rdfs:subClassOf  wo:TaxonRank ;
        vs:term_status   "testing" .

wo:class  rdfs:range  wo:Class .

您的数据中没有wo:Class类型的个人。结果集应该是空的。