2017-02-02 2 views
0

저는 SPARQL 초보자이며 Spanish National Library의 끝점을 처리하려고합니다.SPARQL의 Group_concat

prefix bne: <http://datos.bne.es/def/> # base URI for ontology documented at http://datos.bne.es/def/ 
prefix resource: <http://datos.bne.es/resource/> 
select distinct 
?book 
?author 
?title 
?subtitle 
?ISBN 
?publisher 
?date 
?pags 
?size 
?series 
?edition 
?subjectLabel 
where { 
?book a bne:C1003 . 
?book bne:P3001 "Errata Naturae" . 
?book bne:P1011 ?author . 
?book bne:P3002 ?title . 
OPTIONAL { ?book bne:P3013 ?ISBN } 
OPTIONAL { ?book bne:P3001 ?publisher } 
OPTIONAL { ?book bne:P3006 ?date } 
OPTIONAL { ?book bne:P3004 ?pags } 
OPTIONAL { ?book bne:P3007 ?size } 
OPTIONAL { ?book bne:P3016 ?series } 
OPTIONAL { ?book bne:P1004 ?date } 
OPTIONAL { ?book bne:P3017 ?edition } 
OPTIONAL { ?book bne:P3014 ?subtitle } 
OPTIONAL { ?book bne:OP3008 ?subject } 
?subject rdfs:label ?subjectLabel 
} 
limit 50 

그러나 일부 책은 두 개 이상의 과목 바와 같이, SPARQL은 결과를 반복 :

나는 여기있다, 작동하는 코드가 있습니다. 나는 group_concat을 사용하지만, 어떤 이유로 작동하지 않습니다 : 내가 실수를하고 어디

prefix bne: <http://datos.bne.es/def/> # base URI for ontology documented at http://datos.bne.es/def/ 
prefix resource: <http://datos.bne.es/resource/> 
select distinct 
?book 
?author 
?title 
?subtitle 
?ISBN 
?publisher 
?date 
?pags 
?size 
?series 
?edition 
(GROUP_CONCAT(DISTINCT(?subjectLabel); separator="//") as ?subjects) 
where { 
?book a bne:C1003 . 
?book bne:P3001 "Errata Naturae" . 
?book bne:P1011 ?author . 
?book bne:P3002 ?title . 
OPTIONAL { ?book bne:P3013 ?ISBN } 
OPTIONAL { ?book bne:P3001 ?publisher } 
OPTIONAL { ?book bne:P3006 ?date } 
OPTIONAL { ?book bne:P3004 ?pags } 
OPTIONAL { ?book bne:P3007 ?size } 
OPTIONAL { ?book bne:P3016 ?series } 
OPTIONAL { ?book bne:P1004 ?date } 
OPTIONAL { ?book bne:P3017 ?edition } 
OPTIONAL { ?book bne:P3014 ?subtitle } 
OPTIONAL { ?book bne:OP3008 ?subject } 
?subject rdfs:label ?subjectLabel 
} 
limit 50 
group by ?book 
order by ?date 

사람이 알고 있나요?

감사합니다.

편집 :

내가 잘못된 일을했다 : @AKSW 말했듯이, 나는 모든 변수 코드의 말에 그룹에, 또는 선택에 변수를 추가 할 수 있습니다. 나는이 테스트에 대한 코드의 축소 버전 :

PREFIX bne: <http://datos.bne.es/def/> 
PREFIX resource: <http://datos.bne.es/resource/> 

SELECT ?book ?author ?title (GROUP_CONCAT(DISTINCT ?subject ; separator='//') AS ?subjects) 
WHERE 
    { ?book a      bne:C1003 ; 
      bne:P3001    "Errata Naturae" ; 
      bne:P1011    ?author ; 
      bne:P3002    ?title ; 
      bne:OP3008   ?subject 
    } 
#group everything here 
GROUP BY ?book ?author ?title 

@JeenBroekstra, 나는 SPARQL 검사기에서 실행할 때, 그것은 확인을 말한다, 그러나 나는 도서관의 SPARQL endpoint에서 실행하려고 할 때

의견에서 언급 한 바와 같이
Virtuoso 37000 Error SP030: SPARQL compiler, line 6: syntax error at 'GROUP_CONCAT' before '(' 
+0

"여기에서 생산할 수 없다"는 것은 무엇을 의미합니까? GROUP_CONCAT이 작동하지 않습니까? – AKSW

+0

쿼리에서'books'라는 변수를 사용하지 않으면 이상한'group by? books'가 생깁니다 ... –

+0

죄송합니다.«group by-book»대신«group by-books»를 작성했습니다. 그러나 그것은 실수가 아니 었습니다. 위의 group_concat 코드는 오류를 발생시킵니다. – Nikita

답변

0

, 문제가 target endpointVirtuoso, Open Source Edition, v06.01.3127 as of 2011-11-16에서 실행되고 있다는 것입니다), SPARQL 1.1은 아직 확정되지 않은로서, SPARQL에서 GROUP_CONCAT을 지원하지 않았다, 그것은 나에게 오류를 제공합니다.

current version으로 업그레이드하는 것이 좋습니다!

이 Virtuoso 버전에는 sql:group_concat, as documented으로 제공되는 내장 함수가 있으며, 현재 제공 될 수 있습니다.