我想知道您是否知道维基教科书不是维基百科而DBpedia是基于维基百科?
然后,为什么你有两个前缀dbo
和dba
为相同的命名空间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_BY
与GROUP_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
在维基百科? – AKSW
然后,为什么为同一个命名空间'http:// dbpedia.org/ontology /'有两个前缀'dbo'和'dba'?我真的建议理解你在做什么,而且这个查询不会从其他来源复制和粘贴。 – AKSW