Good morning, all.

This might be a newbie question, so please bear with me...

When using an empty URI, e.g. <> or <#>, as the subject of a statement, I 
cannot retrieve that statement from a model using SPARQL.

I'm using Jena 5.6.0. A minimal test case would be:

import static org.junit.jupiter.api.Assertions.assertTrue;

import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.ResultSet;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.ResourceFactory;
import org.apache.jena.rdf.model.StmtIterator;
import org.apache.jena.vocabulary.DCTerms;
import org.junit.jupiter.api.Test;

class PointyBracketsTest {

    @Test
    void test() {
        final Resource r = ResourceFactory.createResource("");
        final Model m = ModelFactory.createDefaultModel();
        m.add(r, DCTerms.title, "A Title");
        // check that the statement is present...
        final StmtIterator iter = m.listStatements();
        while (iter.hasNext()) {
            System.out.println(iter.nextStatement());
        }
        final String query = "SELECT * WHERE {<> ?p ?o}";
        final Query q = QueryFactory.create(query);
        try (QueryExecution qexec = QueryExecutionFactory.create(q, m)) {
            final ResultSet rs = qexec.execSelect();
            assertTrue(rs.hasNext(), "No result found");
        }
    }

}

When I run the test, it prints out ' [, http://purl.org/dc/terms/title, A 
Title] ' and then fails.

I'd expect that the SPARQL query would return the added triple. The test also 
fails when I add a triple with non-empty subject (i. e. <#>) and then query 
with "SELECT * WHERE {<#> ?p ?o}" so it might be that there is something I've 
misunderstood. If I use a full URI, e. g. "urn:example:a-resource", the test 
passes.

Any help is very much appreciated. Thanks in advance!

Best,

Lars


Reply via email to