ron
ron

Reputation: 1097

How can you change the data type (or some values) in a set of triples?

Say that someone you know accidentally inserted some triples into an RDF database with a datatype of xsd:datetime instead of the proper xsd:dateTime. What's the simplest way to correct this?

I know I can do something like this to find the bad data:

select * where {
  ?s ?p ?o.
  filter (datatype(?o)=xsd:datetime)
}

And I could take those results, fix them up in a text editor, delete the bad ones and insert the good ones... but I have to believe/hope there is an easier way.

Upvotes: 5

Views: 2153

Answers (1)

RobV
RobV

Reputation: 28675

With SPARQL 1.1 you can do this with a SPARQL Update command like so:

DELETE { ?s ?p ?o }
INSERT { ?s ?p ?o2 }
WHERE
{
  ?s ?p ?o .
  FILTER(datatype(?o) = xsd:datetime)
  BIND(STRDT(STR(?o), xsd:dateTime) AS ?o2)
}

Update Commands apply over specific graphs so you may have to issue this mutliple times adding a WITH <graph> to the start of the command for each named graph you need to correct.

Upvotes: 7

Related Questions