-
Notifications
You must be signed in to change notification settings - Fork 2
Getting Started
Below we present examples for getting started in using FedX.
The examples query data from http://dbpedia.org/ and join it with data from https://www.wikidata.org/. It turns out that these endpoints are currently the most reliable ones that are publicly accessible.
Example query
Retrieve the European Union countries from DBpedia and join it with the GDP data coming from Wikidata
SELECT * WHERE {
?country a yago:WikicatMemberStatesOfTheEuropeanUnion .
?country owl:sameAs ?countrySameAs .
?countrySameAs wdt:P2131 ?gdp .
}
Note that the query is a bit artificial, however, it illustrates quite well the powers of federating different data sources.
The following Java code can be used to execute our example query against the federation.
Config.initialize();
FedXRepository repository = FedXFactory.newFederation()
.withSparqlEndpoint("http://dbpedia.org/sparql")
.withSparqlEndpoint("https://query.wikidata.org/sparql")
.create();
try (RepositoryConnection conn = repository.getConnection()) {
String query =
"PREFIX wd: <http://www.wikidata.org/entity/> "
+ "PREFIX wdt: <http://www.wikidata.org/prop/direct/> "
+ "SELECT * WHERE { "
+ " ?country a <http://dbpedia.org/class/yago/WikicatMemberStatesOfTheEuropeanUnion> ."
+ " ?country <http://www.w3.org/2002/07/owl#sameAs> ?countrySameAs . "
+ " ?countrySameAs wdt:P2131 ?gdp ."
+ "}";
TupleQuery tq = conn.prepareTupleQuery(query);
try (TupleQueryResult tqRes = tq.evaluate()) {
int count = 0;
while (tqRes.hasNext()) {
BindingSet b = tqRes.next();
System.out.println(b);
count++;
}
System.out.println("Results: " + count);
}
}
repository.shutDown();
The full code is also available as source in the "demos" package of the test source folder.
Instead of defining the federation via code, it is also possible to use data configurations. See also FedX-In-Java for more examples.
As simple as that, FedX provides a comprehensive command line interface to get started without any prerequisites. Just start the CLI (cli.bat/cli.sh) and access real SPARQL endpoints from the Linked Open Data cloud.
> ./cli.sh -d examples/DBpediaWikidata.ttl @q examples/q_gettingStarted.txt
See also Using the CLI for detailed documentation.
(c) 2011-2018 fluid Operations AG
(c) 2018-2019 Veritas Technologies LLC
http://www.veritas.com
Last updated: 08.04.2019