-1

我使用两个不同的客户端使用相同的 sparql 语句,但两者都没有返回相同的结果。owl 文件采用 rdf 语法,可在此处访问。这是 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 }

我正在使用顶部编织和以下 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

4

1 回答 1

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您的数据中没有任何类型的个人。结果集应该是空的。

于 2013-11-16T21:03:02.803 回答