moving a rdf ordered list from a graph to another with sparql

只愿长相守 提交于 2021-01-27 19:01:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!