SPARQL Blank node skolemization with incremental Variable

118 views Asked by At

I am trying to execute Blank node skolemization on a graph using an incremental variable for the identifier, however, the urn:count object is not being updated.

I have the following code so far.

PREFIX :    <http://example.com/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>


####################
# Create Counter Graph #
####################

INSERT DATA {
    graph <urn:counters> {<urn:Example> <urn:count> 1 }
}
;


####################
# Rewrite objects #
####################

DELETE {
    #remove the old value of the counter
    graph <urn:counters> {<urn:Example> <urn:count> ?old}
  ?s ?p ?bnode .
}
INSERT {
    #update the new value of the counter
    graph <urn:counters> {<urn:Example> <urn:count> ?new}
  
  ?s ?p ?iri .
  GRAPH :aliases {
    ?bnode owl:sameAs ?iri .
  }
}
WHERE {
  {
    SELECT ?bnode ?iri ?new ?old
    WHERE {

      {        
        SELECT DISTINCT ?bnode
        WHERE {
          [] ?p ?bnode .
          FILTER isBlank(?bnode)
        }
      } 
                # retrieve the counter
    graph <urn:counters> {<urn:Example> <urn:count> ?old}
    
    
    # compute the new value
    bind(?old+1 as ?new)  
    
    
    #construct the IRI
    bind(IRI(concat("http://example.org/item/", str(?old))) as ?iri) 
    }
  }
    ?s ?p ?bnode .
}
;

Which produces the following output.

<#TripleMap1>
        rr:logicalTable        <http://example.org/item/1> ;
        rr:predicateObjectMap  <http://example.org/item/1> ;
        rr:subjectMap          <http://example.org/item/1> .

However I would like the output as follows.

<#TripleMap1>
        rr:logicalTable        <http://example.org/item/1> ;
        rr:predicateObjectMap  <http://example.org/item/2> ;
        rr:subjectMap          <http://example.org/item/3> .

And the input graph is as follows.

@prefix rr:    <http://www.w3.org/ns/r2rml#> .
<#TripleMap1>
        rr:logicalTable        [] ;
        rr:predicateObjectMap  [];
        rr:subjectMap []; 

Any help would be appreciated.

0

There are 0 answers