In this case I need to construct new unique identifiers for instances that do already exist (hence having already a unique id) based on some given rules for constructing derefencable Linked data identifiers.
Since I need to do some text manipulation I need some function libraries in this case coming from
Jena ARQ and from
TopBraid SparqlMotion.
Here is the code:
CONSTRUCT {?subject owl:sameAs ?resource.}
WHERE {
?subject a :City .
?subject rdfs:label ?label.
?subject :startDate ?startDate.
LET (?ns := "http://www.test.org/vocab/terms/"^^xsd:string)
LET (?type := "City"^^xsd:string)
LET (?startdate := smf:cast(?startDate, xsd:string))
LET (?date := smf:regex(?startdate,'-','/'))
LET (?name := smf:regex(?label,' ','_'))
LET (?identifier := fn:concat(?ns, ?type, '/', ?date,'/',?name))
LET (?resource := smf:resource(?identifier))
}The first two LET clauses just assign a string to a variable.
Then the value of the property :startDate is casted to a string also.
Using the regex function the hyphens in the date are replaced by slashes.
Then the value of rdfs:label is taken and the whites in it are replaced by underscores.
Using the concat function all those strings are concatened as string, hence the last line to convert the string to a resource identifier.
Comments