Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

rdf

sparql

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.

like image 992
ron Avatar asked Jul 08 '12 23:07

ron


People also ask

What is a triple in Java?

A triple consisting of three elements. This class is an abstract implementation defining the basic API. It refers to the elements as 'left', 'middle' and 'right'. Subclass implementations may be mutable or immutable. However, there is no restriction on the type of the stored objects that may be stored.

What data type can store different type of values at different times once the program is executed?

A union is a type whose variables are allowed to store different type values at different times during execution.


1 Answers

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.

like image 102
RobV Avatar answered Oct 11 '22 17:10

RobV