Skip to content

SPARQL CONSTRUCT: Missing rdf:reifies triple when pre-bound variable is in the reified triple #4129

Description

@HolgerKnublauch

Version

6.2.0

What happened?

There appears to be a problem with the RDF 1.2 annotation syntax in CONSTRUCT queries when one of the variables is pre-bound. The rdf:reifies triple is missing from the output. It works fine for variables that are bound during the WHERE clause.

import java.util.Map;

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.Syntax;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.ResourceFactory;
import org.apache.jena.riot.Lang;
import org.apache.jena.riot.RDFDataMgr;
import org.apache.jena.sparql.core.Var;
import org.apache.jena.sparql.syntax.syntaxtransform.QueryTransformOps;
import org.apache.jena.vocabulary.OWL;

/**
 * Standalone demo: runs a CONSTRUCT query with an RDF-star annotation
 * ({| ... |}) with $this substituted for owl:Thing before execution.
 */
public class RDFStarConstructDemo {

	public static void main(String[] args) {
		String queryString =
				"PREFIX ex: <http://example.com/>\n" +
				"CONSTRUCT {\n" +
				"	$this ex:seeAlso ex:Nothing {| ex:tempTriple true |} .\n" +
				"}\n" +
				"WHERE {\n" +
				"}\n";

		Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);

		query = QueryTransformOps.replaceVars(query, Map.of(
				Var.alloc("this"), ResourceFactory.createResource(OWL.Thing.getURI()).asNode()));

		Model model = ModelFactory.createDefaultModel();

		try (QueryExecution qexec = QueryExecutionFactory.create(query, model)) {
			Model result = qexec.execConstruct();
			RDFDataMgr.write(System.out, result, Lang.TURTLE);
		}
	}
}

Relevant output and stacktrace

PREFIX ex: <http://example.com/>

[ ex:tempTriple  true ] .

<http://www.w3.org/2002/07/owl#Thing>
        ex:seeAlso  ex:Nothing .

Are you interested in making a pull request?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions