Should the pseudo IRI notation for blank nodes (i.e., "<_:{anon-id}>"
where {anon-id} is the id of a blank node) work in the INSERT clause
of an UpdateRequest's command? What I'm finding is that where INSERT {
... } WHERE { BIND( ... ) } works, INSERT { ... } WHERE {} fails.
Here's code/output that illustrates this:
Code:
public void test() {
Model m = ModelFactory.createDefaultModel();
Resource a = m.createResource();
Resource b = m.createResource();
Property p = m.createProperty( "urn:p" );
Property q = m.createProperty( "urn:q" );
// Use pseudo IRI in WHERE/BIND for INSERT, succeeds
String bindCommand = "INSERT { ?a <urn:p> ?b } WHERE { " +
"BIND( <_:"+a.getId()+"> as ?a ) "+
"BIND( <_:"+b.getId()+"> as ?b ) }";
// Use pseudo IRI in INSERT directly, fails
String directCommand = "INSERT { <_:"+a.getId()+"> <urn:p>
<_:"+b.getId()+"> } WHERE {}";
// create an update from each command string, clear the model,
run
the update, and check the model
for ( String command : new String[] { bindCommand,
directCommand } ) {
UpdateRequest update = UpdateFactory.create( command );
System.out.println( "\ncommand:\n"+command );
System.out.println( "update:\n"+update );
m.removeAll();
m.add( a, q, b ); // at least one triple, to identify a
and b
UpdateAction.execute( update, m );
System.out.println( "triple added? " + m.contains( a,
p, b ));
m.write( System.out, "N-Triples" );
}
}
Output:
command:
INSERT { ?a <urn:p> ?b } WHERE { BIND( <_:-1ae775c2:13d1823b447:-7ffa>
as ?a ) BIND( <_:-1ae775c2:13d1823b447:-7ff9> as ?b ) }
update:
INSERT {
?a <urn:p> ?b .
}
WHERE
{ BIND(_:b0 AS ?a)
BIND(_:b1 AS ?b)
}
triple added? true /** BIND case works **/
_:AX2dX1ae775c2X3aX13d1823b447X3aXX2dX7ffa <urn:p>
_:AX2dX1ae775c2X3aX13d1823b447X3aXX2dX7ff9 .
_:AX2dX1ae775c2X3aX13d1823b447X3aXX2dX7ffa <urn:q>
_:AX2dX1ae775c2X3aX13d1823b447X3aXX2dX7ff9 .
command:
INSERT { <_:-1ae775c2:13d1823b447:-7ffa> <urn:p>
<_:-1ae775c2:13d1823b447:-7ff9> } WHERE {}
update:
INSERT {
_:b0 <urn:p> _:b1 .
}
WHERE
{ }
triple added? false /** non bind case fails, and the pseudo-IRIs
created new blank nodes! **/
_:AX2dX1ae775c2X3aX13d1823b447X3aXX2dX7ffa <urn:q>
_:AX2dX1ae775c2X3aX13d1823b447X3aXX2dX7ff9 .
_:AX2dX1ae775c2X3aX13d1823b447X3aXX2dX7ff8 <urn:p>
_:AX2dX1ae775c2X3aX13d1823b447X3aXX2dX7ff7 .
Thoughts? Expected behavior?
//JT
--
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/