지식그래프(Knowledge Graph)

[SPARQL] GROUP_CONCAT 여러 행을 단일 행으로 출력

송채채 2023. 8. 11. 11:34

예시로 type이 여러개인 개체가 있을 때, SPARQL 쿼리를 출력하면 중복으로 출력됨

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT ?URI ?type ?label ?definition
WHERE { 
    ?URI a ?type ;
        rdfs:label ?label ;
        skos:definition ?definition .
}
1
"address"@en
"index to a location to which communications may be delivered"
2
"address"@en
"index to a location to which communications may be delivered"

같은 URI이지만, type이 2개인 경우 2번 출력됨

 

내가 원하는 형태는, 하나의 셀에 rdfs:Class와 owl:Class가 같이 출력되길 원함

- GROUP_CONCAT

- BIND

- GROUP BY

 

PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>

SELECT ?URI (GROUP_CONCAT(DISTINCT ?type; separator = ", ") AS ?types) ?label ?definition 
WHERE { 
    ?URI a ?type ;
        rdfs:label ?label ;
        skos:definition ?definition .
}
GROUP BY ?URI ?label ?definition
1
"address"@en
"index to a location to which communications may be delivered"
2
"addressing scheme"
"system for allocating addresses to objects"

참고

- joyHong, H_4. SPARQL group_concat

- [SPARQL / RDF] 동일한 URI의 여러 행 데이터를 한 행으로 조회(feat. 카티션 프로덕트/Cartesian Product)

반응형