lost Coder
lost Coder

Reputation: 577

How to query a named graph in Apache Jena Fuseki server

I am laoding a .ttl file into the Jena Fuseki server and instead of the default graph I am using the named graph <http://examples/test>.

/home/user/jena-fuseki-1.1.1/./s-put http://192.168.1.38:3030/ds/data http://example/test /home/user/testdata.ttl

I am able to load the graph and retrieve result using the following command.

/home/user/jena-fuseki-1.1.1/./s-get http://192.168.1.38:3030/ds/data http://example/test

But when I start querying using the s-query command, it is taking the default unnamed graph. How to make the s-query command work on the named graph.

 /home/user/jena-fuseki-1.1.1/./s-query --service http://localhost:3030/ds/query 'SPARQL Query'

This is doing the query on the default unnamed graph. How to make it work on the named graph <http://example/test>?

Upvotes: 3

Views: 3846

Answers (2)

AndyS
AndyS

Reputation: 16700

To access the named graph in a query, use the GRAPH keyword.

SELECT ?subject ?predicate ?object
WHERE {
  GRAPH <http://examples/test>
  {
    ?subject ?predicate ?object
  }
}

http://www.w3.org/TR/sparql11-query/#queryDataset

Upvotes: 6

Jan Martin Keil
Jan Martin Keil

Reputation: 1519

You can specify the named graph in the SPARQL query using a FROM-clause. For example to get all triples in your graph use

SELECT ?subject ?predicate ?object
FROM <http://examples/test>
WHERE {
  ?subject ?predicate ?object
}

A detailed description and further options can be found in the SPARQL 1.1 Query Language specification of W3C.

Upvotes: 4

Related Questions