From 997c24fdf322469f196b28c6781e94201c147cfa Mon Sep 17 00:00:00 2001 From: Andreas Schwarte Date: Tue, 21 May 2019 13:21:48 +0200 Subject: [PATCH] Fixes for CLI + Getting Started examples using DBpedia and Wikidata Fixes for CLI * fix bundling of logging backend in binary distribution * fix initialization of default prefix Examples * GettingStartedDemo: java example * CLi: ./cli.sh -d examples/DBpediaWikidata.ttl @q examples/q_gettingStarted.txt --- README.md | 6 ++- build.gradle | 2 +- examples/DBpediaWikidata.ttl | 15 ++++++ examples/q_gettingStarted.txt | 7 +++ src/com/fluidops/fedx/CLI.java | 10 ++-- .../fedx/endpoint/EndpointFactory.java | 6 +-- test/demos/GettingStartedDemo.java | 54 +++++++++++++++++++ 7 files changed, 89 insertions(+), 11 deletions(-) create mode 100644 examples/DBpediaWikidata.ttl create mode 100644 examples/q_gettingStarted.txt create mode 100644 test/demos/GettingStartedDemo.java diff --git a/README.md b/README.md index b3e01a1..fc8c4fe 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,11 @@ techniques and is thus a highly scalable solution for practical federated query * Practical applicability & easy integration as a [http://rdf4j.org/](RDF4J) SAIL * Comprehensive CLI for federated query processing from the command line -## Documentation +## Documentation and Getting Started -Refer to the [wiki](https://github.com/VeritasOS/fedx/wiki) for the latest documentation +Refer to the [wiki](https://github.com/VeritasOS/fedx/wiki) for the latest documentation. + +Particularly see [Getting Started](https://github.com/VeritasOS/fedx/wiki/Getting-Started) for the first steps. ## Development diff --git a/build.gradle b/build.gradle index 4577a5e..5f54828 100644 --- a/build.gradle +++ b/build.gradle @@ -294,7 +294,7 @@ task deploy(type: Copy, dependsOn: ["jar"] ) { into "$deployDir" into("lib") { - from configurations.compileClasspath + from configurations.runtimeClasspath } into("lib") { diff --git a/examples/DBpediaWikidata.ttl b/examples/DBpediaWikidata.ttl new file mode 100644 index 0000000..26b5e58 --- /dev/null +++ b/examples/DBpediaWikidata.ttl @@ -0,0 +1,15 @@ +@prefix sd: . +@prefix fedx: . +@prefix foaf: . +@prefix rdf: . +@prefix owl: . + + a sd:Service ; + fedx:store "SPARQLEndpoint"; + sd:endpoint "http://dbpedia.org/sparql" ; + fedx:supportsASKQueries false . + + a sd:Service ; + fedx:store "SPARQLEndpoint"; + sd:endpoint "https://query.wikidata.org/sparql" ; + fedx:supportsASKQueries false . diff --git a/examples/q_gettingStarted.txt b/examples/q_gettingStarted.txt new file mode 100644 index 0000000..15474ba --- /dev/null +++ b/examples/q_gettingStarted.txt @@ -0,0 +1,7 @@ +PREFIX wd: +PREFIX wdt: +SELECT * WHERE { + ?country a . + ?country ?countrySameAs . + ?countrySameAs wdt:P2131 ?gdp . +} \ No newline at end of file diff --git a/src/com/fluidops/fedx/CLI.java b/src/com/fluidops/fedx/CLI.java index 812e454..e19a709 100644 --- a/src/com/fluidops/fedx/CLI.java +++ b/src/com/fluidops/fedx/CLI.java @@ -148,16 +148,16 @@ public void run(String[] args) { if (queries.size()==0) error("No queries specified", true); - // initialize default prefix declarations (if the user did not specify anything) - if (Config.getConfig().getPrefixDeclarations() == null) { - initDefaultPrefixDeclarations(); - } - // setup the federation try { repo = FedXFactory.initializeFederation(endpoints); + // initialize default prefix declarations (if the user did not specify anything) + if (Config.getConfig().getPrefixDeclarations() == null) { + initDefaultPrefixDeclarations(); + } + int count = 1; for (String queryString : queries) { diff --git a/src/com/fluidops/fedx/endpoint/EndpointFactory.java b/src/com/fluidops/fedx/endpoint/EndpointFactory.java index 8baa18e..40b0265 100644 --- a/src/com/fluidops/fedx/endpoint/EndpointFactory.java +++ b/src/com/fluidops/fedx/endpoint/EndpointFactory.java @@ -222,8 +222,8 @@ public static Endpoint loadNativeEndpoint(String location) throws FedXException /** * Utility function to load federation members from a data configuration file. A * data configuration file provides information about federation members in form - * of ntriples. Currently the types NativeStore and SPARQLEndpoint are - * supported. For details please refer to the documentation in + * of turtle. Currently the types NativeStore and SPARQLEndpoint are supported. + * For details please refer to the documentation in * {@link NativeRepositoryInformation} and {@link SPARQLRepositoryInformation}. * * @param dataConfig @@ -239,7 +239,7 @@ public static List loadFederationMembers(File dataConfig) throws FedXE throw new FedXRuntimeException("File does not exist: " + dataConfig.getAbsolutePath()); Model graph = new TreeModel(); - RDFParser parser = Rio.createParser(RDFFormat.N3); + RDFParser parser = Rio.createParser(RDFFormat.TURTLE); RDFHandler handler = new DefaultRDFHandler(graph); parser.setRDFHandler(handler); try (FileReader fr = new FileReader(dataConfig)) { diff --git a/test/demos/GettingStartedDemo.java b/test/demos/GettingStartedDemo.java new file mode 100644 index 0000000..1d3cd6e --- /dev/null +++ b/test/demos/GettingStartedDemo.java @@ -0,0 +1,54 @@ +package demos; + +import org.eclipse.rdf4j.query.BindingSet; +import org.eclipse.rdf4j.query.TupleQuery; +import org.eclipse.rdf4j.query.TupleQueryResult; +import org.eclipse.rdf4j.repository.RepositoryConnection; + +import com.fluidops.fedx.Config; +import com.fluidops.fedx.FedXFactory; +import com.fluidops.fedx.repository.FedXRepository; + +public class GettingStartedDemo { + + public static void main(String[] args) { + + Config.initialize(); + + Config.getConfig().set("debugQueryPlan", "true"); + + 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: " + + "PREFIX wdt: " + + "SELECT * WHERE { " + + " ?country a ." + + " ?country ?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(); + + } + +}