Is there a way to generate UUID's in SPARQL? I'm using the Jena-Fuseki version. I cannot use b-nodes. Thanks!
Jena's ARQ includes a number of built-in functions as SPARQL extensions , including a UUID generator. Many of these functions are listed on the Functions in ARQ page of the ARQ documentation, though uuid
is not. Here's an example usage, with Jena's command line tools. The following query is in a file called query.sparql
.
prefix afn: <http://jena.hpl.hp.com/ARQ/function#>
prefix ex: <http://example.org/>
construct {
?uuid a ex:UUID
}
where {
BIND( afn:uuid() as ?uuid )
}
The arq
command line tool needs an data input, so I created a blank file called data.n3
. The construct
query returns an RDF graph that says the generated UUID is an ex:UUID
.
$ arq --query query.sparql --data data.n3
@prefix afn: <http://jena.hpl.hp.com/ARQ/function#> .
@prefix ex: <http://example.org/> .
<urn:uuid:295322a3-7eab-4e4c-b0a0-ca8ac77f3205>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
ex:UUID .
With a different serialization format:
$ arq --query query.sparql --data data.n3 --results RDF/XML
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:afn="http://jena.hpl.hp.com/ARQ/function#"
xmlns:ex="http://example.org/">
<ex:UUID rdf:about="urn:uuid:10c7c8f0-4154-4bbf-ab0c-c52a4196b804"/>
</rdf:RDF>
实际上,Jena似乎在PREFIX afn上提供了几个功能:< http://jena.hpl.hp.com/ARQ/function# >-afn:uuid()(返回URN)及其对应的afn: struuid()。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.