On 8/6/2013 2:54, Rob Vesse wrote:
pss.setIri("node", "_:blankNodeID");
This appears to work better - it now correctly matches the triples in the WHERE clause.

But now the INSERT is not correct. See test case, which creates the "inverse" of a triple involving a blank node. TemplateLib.subst seems to create the new blank node. If there are multiple iterations, it creates a new blank node in each iteration.

Thanks
Holger

package org.topbraid.core.rdf;

import org.junit.Assert;
import org.junit.Test;

import com.hp.hpl.jena.query.ParameterizedSparqlString;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.sparql.core.DatasetImpl;
import com.hp.hpl.jena.sparql.modify.GraphStoreBasic;
import com.hp.hpl.jena.update.GraphStore;
import com.hp.hpl.jena.update.UpdateExecutionFactory;
import com.hp.hpl.jena.update.UpdateProcessor;
import com.hp.hpl.jena.update.UpdateRequest;
import com.hp.hpl.jena.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.RDF;

public class TestPreboundBlankNode {

        @Test
        public void testPreboundBlankNode() {
                
                Model model = ModelFactory.createDefaultModel();
                Resource bnode = model.createResource();
                bnode.addProperty(RDF.type, OWL.Thing);
                
                String str = "INSERT { ?o ?p ?s } WHERE { ?s ?p ?o }";
                ParameterizedSparqlString s = new 
ParameterizedSparqlString(str);
                s.setIri("s", "_:" + bnode.getId());
                UpdateRequest query = s.asUpdate();
                
                GraphStore graphStore = new GraphStoreBasic(new 
DatasetImpl(model));
                UpdateProcessor proc = UpdateExecutionFactory.create(query, 
graphStore);
                proc.execute();

                // We now have 2 triples, but the bnodes are different in the 
new one
                for(Statement st : model.listStatements().toList()) {
                        System.out.println(st);
                }
                
                Assert.assertEquals(1, model.listStatements(null, null, 
bnode).toList().size());
        }
}

Reply via email to