# (rdf4j-stardog) CONSTRUCT query bringing default contexts

**URL:** <https://community.stardog.com/t/rdf4j-stardog-construct-query-bringing-default-contexts/1573>\
**Category:** Support\
**Created:** [April 5, 2019, 12:46am UTC](https://community.stardog.com/t/rdf4j-stardog-construct-query-bringing-default-contexts/1573 "2019-04-05T00:46:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mhernandeza](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@mhernandeza](https://community.stardog.com/u/mhernandeza)\
**Post date:** [April 5, 2019, 12:46am UTC](https://community.stardog.com/t/rdf4j-stardog-construct-query-bringing-default-contexts/1573/1 "2019-04-05T00:46:46Z")

</div>

Hi all, I am performing the following `CONSTRUCT` query using the RDF4J connector:

```auto
    CONSTRUCT {
    	?s ?p ?o .
    }
    WHERE {
    	VALUES( ?g ){
    		( <http://my-test.com/test/> )
    	}

    	GRAPH ?g {
    		?s ?p ?o .
    	}
    }

```

When performing the exact same query with Stardog Studio no contexts are returned, as expected. However, executing it programmatically retrieves statements that contain a default Stardog context; which, in this case, is not desired.

Is retrieving contexts with CONSTRUCT queries the expected behaviour? If so, can this be disabled in any way to prevent it from happening?

Thanks in advanced for your help

---

<div class="post-metadata">

**Author:** ![stephen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/stephen/32/27_2.png) [@stephen](https://community.stardog.com/u/stephen)\
**Post date:** [April 5, 2019, 6:08pm UTC](https://community.stardog.com/t/rdf4j-stardog-construct-query-bringing-default-contexts/1573/2 "2019-04-05T18:08:58Z")

</div>

Hi,

Could you share a data set that shows what you are experiencing? I recreated with some dummy data and I see what appear to be the right results:

```java
try (RepositoryConnection c = repo.getConnection()) {
            final IRI aGraph = vf.createIRI("http://my-test.com/test/");
            c.begin();
            c.add(vf.createStatement(vf.createIRI("urn:a"), vf.createIRI("urn:b"), vf.createIRI("urn:c")));
            c.add(vf.createStatement(vf.createIRI("urn:d"), vf.createIRI("urn:e"), vf.createIRI("urn:f"), aGraph));
            c.commit();

            final String aQuery = "CONSTRUCT {\n" +
                                          " \t?s ?p ?o .\n" +
                                          " }\n" +
                                          " WHERE {\n" +
                                          " \tVALUES( ?g ){\n" +
                                          " \t\t( <http://my-test.com/test/> )\n" +
                                          " \t}\n" +
                                          "\n" +
                                          " \tGRAPH ?g {\n" +
                                          " \t\t?s ?p ?o .\n" +
                                          " \t}\n" +
                                          " }" ;

            try (GraphQueryResult res = c.prepareGraphQuery(aQuery).evaluate()) {
                while(res.hasNext()) {
                    System.out.println(res.next().toString());
                }
            }
        }

```

```auto
(urn:d, urn:e, urn:f) [tag:stardog:api:context:default]

```

Only the triple I inserted into the graph is displayed. It itself has the default context because `CONSTRUCT { ?s ?p ?o }` dictates that.

---

<div class="post-metadata">

**Author:** ![mhernandeza](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@mhernandeza](https://community.stardog.com/u/mhernandeza)\
**Post date:** [April 5, 2019, 6:36pm UTC](https://community.stardog.com/t/rdf4j-stardog-construct-query-bringing-default-contexts/1573/3 "2019-04-05T18:36:35Z")

</div>

Hi Stephen, thanks for your response.

Your example is exactly the behavior I am encountering, my question revolves around the fact that executing the same query in Stardog Studio returns the requested triples without an added context, not even the default, hence my confusion. Finally, I would just like to know: if this is the expected behavior when using the connector, is there a way to disable it?

---

<div class="post-metadata">

**Author:** ![stephen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/stephen/32/27_2.png) [@stephen](https://community.stardog.com/u/stephen)\
**Post date:** [April 5, 2019, 6:51pm UTC](https://community.stardog.com/t/rdf4j-stardog-construct-query-bringing-default-contexts/1573/4 "2019-04-05T18:51:32Z")

</div>

Stardog doesn't have the notion of a triple with NO context; having the default context is the same idea. The RDF produced by Studio is simply leaving the default context out because it doesn't need to be there.

---

<div class="post-metadata">

**Author:** ![mhernandeza](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@mhernandeza](https://community.stardog.com/u/mhernandeza)\
**Post date:** [April 5, 2019, 9:54pm UTC](https://community.stardog.com/t/rdf4j-stardog-construct-query-bringing-default-contexts/1573/5 "2019-04-05T21:54:15Z")

</div>

Ok, got it.

I was wondering, since this behavior was not present in version 5, and it deviates from the SPARQL standard's expected behavior, is there a chance that a future release might implement a way for users to manage that configuration?

Thanks for your support!

---

<div class="post-metadata">

**Author:** ![stephen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/stephen/32/27_2.png) [@stephen](https://community.stardog.com/u/stephen)\
**Post date:** [April 9, 2019, 7:21pm UTC](https://community.stardog.com/t/rdf4j-stardog-construct-query-bringing-default-contexts/1573/6 "2019-04-09T19:21:09Z")

</div>

Hi again,

As a matter of fact, upon further review this IS a bug, and it will be addressed in the next Stardog release. Thanks for reporting it!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [April 23, 2019, 7:28pm UTC](https://community.stardog.com/t/rdf4j-stardog-construct-query-bringing-default-contexts/1573/7 "2019-04-23T19:28:00Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
