diff --git a/src/fr/inrialpes/exmo/queryprocessor/QueryProcessor.java b/src/fr/inrialpes/exmo/queryprocessor/QueryProcessor.java new file mode 100644 index 0000000000000000000000000000000000000000..85344069070916263283be777612b488509379be --- /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 0000000000000000000000000000000000000000..3e602b513aee6b3ced6859e49b0ae203b497ef45 --- /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 0000000000000000000000000000000000000000..3f775eedbbf4f4c8bfb5edd929d9a617eed3ded8 --- /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 0000000000000000000000000000000000000000..c5ad0a8bde703ec4bcdd445b92ac0de7e9614db2 --- /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 0000000000000000000000000000000000000000..1a34eae315fe8309c3f6134b5add147abf12ccab --- /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 0000000000000000000000000000000000000000..928a4c2761227e84b6afb3b0db60c58890f5bba7 --- /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 0000000000000000000000000000000000000000..648b883d92cd95586e7bbea3de85177122782f55 --- /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 0000000000000000000000000000000000000000..775519546d4cd43f6ba38b4ccef3e30a4b5249b1 --- /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; + } +}