问题
I have a list in a rdf knowledge graph in a Fuseki dataset. I can get the elements of the list with something like
select ?webpage
where {
graph <http://datamusee.givingsense.eu/graph/webtracks>
{
?track <http://erlangen-crm.org/current/P16_used_specific_object> ?content.
?content rdf:rest*/rdf:first ?webpage .
}
}
but I would like to copy the list from the webtracks graph to another graph
I doen't find how to do it either with an insert or by exporting the data with a construct and then importing it.
回答1:
Based on https://afs.github.io/rdf-lists-sparql#del-all-1
Example data:
:x :p (1 2 3) .
#-- The list start.
INSERT { GRAPH :g { ?a :p ?list } }
WHERE { ?a :p ?list }
;
#-- Copy triples in the list by INSERTing and DELETEing.
#-- ?z is an cons-cell element in the list
DELETE {
?z rdf:first ?head ; rdf:rest ?tail
}
INSERT {
GRAPH :g {
?z rdf:first ?head ; rdf:rest ?tail . }
}
WHERE {
?a :p ?list .
#-- Match each cons-cell in the list in ?z.
?list rdf:rest* ?z .
##-- For each cons-cell, get the head and tail.
?z rdf:first ?head ;
rdf:rest ?tail .
}
;
#-- Finally, optionally, remove the triple with the list.
DELETE { ?a :p ?list }
WHERE { ?a :p ?list }
来源:https://stackoverflow.com/questions/63075028/moving-a-rdf-ordered-list-from-a-graph-to-another-with-sparql