Skip to content

Instantly share code, notes, and snippets.

@jindrichmynarz
Created April 7, 2017 09:44
Show Gist options
  • Save jindrichmynarz/2d5bd070ab765141151c9a82eda9f556 to your computer and use it in GitHub Desktop.
Save jindrichmynarz/2d5bd070ab765141151c9a82eda9f556 to your computer and use it in GitHub Desktop.
Generate 0 to 10 random RDF triples
PREFIX : <http://localhost/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
CONSTRUCT {
?s ?p ?o .
}
WHERE {
# Generate 0 to 10 triples
VALUES ?n { 0 1 2 3 4 5 6 7 8 9 10 }
BIND (if(rand() < 1/3.0, bnode(),
if(rand() < 1/2.0, uuid(), iri(concat(str(:), struuid())))) AS ?s)
BIND (if(rand() < 1/2.0, uuid(), iri(concat(str(:), struuid()))) AS ?p)
BIND (if(rand() < 1/3.0, xsd:decimal,
if(rand() < 1/2.0, xsd:float, xsd:double)) AS ?datatype)
BIND (if(rand() < 1/7.0, struuid(),
if(rand() < 1/6.0, sha512(str(now())),
if(rand() < 1/5.0, strdt(rand() * 100, ?datatype),
if(rand() < 1/4.0, strlang(struuid(), "zxx"),
if(rand() < 1/3.0, xsd:date(now()),
if(rand() < 1/2.0, now(), xsd:boolean(rand() > 0.5))))))) AS ?literal)
BIND (if(rand() < 1/4.0, ?literal,
if(rand() < 1/3.0, bnode(),
if(rand() < 1/2.0, uuid(), iri(concat(str(:), struuid()))))) AS ?o)
FILTER (floor(rand() * 11) < ?n)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment