2017-06-10 57 views
-1

我怎样才能得到书的列表,从维基与SPARQL查询FO例如: PREFIX DBO:http://dbpedia.org/ontology/ PREFIX DBA:???http://dbpedia.org/ontology/
SELECT作者姓名标签?文本?标题?isbn?出版商?literaryGenre?pages WHERE
{?book a dbo:Book。
?book dbo:author?author。 ?book dbo:numberOfPages?pages。 ?book dbp:title?title。 ?book dba:isbn?isbn。 ?book dba:publisher?publisher。我怎样才能得到书的列表,从维基与SPARQL查询

FILTER正则表达式(?title,“java”)。 }

+0

在维基百科? – AKSW

+0

然后,为什么为同一个命名空间'http:// dbpedia.org/ontology /'有两个前缀'dbo'和'dba'?我真的建议理解你在做什么,而且这个查询不会从其他来源复制和粘贴。 – AKSW

回答

1

我想知道您是否知道维基教科书不是维基百科而DBpedia是基于维基百科?

然后,为什么你有两个前缀dbodba为相同的命名空间http://dbpedia.org/ontology/?我真的建议理解你在做什么以及查询是做什么的,而不是从其他来源复制和粘贴。 SPARQL和RDF教程可能会有所帮助,而且官方文档也很有用。

接下来的问题,您SELECT变量?name?label,未在WHERE部分三重模式约束?text?literaryGenre。目前还不清楚你期望得到什么?text。这本书的全文?!当然,这不会存在,请考虑版权。 和?name?title之间的区别是什么?我不认为dbp:title是适当的属性在这里,看到

PREFIX dbo: <http://dbpedia.org/ontology/> 
PREFIX dbp: <http://dbpedia.org/property/> 

SELECT count(*) WHERE { 
?book a dbo:Book ; 
     dbp:title ?title. 
} 

19返回。

我的建议:

PREFIX dbo: <http://dbpedia.org/ontology/> 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 

SELECT * WHERE { 
?book a dbo:Book . 
?book dbo:author ?author . 
OPTIONAL { ?book dbo:numberOfPages ?pages } 
OPTIONAL { ?book dbo:isbn ?isbn } 
OPTIONAL { ?book dbo:publisher ?publisher } 

# get the English title 
?book rdfs:label ?name. 
FILTER(LANGMATCHES(LANG(?name), 'en')) 

# get an English description, but not the text 
?book rdfs:comment ?text . 
FILTER(LANGMATCHES(LANG(?text), 'en')) 

# filter for books whose title contains "java" 
FILTER regex(str(?name) , "java", "i") . 
} 
使用的Virtuoso全文索引断言 bif:contains

更高效:

PREFIX dbo: <http://dbpedia.org/ontology/> 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 

SELECT * WHERE { 
?book a dbo:Book . 
?book dbo:author ?author . 
OPTIONAL { ?book dbo:numberOfPages ?pages } 
OPTIONAL { ?book dbo:isbn ?isbn } 
OPTIONAL { ?book dbo:publisher ?publisher } 

# get the English title 
?book rdfs:label ?name. 
FILTER(LANGMATCHES(LANG(?name), 'en')) 

# get an English description, but not the text 
?book rdfs:comment ?text . 
FILTER(LANGMATCHES(LANG(?text), 'en')) 


# filter for books whose title contains "java" 
?name bif:contains '"java"' 
} 

一本书可能有多个作者RESP。发行商可能会在组合得到重复的行,这里GROUP_BYGROUP_CONCAT是要走的路(由书分组):我想知道你是否知道,维基教科书** **不Wikipedia和DBpedia的基于

PREFIX dbo: <http://dbpedia.org/ontology/> 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 

SELECT ?book (group_concat(DISTINCT ?author; separator = ", ") as ?authors) (group_concat(DISTINCT ?publisher; separator = ", ") as ?publishers) (sample(?pages) as ?numPages) (sample(?isbn_tmp) as ?isbn) WHERE { 
?book a dbo:Book . 
?book dbo:author ?author . 
OPTIONAL { ?book dbo:numberOfPages ?pages } 
OPTIONAL { ?book dbo:isbn ?isbn_tmp } 
OPTIONAL { ?book dbo:publisher ?publisher } 

# get the English title 
?book rdfs:label ?name. 
FILTER(LANGMATCHES(LANG(?name), 'en')) 

# get an English description, but not the text 
?book rdfs:comment ?text . 
FILTER(LANGMATCHES(LANG(?text), 'en')) 


# filter for books whose title contains "java" 
?name bif:contains '"java"' 
} 
GROUP BY ?book 
相关问题