NIHVIVO-3452 SPARQL 1.1 for SPARQL page and ingest tools
This commit is contained in:
parent
c800d0c877
commit
fb008e7410
4 changed files with 47 additions and 9 deletions
|
@ -14,7 +14,6 @@ import java.util.Iterator;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
|
@ -33,11 +32,9 @@ import com.hp.hpl.jena.query.DatasetFactory;
|
|||
import com.hp.hpl.jena.query.Query;
|
||||
import com.hp.hpl.jena.query.QueryExecution;
|
||||
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
||||
import com.hp.hpl.jena.query.QueryFactory;
|
||||
import com.hp.hpl.jena.query.QuerySolution;
|
||||
import com.hp.hpl.jena.query.ResultSet;
|
||||
import com.hp.hpl.jena.query.ResultSetFormatter;
|
||||
import com.hp.hpl.jena.query.Syntax;
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
|
@ -51,6 +48,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
|||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.UseAdvancedDataToolsPages;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Ontology;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.SparqlQueryUtils;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -62,8 +60,6 @@ import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
|
|||
*/
|
||||
public class SparqlQueryServlet extends BaseEditController {
|
||||
private static final Log log = LogFactory.getLog(SparqlQueryServlet.class.getName());
|
||||
|
||||
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
|
||||
|
||||
protected static HashMap<String,ResultSetFormat>formatSymbols = new HashMap<String,ResultSetFormat>();
|
||||
static{
|
||||
|
@ -225,7 +221,7 @@ public class SparqlQueryServlet extends BaseEditController {
|
|||
|
||||
QueryExecution qe = null;
|
||||
try{
|
||||
Query query = QueryFactory.create(queryParam, SYNTAX);
|
||||
Query query = SparqlQueryUtils.create(queryParam);
|
||||
qe = QueryExecutionFactory.create(query, dataset);
|
||||
if( query.isSelectType() ){
|
||||
ResultSet results = null;
|
||||
|
|
|
@ -68,6 +68,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
|||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.UseAdvancedDataToolsPages;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Ontology;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.SparqlQueryServlet;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaBaseDao;
|
||||
|
@ -77,6 +78,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaSDBModelMaker;
|
|||
import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaSpecialModelMaker;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
||||
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetup;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.SparqlQueryUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestWorkflowProcessor;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaOutputUtils;
|
||||
|
@ -920,7 +922,7 @@ public class JenaIngestController extends BaseEditController {
|
|||
}
|
||||
}
|
||||
Model tempModel = ModelFactory.createDefaultModel();
|
||||
Query query = QueryFactory.create(queryStr, Syntax.syntaxARQ);
|
||||
Query query = SparqlQueryUtils.create(queryStr);
|
||||
QueryExecution qexec = QueryExecutionFactory.create(query,source);
|
||||
try {
|
||||
qexec.execConstruct(tempModel);
|
||||
|
|
|
@ -2,6 +2,15 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.utils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.hp.hpl.jena.query.Query;
|
||||
import com.hp.hpl.jena.query.QueryFactory;
|
||||
import com.hp.hpl.jena.query.QueryParseException;
|
||||
import com.hp.hpl.jena.query.Syntax;
|
||||
|
||||
/**
|
||||
* Some utility methods that help when dealing with SPARQL queries.
|
||||
*/
|
||||
|
@ -12,6 +21,12 @@ public class SparqlQueryUtils {
|
|||
*/
|
||||
private static final char[] REGEX_SPECIAL_CHARACTERS = "[\\^$.|?*+()]"
|
||||
.toCharArray();
|
||||
|
||||
/**
|
||||
* A list of SPARQL syntaxes to try when parsing queries
|
||||
*/
|
||||
public static final List<Syntax> SUPPORTED_SYNTAXES = Arrays.asList(
|
||||
Syntax.syntaxARQ , Syntax.syntaxSPARQL_11);
|
||||
|
||||
/**
|
||||
* Escape any regex special characters in the string.
|
||||
|
@ -40,5 +55,28 @@ public class SparqlQueryUtils {
|
|||
}
|
||||
return clean.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience method to attempt parsing a query string with various syntaxes
|
||||
* @param queryString
|
||||
* @return Query
|
||||
*/
|
||||
public static Query create(String queryString) {
|
||||
boolean parseSuccess = false;
|
||||
Iterator<Syntax> syntaxIt = SUPPORTED_SYNTAXES.iterator();
|
||||
Query query = null;
|
||||
while (!parseSuccess && syntaxIt.hasNext()) {
|
||||
Syntax syntax = syntaxIt.next();
|
||||
try {
|
||||
query = QueryFactory.create(queryString, syntax);
|
||||
parseSuccess = true;
|
||||
} catch (QueryParseException e) {
|
||||
if (!syntaxIt.hasNext()) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
return query;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue