1

some help please.

so far I know how to use Jena with ARQ (command line), load an xml file write the query to a query.rq file and run queries with the following command:

user3358377
  • 145
  • 3
  • 16
  • 1
    You're asking a lot in this question, and it's not clear all of what you need. You can exploit Jena's support for the `service` keyword to query external endpoints, or you could download some LinkedMDB data (if it's available for download) and query it locally. You don't have to use Fuseki here if you don't want to. You could either write some Java code to execute the SPARQL query, or you could load the data into a Fuseki instance and query it that way, or you could use the command line tools that are bundled with Jena. – Joshua Taylor Apr 15 '14 at 19:04

1 Answers1

1

LinkedMDB uses D2R Server to expose a read-only SPARQL Endpoint at http://data.linkedmdb.org/sparql.

If it is conformant, then you can use Jena to query the endpoint:

final String service = "http://data.linkedmdb.org/sparql";
final Query query = QueryFactory.create("SELECT * WHERE { ?s ?p ?o } LIMIT 1");
final QueryExecution exec = QueryExecutionFactory.createServiceRequest(service, query);
final ResultSet resultSet = exec.execSelect();
ResultSetFormatter.out(resultSet);

This works and provides output similar to the following:

------------------------------------------------------------------------------------------------------------------------------------------------------------
| s                                                               | p                                            | o                                       |
============================================================================================================================================================
| <http://data.linkedmdb.org/resource/film_distribution_medium/1> | <http://www.w3.org/2000/01/rdf-schema#label> | "Theatrical (Film Distribution Medium)" |
------------------------------------------------------------------------------------------------------------------------------------------------------------

If you want to extract data and store it in some other model, then Federated Query would be an appropriate way to do so:

final Model localModel = ModelFactory.createDefaultModel();

final Query query = QueryFactory.create(
    "CONSTRUCT { ?s ?p ?o } WHERE {\n"+
    "  SERVICE <http://data.linkedmdb.org/sparql> { SELECT * { ?s ?p ?o . } LIMIT 1 } \n"+
    "}"
);

final QueryExecution exec = QueryExecutionFactory.create(query, localModel);
exec.execConstruct(localModel);
localModel.write(System.out, "N3");

As this output demonstrates, the triples that we built during the construct query were stored in the local model.

<http://data.linkedmdb.org/resource/film_distribution_medium/1>
        <http://www.w3.org/2000/01/rdf-schema#label>
                "Theatrical (Film Distribution Medium)" .

If you wish to use Fuseki as a data storage, rather than a local model, then you can use any number of methods for accessing Fuseki from Java. You'll just need to adjust the structure of your queries appropriately.

For example, in order to modify your own fuseki's data, you would need to execute an update query using the UpdateRemote.execute from the documentation, and that query would need to contain a federated query (SERVICE) as per the second example.

Rob Hall
  • 2,693
  • 16
  • 22