Skip to content

Commit

Permalink
Fixes for CLI + Getting Started examples using DBpedia and Wikidata
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Andreas Schwarte committed May 21, 2019
1 parent 79ef7bf commit 997c24f
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 11 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ task deploy(type: Copy, dependsOn: ["jar"] ) {
into "$deployDir"

into("lib") {
from configurations.compileClasspath
from configurations.runtimeClasspath
}

into("lib") {
Expand Down
15 changes: 15 additions & 0 deletions examples/DBpediaWikidata.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@prefix sd: <http://www.w3.org/ns/sparql-service-description#> .
@prefix fedx: <http://www.fluidops.com/config/fedx#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .

<http://DBpedia> a sd:Service ;
fedx:store "SPARQLEndpoint";
sd:endpoint "http://dbpedia.org/sparql" ;
fedx:supportsASKQueries false .

<http://Wikidata> a sd:Service ;
fedx:store "SPARQLEndpoint";
sd:endpoint "https://query.wikidata.org/sparql" ;
fedx:supportsASKQueries false .
7 changes: 7 additions & 0 deletions examples/q_gettingStarted.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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 .
}
10 changes: 5 additions & 5 deletions src/com/fluidops/fedx/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
6 changes: 3 additions & 3 deletions src/com/fluidops/fedx/endpoint/EndpointFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -239,7 +239,7 @@ public static List<Endpoint> 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)) {
Expand Down
54 changes: 54 additions & 0 deletions test/demos/GettingStartedDemo.java
Original file line number Diff line number Diff line change
@@ -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: <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();

}

}

0 comments on commit 997c24f

Please sign in to comment.