Jena version: 3.16.0-SNAPSHOT

On Sun, Jul 5, 2020 at 4:22 PM Martynas Jusevičius
<[email protected]> wrote:
>
> Hi,
>
> I came across a situation where I want to carry over a blank node ID
> in a QuerySolutionMap to QueryExecution, to match exact blank node
> resources rather than have them as variables.
>
> I found an old thread by Holger on this topic:
> https://mail-archives.apache.org/mod_mbox/jena-users/201308.mbox/browser
>
> The suggestion was to use <_:LABEL> URI scheme for blank nodes.
> https://jena.apache.org/documentation/query/extension.html#blank-node-labels
>
> Based on that, I tried this logic:
>
>     if (instance.isURIResource()) qsm.add(SPIN.THIS_VAR_NAME, instance);
>     if (instance.isAnon()) qsm.add(SPIN.THIS_VAR_NAME,
> model.createResource("_:" + instance.getId()));
>
> However I'm not getting the results I expect. So I decided to make an
> isolated test:
>
>     @Test
>     public void bnodeQueryTest()
>     {
>         Model model = ModelFactory.createDefaultModel();
>         Resource bnode = model.createResource().addProperty(FOAF.name,
> "whateverest");
>         AnonId id = bnode.getId();
>
>         Query query = QueryFactory.create("SELECT * { ?s ?p ?o }");
>         QuerySolutionMap qsm = new QuerySolutionMap();
>         qsm.add("s", model.createResource("_:" + id));
>
>         try (QueryExecution qex = QueryExecutionFactory.create(query,
> model, qsm))
>         {
>             ResultSet resultSet = qex.execSelect();
>
>             assertTrue(resultSet.hasNext());
>             assertEquals(id, resultSet.next().get("s").asResource().getId());
>         }
>     }
>
> The test fails on assertTrue() because SELECT returns no results.
>
> Is the test flawed? Am I misunderstanding the use of this URI scheme?
> If not, what's the purpose if it cannot match blank nodes in data?
>
> Martynas

Reply via email to