Skip to content

Commit

Permalink
Added parameters to query multiple end points
Browse files Browse the repository at this point in the history
  • Loading branch information
cgueret committed Apr 17, 2012
1 parent c562cbd commit 1b88b17
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 96 deletions.
12 changes: 12 additions & 0 deletions queries/endpoints.ttl
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,12 @@
@prefix : <http://example.org#>.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix sd: <http://www.w3.org/ns/sparql-service-description#> .


_:dbpedia
a sd:Service;
sd:defaultGraph "http://dbpedia.org";
sd:endpoint "http://dbpedia.org/sparql";
sd:supportedLanguage "virtuoso".
57 changes: 37 additions & 20 deletions src/main/java/nl/vu/queryfinder/ServiceExec.java
Original file line number Original file line Diff line number Diff line change
@@ -1,38 +1,51 @@
package nl.vu.queryfinder; package nl.vu.queryfinder;


import java.io.FileNotFoundException; import java.util.HashMap;
import java.io.IOException; import java.util.Map;


import nl.vu.queryfinder.model.Directory;
import nl.vu.queryfinder.model.Query; import nl.vu.queryfinder.model.Query;
import nl.vu.queryfinder.services.Service; import nl.vu.queryfinder.services.Service;
import nl.vu.queryfinder.services.impl.Copy; import nl.vu.queryfinder.services.impl.Copy;
import nl.vu.queryfinder.services.impl.SPARQLMatcher;


import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options; import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser; import org.apache.commons.cli.PosixParser;
import org.openrdf.repository.RepositoryException;
import org.openrdf.rio.RDFHandlerException;
import org.openrdf.rio.RDFParseException;


public class ServiceExec { public class ServiceExec {
// The parameters given to the component
private final Map<String, String> parameters = new HashMap<String, String>();


/** /**
* @param input * @param input
* @param component * @param component
* @return * @return
* @throws IOException * @throws Exception
* @throws RepositoryException
* @throws RDFParseException
*/ */
public Query process(String input, String component) throws RDFParseException, RepositoryException, IOException { public Query process(String input, String component) throws Exception {
Query inputQuery = new Query(); Query inputQuery = new Query();
inputQuery.loadFrom(input); inputQuery.loadFrom(input);


Service service = new Copy(); // If a component fail, we will return the input query
return service.process(inputQuery); Query outputQuery = inputQuery;

if (component.equals("copy")) {
Service service = new Copy();
outputQuery = service.process(inputQuery);
}

if (component.equals("sparqlmatcher")) {
if (!parameters.containsKey("endpoints"))
throw new Exception("Requiered parameter is missing");
Directory directory = Directory.create(parameters.get("endpoints"));
Service service = new SPARQLMatcher(directory);
outputQuery = service.process(inputQuery);
}

return outputQuery;
} }


/** /**
Expand All @@ -46,15 +59,9 @@ public static void printHelpAndExit(Options options, int exitCode) {


/** /**
* @param args * @param args
* @throws ParseException * @throws Exception
* @throws IOException
* @throws FileNotFoundException
* @throws RDFHandlerException
* @throws RDFParseException
* @throws RepositoryException
*/ */
public static void main(String[] args) throws ParseException, RDFParseException, RDFHandlerException, public static void main(String[] args) throws Exception {
FileNotFoundException, IOException, RepositoryException {
// Compose the options // Compose the options
Options options = new Options(); Options options = new Options();
options.addOption("c", "component", true, "name of the processing component"); options.addOption("c", "component", true, "name of the processing component");
Expand All @@ -78,6 +85,16 @@ public static void main(String[] args) throws ParseException, RDFParseException,
// Create an instance // Create an instance
ServiceExec instance = new ServiceExec(); ServiceExec instance = new ServiceExec();


// Handle parameters
if (line.hasOption("p")) {
String[] params = line.getOptionValue("p").split("'");
for (String param : params) {
String[] keyvalue = param.split("=");
if (keyvalue.length == 2)
instance.parameters.put(keyvalue[0], keyvalue[1]);
}
}

// Process the input query and get the new one // Process the input query and get the new one
Query newQuery = instance.process(line.getOptionValue("i"), line.getOptionValue("c")); Query newQuery = instance.process(line.getOptionValue("i"), line.getOptionValue("c"));


Expand Down
30 changes: 30 additions & 0 deletions src/main/java/nl/vu/queryfinder/model/Directory.java
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
*
*/
package nl.vu.queryfinder.model;

import java.util.ArrayList;

/**
* A directory is a collection of end points
*
* @author Christophe Guéret <christophe.gueret@gmail.com>
*
*/
public class Directory extends ArrayList<EndPoint> {

/**
*
*/
private static final long serialVersionUID = -7897336454073821165L;

/**
* @param fileName
* @return
*/
public static Directory create(String fileName) {
Directory directory = new Directory();

return directory;
}
}
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
package nl.vu.queryfinder.services; package nl.vu.queryfinder.model;


import java.net.URI; import java.net.URI;


Expand Down Expand Up @@ -73,8 +73,8 @@ public String toString() {
* @param uri * @param uri
* @param defaultGraph * @param defaultGraph
*/ */
public EndPoint(URI uri, String defaultGraph, EndPointType type) { public EndPoint(String uri, String defaultGraph, EndPointType type) {
this.uri = uri; this.uri = URI.create(uri);
this.defaultGraph = defaultGraph; this.defaultGraph = defaultGraph;
this.type = type; this.type = type;
} }
Expand Down
Loading

0 comments on commit 1b88b17

Please sign in to comment.