From 720940ad1212c35bc439acc5537f3a02f2ae7968 Mon Sep 17 00:00:00 2001 From: Arun Sharma <sharma.arun@gmail.com> Date: Mon, 22 May 2006 10:10:08 +0000 Subject: [PATCH] Restructured query processor --- .../exmo/queryprocessor/QueryProcessor.java | 41 ++++++++++ .../QueryTypeMismatchException.java | 43 +++++++++++ .../exmo/queryprocessor/RDFGraph.java | 26 +++++++ .../inrialpes/exmo/queryprocessor/Result.java | 38 ++++++++++ .../inrialpes/exmo/queryprocessor/Triple.java | 31 ++++++++ .../inrialpes/exmo/queryprocessor/Type.java | 26 +++++++ .../impl/QueryProcessorImpl.java | 74 +++++++++++++++++++ .../exmo/queryprocessor/impl/ResultImpl.java | 43 +++++++++++ 8 files changed, 322 insertions(+) create mode 100644 src/fr/inrialpes/exmo/queryprocessor/QueryProcessor.java create mode 100644 src/fr/inrialpes/exmo/queryprocessor/QueryTypeMismatchException.java create mode 100644 src/fr/inrialpes/exmo/queryprocessor/RDFGraph.java create mode 100644 src/fr/inrialpes/exmo/queryprocessor/Result.java create mode 100644 src/fr/inrialpes/exmo/queryprocessor/Triple.java create mode 100644 src/fr/inrialpes/exmo/queryprocessor/Type.java create mode 100644 src/fr/inrialpes/exmo/queryprocessor/impl/QueryProcessorImpl.java create mode 100644 src/fr/inrialpes/exmo/queryprocessor/impl/ResultImpl.java diff --git a/src/fr/inrialpes/exmo/queryprocessor/QueryProcessor.java b/src/fr/inrialpes/exmo/queryprocessor/QueryProcessor.java new file mode 100644 index 00000000..85344069 --- /dev/null +++ b/src/fr/inrialpes/exmo/queryprocessor/QueryProcessor.java @@ -0,0 +1,41 @@ +/* + * QueryProcessor.java + * + * Created on March 20, 2006, 10:29 AM + * + */ + +package fr.inrialpes.exmo.queryprocessor; + +/** + * + * @author Arun Sharma + */ +public interface QueryProcessor { + /** + * @param query -- The query string + * @param type -- The query type, can be one of SELECT, ASK, CONSTRUCT, or DESCRIBE + * @returns Result, result form depends on type + */ + public Result query(String query, Type type); + + /** + *@param query -- The query string + */ + public Result query(String query); + + /** + *@param query -- The query string + *@returns query results as string + */ + public String queryWithStringResults(String query); + + /** + *@param query -- the query string + *@returns the type of the query + */ + public int getType(String query); + + public void loadOntology(String uri); + +} diff --git a/src/fr/inrialpes/exmo/queryprocessor/QueryTypeMismatchException.java b/src/fr/inrialpes/exmo/queryprocessor/QueryTypeMismatchException.java new file mode 100644 index 00000000..3e602b51 --- /dev/null +++ b/src/fr/inrialpes/exmo/queryprocessor/QueryTypeMismatchException.java @@ -0,0 +1,43 @@ +/* + * QueryTypeMismatchException.java + * + * Created on March 20, 2006, 11:03 AM + * + */ + +package fr.inrialpes.exmo.queryprocessor; + +/** + * + * @author Arun Sharma + */ +public class QueryTypeMismatchException extends Exception { + /** + * Create a new <code>QueryTypeMismatchException</code> with no + * detail mesage. + */ + public QueryTypeMismatchException() { + super(); + } + + /** + * Create a new <code>QueryTypeMismatchException</code> with + * the <code>String</code> specified as an error message. + * + * @param message The error message for the exception. + */ + public QueryTypeMismatchException(String message) { + super(message); + } + + /** + * Create a new <code>QueryTypeMismatchException</code> with + * the <code>String</code> specified as an error message and the + * <code>Throwable</code> that caused this exception to be raised. + * @param message The error message for the exception + * @param cause The cause of the exception + */ + public QueryTypeMismatchException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/src/fr/inrialpes/exmo/queryprocessor/RDFGraph.java b/src/fr/inrialpes/exmo/queryprocessor/RDFGraph.java new file mode 100644 index 00000000..3f775eed --- /dev/null +++ b/src/fr/inrialpes/exmo/queryprocessor/RDFGraph.java @@ -0,0 +1,26 @@ +/* + * RDFGraph.java + * + * Created on March 20, 2006, 11:10 AM + * + */ + +package fr.inrialpes.exmo.queryprocessor; + +/** + * + * @author Arun Sharma + */ +public interface RDFGraph { + /** + *@returns RDF/XML representation of the graph + */ + public String getXML(); + + /**@returns rdf triples + */ + public Triple[] getTriples(); + + //TODO: getN3(); + //TODO: some JenaRepresentation +} diff --git a/src/fr/inrialpes/exmo/queryprocessor/Result.java b/src/fr/inrialpes/exmo/queryprocessor/Result.java new file mode 100644 index 00000000..c5ad0a8b --- /dev/null +++ b/src/fr/inrialpes/exmo/queryprocessor/Result.java @@ -0,0 +1,38 @@ +/* + * Result.java + * + * Created on March 20, 2006, 10:55 AM + * + */ + +package fr.inrialpes.exmo.queryprocessor; + +import java.util.Collection; + +/** + * + * @author Arun Sharma + */ +public interface Result { + /**@returns the type of the result set + */ + public int getType(); + + /**@returns the reslut for ASK type queries + */ + public boolean getAskResult() throws QueryTypeMismatchException; + + /** + *@returns the RDF graph for construct queries + */ + public RDFGraph getConstructResult() throws QueryTypeMismatchException; + + /**@returns a collection set for SELECT queries + */ + public Collection getSelectResult() throws QueryTypeMismatchException; + + /**@returns an XML string for the SELECT queries + */ + public String getSelectResultasXML() throws QueryTypeMismatchException; + +} diff --git a/src/fr/inrialpes/exmo/queryprocessor/Triple.java b/src/fr/inrialpes/exmo/queryprocessor/Triple.java new file mode 100644 index 00000000..1a34eae3 --- /dev/null +++ b/src/fr/inrialpes/exmo/queryprocessor/Triple.java @@ -0,0 +1,31 @@ +/* + * Triple.java + * + * Created on March 20, 2006, 11:12 AM + * + */ + +package fr.inrialpes.exmo.queryprocessor; + +/** + * + * @author Arun Sharma + */ +public interface Triple { + + public String subject = ""; + public String object = ""; + public String predicate = ""; + + public String getObject(); + + public void setObject(String obj); + + public String getPredicate() ; + + public void setPredicate(String pred); + + public String getSubject(); + + public void setSubject(String sub); +} diff --git a/src/fr/inrialpes/exmo/queryprocessor/Type.java b/src/fr/inrialpes/exmo/queryprocessor/Type.java new file mode 100644 index 00000000..928a4c27 --- /dev/null +++ b/src/fr/inrialpes/exmo/queryprocessor/Type.java @@ -0,0 +1,26 @@ +/* + * Type.java + * + * Created on March 20, 2006, 11:20 AM + * + * + */ + +package fr.inrialpes.exmo.queryprocessor; + +/** + * + * @author Arun Sharma + */ +public class Type { + + public static int SELECT = 1; + public static int ASK = 2; + public static int CONSTRUCT = 3; + public static int DESCRIBE = 4; + + /** Creates a new instance of Type */ + public Type() { + } + +} diff --git a/src/fr/inrialpes/exmo/queryprocessor/impl/QueryProcessorImpl.java b/src/fr/inrialpes/exmo/queryprocessor/impl/QueryProcessorImpl.java new file mode 100644 index 00000000..648b883d --- /dev/null +++ b/src/fr/inrialpes/exmo/queryprocessor/impl/QueryProcessorImpl.java @@ -0,0 +1,74 @@ +package fr.inrialpes.exmo.queryprocessor.impl; + +/** + * @author Arun Sharma + */ + +import java.util.Set; +import java.util.HashSet; + +import com.hp.hpl.jena.query.Query; +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.QueryExecutionFactory; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.query.QueryFactory; +import com.hp.hpl.jena.query.QueryExecution; + +import com.hp.hpl.jena.rdf.model.Resource; +import com.hp.hpl.jena.rdf.model.Model; + +import fr.inrialpes.exmo.queryprocessor.Result; +import fr.inrialpes.exmo.queryprocessor.Type; +import fr.inrialpes.exmo.queryprocessor.QueryProcessor; +import fr.inrialpes.exmo.queryprocessor.impl.ResultImpl; +/** + * + * @author Arun Sharma + */ +public class QueryProcessorImpl implements QueryProcessor { + + Model aModel; + ResultSet aResultSet; + Set aResults = new HashSet(); + + public QueryProcessorImpl() { + + } + public QueryProcessorImpl(Model m) { + aModel = m; + } + + public Result query(String query) { + Query myquery = QueryFactory.create(query); + QueryExecution qe = QueryExecutionFactory.create(myquery, aModel); + System.err.println("Executing query: " + query); + aResultSet = qe.execSelect(); + + while (aResultSet.hasNext()) + { + QuerySolution aSolution = aResultSet.nextSolution(); + Resource aRes = (Resource)aSolution.get("uri"); + aResults.add(aRes); + } + + qe.close(); + ResultImpl res = new ResultImpl(aResults); + return res; + } + + public Result query(String query, Type type) { + return null; + } + + public String queryWithStringResults(String query) { + return null; + } + + public int getType(String query) { + return 0; + } + + public void loadOntology(String uri) { + + } +} diff --git a/src/fr/inrialpes/exmo/queryprocessor/impl/ResultImpl.java b/src/fr/inrialpes/exmo/queryprocessor/impl/ResultImpl.java new file mode 100644 index 00000000..77551954 --- /dev/null +++ b/src/fr/inrialpes/exmo/queryprocessor/impl/ResultImpl.java @@ -0,0 +1,43 @@ +/* + * ResultImpl.java + * + * Created on May 21, 2006, 10:49 PM + * + * + */ + +package fr.inrialpes.exmo.queryprocessor.impl; + +import fr.inrialpes.exmo.queryprocessor.*; +import java.util.*; +/** + * + * @author Arun Sharma + */ +public class ResultImpl implements Result{ + + Set aSet = new HashSet(); + + public ResultImpl(Set set) { + aSet = set; + } + + /**@returns a collection set for SELECT queries + */ + public Collection getSelectResult() throws QueryTypeMismatchException { + return aSet; + } + + public int getType() { + return 0; + } + public boolean getAskResult() throws QueryTypeMismatchException { + return false; + } + public RDFGraph getConstructResult() throws QueryTypeMismatchException { + return null; + } + public String getSelectResultasXML() throws QueryTypeMismatchException { + return null; + } +} -- GitLab