Question

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:

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top