code to run two-stage CONSTRUCTs and SELECTs for list views
This commit is contained in:
parent
aa1ad284bf
commit
bca2dbefcc
7 changed files with 109 additions and 15 deletions
|
@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.dao;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||||
|
@ -31,4 +32,6 @@ public interface ObjectPropertyStatementDao {
|
||||||
int insertNewObjectPropertyStatement(ObjectPropertyStatement objPropertyStmt );
|
int insertNewObjectPropertyStatement(ObjectPropertyStatement objPropertyStmt );
|
||||||
|
|
||||||
public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(String subjectUri, String propertyUri, String query);
|
public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(String subjectUri, String propertyUri, String query);
|
||||||
|
|
||||||
|
public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(String subjectUri, String propertyUri, String query, Set<String> constructQueries);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ package edu.cornell.mannlib.vitro.webapp.dao.filtering;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import net.sf.jga.algorithms.Filter;
|
import net.sf.jga.algorithms.Filter;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
|
@ -89,6 +90,14 @@ class ObjectPropertyStatementDaoFiltering extends BaseFiltering implements Objec
|
||||||
return innerObjectPropertyStatementDao.getObjectPropertyStatementsForIndividualByProperty(subjectUri, propertyUri, query);
|
return innerObjectPropertyStatementDao.getObjectPropertyStatementsForIndividualByProperty(subjectUri, propertyUri, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
// RY What about filtering?
|
||||||
|
public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(
|
||||||
|
String subjectUri, String propertyUri, String query, Set<String> queryStrings) {
|
||||||
|
return innerObjectPropertyStatementDao.getObjectPropertyStatementsForIndividualByProperty(subjectUri, propertyUri, query, queryStrings);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
// // RY What about filtering?
|
// // RY What about filtering?
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
@ -21,6 +22,8 @@ import com.hp.hpl.jena.query.QuerySolution;
|
||||||
import com.hp.hpl.jena.query.QuerySolutionMap;
|
import com.hp.hpl.jena.query.QuerySolutionMap;
|
||||||
import com.hp.hpl.jena.query.ResultSet;
|
import com.hp.hpl.jena.query.ResultSet;
|
||||||
import com.hp.hpl.jena.query.Syntax;
|
import com.hp.hpl.jena.query.Syntax;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
import com.hp.hpl.jena.rdf.model.Property;
|
import com.hp.hpl.jena.rdf.model.Property;
|
||||||
import com.hp.hpl.jena.rdf.model.Resource;
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||||
|
@ -247,6 +250,17 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(
|
||||||
|
String subjectUri,
|
||||||
|
String propertyUri,
|
||||||
|
String queryString) {
|
||||||
|
|
||||||
|
return getObjectPropertyStatementsForIndividualByProperty(
|
||||||
|
subjectUri, propertyUri, null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
/*
|
/*
|
||||||
* SPARQL-based method for getting values related to a single object property.
|
* SPARQL-based method for getting values related to a single object property.
|
||||||
|
@ -255,7 +269,14 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
|
||||||
* custom queries that could request any data in addition to just the object of the statement.
|
* custom queries that could request any data in addition to just the object of the statement.
|
||||||
* However, we do need to get the object of the statement so that we have it to create editing links.
|
* However, we do need to get the object of the statement so that we have it to create editing links.
|
||||||
*/
|
*/
|
||||||
public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(String subjectUri, String propertyUri, String queryString) {
|
public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(
|
||||||
|
String subjectUri,
|
||||||
|
String propertyUri,
|
||||||
|
String queryString,
|
||||||
|
Set<String> constructQueryStrings ) {
|
||||||
|
|
||||||
|
Model constructedModel = constructModelForSelectQueries(
|
||||||
|
subjectUri, propertyUri, constructQueryStrings);
|
||||||
|
|
||||||
log.debug("Query string for object property " + propertyUri + ": " + queryString);
|
log.debug("Query string for object property " + propertyUri + ": " + queryString);
|
||||||
|
|
||||||
|
@ -281,8 +302,13 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
|
||||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
dataset.getLock().enterCriticalSection(Lock.READ);
|
||||||
try {
|
try {
|
||||||
|
|
||||||
QueryExecution qexec = QueryExecutionFactory.create(
|
|
||||||
query, dataset, initialBindings);
|
QueryExecution qexec = (constructedModel == null)
|
||||||
|
? QueryExecutionFactory.create(
|
||||||
|
query, dataset, initialBindings)
|
||||||
|
: QueryExecutionFactory.create(
|
||||||
|
query, constructedModel, initialBindings);
|
||||||
|
|
||||||
ResultSet results = qexec.execSelect();
|
ResultSet results = qexec.execSelect();
|
||||||
|
|
||||||
while (results.hasNext()) {
|
while (results.hasNext()) {
|
||||||
|
@ -297,4 +323,59 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Model constructModelForSelectQueries(String subjectUri,
|
||||||
|
String propertyUri,
|
||||||
|
Set<String> constructQueries) {
|
||||||
|
|
||||||
|
if (constructQueries == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Model constructedModel = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
|
for (String queryString : constructQueries) {
|
||||||
|
|
||||||
|
log.debug("CONSTRUCT query string for object property " +
|
||||||
|
propertyUri + ": " + queryString);
|
||||||
|
|
||||||
|
Query query = null;
|
||||||
|
try {
|
||||||
|
query = QueryFactory.create(queryString, Syntax.syntaxARQ);
|
||||||
|
} catch(Throwable th){
|
||||||
|
log.error("Could not create CONSTRUCT SPARQL query for query " +
|
||||||
|
"string. " + th.getMessage());
|
||||||
|
log.error(queryString);
|
||||||
|
return constructedModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
QuerySolutionMap initialBindings = new QuerySolutionMap();
|
||||||
|
initialBindings.add(
|
||||||
|
"subject", ResourceFactory.createResource(subjectUri));
|
||||||
|
initialBindings.add(
|
||||||
|
"property", ResourceFactory.createResource(propertyUri));
|
||||||
|
|
||||||
|
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
|
||||||
|
DatasetWrapper w = dwf.getDatasetWrapper();
|
||||||
|
Dataset dataset = w.getDataset();
|
||||||
|
dataset.getLock().enterCriticalSection(Lock.READ);
|
||||||
|
try {
|
||||||
|
|
||||||
|
QueryExecution qe = QueryExecutionFactory.create(
|
||||||
|
query, dataset, initialBindings);
|
||||||
|
try {
|
||||||
|
qe.execConstruct(constructedModel);
|
||||||
|
} finally {
|
||||||
|
qe.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
dataset.getLock().leaveCriticalSection();
|
||||||
|
w.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return constructedModel;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,15 +53,16 @@ public class ObjectPropertyStatementDaoSDB extends
|
||||||
String[] graphVars = { "?g", "?h", "?i", "?j" };
|
String[] graphVars = { "?g", "?h", "?i", "?j" };
|
||||||
String query = "CONSTRUCT { \n" +
|
String query = "CONSTRUCT { \n" +
|
||||||
" <" + entity.getURI() + "> ?p ?o . \n" +
|
" <" + entity.getURI() + "> ?p ?o . \n" +
|
||||||
" ?o a ?oType . \n" +
|
// " ?o a ?oType . \n" +
|
||||||
" ?o <" + RDFS.label.getURI() + "> ?oLabel . \n" +
|
" ?o <" + RDFS.label.getURI() + "> ?oLabel . \n" +
|
||||||
" ?o <" + VitroVocabulary.MONIKER + "> ?oMoniker \n" +
|
" ?o <" + VitroVocabulary.MONIKER + "> ?oMoniker \n" +
|
||||||
"} WHERE { GRAPH ?g { \n" +
|
"} WHERE { \n" +
|
||||||
" <" + entity.getURI() + "> ?p ?o \n" +
|
" { <" + entity.getURI() + "> ?p ?o } \n" +
|
||||||
" OPTIONAL { GRAPH ?h { ?o a ?oType } } \n" +
|
// " UNION { <" + entity.getURI() + "> ?p ?o . ?o a ?oType } \n" +
|
||||||
" OPTIONAL { GRAPH ?i { ?o <" + RDFS.label.getURI() + "> ?oLabel } } \n" +
|
" UNION { <" + entity.getURI() + "> ?p ?o . \n" +
|
||||||
" OPTIONAL { GRAPH ?j { ?o <" + VitroVocabulary.MONIKER + "> ?oMoniker } } \n" +
|
" ?o <" + RDFS.label.getURI() + "> ?oLabel } \n" +
|
||||||
"} \n" +
|
" UNION { <" + entity.getURI() + "> ?p ?o . \n " +
|
||||||
|
" ?o <" + VitroVocabulary.MONIKER + "> ?oMoniker } \n" +
|
||||||
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
|
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
|
||||||
"}";
|
"}";
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
|
@ -214,7 +214,7 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
|
||||||
inferenceOms.getTBoxModel().addSubModel(vitroTBoxModel);
|
inferenceOms.getTBoxModel().addSubModel(vitroTBoxModel);
|
||||||
unionOms.getTBoxModel().addSubModel(vitroTBoxModel);
|
unionOms.getTBoxModel().addSubModel(vitroTBoxModel);
|
||||||
|
|
||||||
log.error("Setting up union models and DAO factories");
|
log.info("Setting up union models and DAO factories");
|
||||||
|
|
||||||
// create TBox + ABox union models and set up webapp DAO factories
|
// create TBox + ABox union models and set up webapp DAO factories
|
||||||
OntModel baseUnion = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM,
|
OntModel baseUnion = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM,
|
||||||
|
@ -278,7 +278,7 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
|
||||||
|
|
||||||
ensureEssentialInterfaceData(unionOms.getApplicationMetadataModel(), sce, wadf);
|
ensureEssentialInterfaceData(unionOms.getApplicationMetadataModel(), sce, wadf);
|
||||||
|
|
||||||
//log.info("Setting up namespace mapper");
|
log.info("Setting up namespace mapper");
|
||||||
|
|
||||||
NamespaceMapper namespaceMapper = new NamespaceMapperJena(masterUnion, masterUnion, defaultNamespace);
|
NamespaceMapper namespaceMapper = new NamespaceMapperJena(masterUnion, masterUnion, defaultNamespace);
|
||||||
sce.getServletContext().setAttribute("NamespaceMapper", namespaceMapper);
|
sce.getServletContext().setAttribute("NamespaceMapper", namespaceMapper);
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
|
||||||
String subjectUri = subject.getURI();
|
String subjectUri = subject.getURI();
|
||||||
String propertyUri = op.getURI();
|
String propertyUri = op.getURI();
|
||||||
List<Map<String, String>> statementData =
|
List<Map<String, String>> statementData =
|
||||||
opDao.getObjectPropertyStatementsForIndividualByProperty(subjectUri, propertyUri, getSelectQuery());
|
opDao.getObjectPropertyStatementsForIndividualByProperty(subjectUri, propertyUri, getSelectQuery(), getConstructQueries());
|
||||||
|
|
||||||
/* Apply post-processing */
|
/* Apply post-processing */
|
||||||
postprocess(statementData, wdf);
|
postprocess(statementData, wdf);
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class UncollatedObjectPropertyTemplateModel extends ObjectPropertyTemplat
|
||||||
String subjectUri = subject.getURI();
|
String subjectUri = subject.getURI();
|
||||||
String propertyUri = op.getURI();
|
String propertyUri = op.getURI();
|
||||||
List<Map<String, String>> statementData =
|
List<Map<String, String>> statementData =
|
||||||
opDao.getObjectPropertyStatementsForIndividualByProperty(subjectUri, propertyUri, getSelectQuery());
|
opDao.getObjectPropertyStatementsForIndividualByProperty(subjectUri, propertyUri, getSelectQuery(), getConstructQueries());
|
||||||
|
|
||||||
/* Apply postprocessing */
|
/* Apply postprocessing */
|
||||||
postprocess(statementData, wdf);
|
postprocess(statementData, wdf);
|
||||||
|
|
Loading…
Add table
Reference in a new issue