Adding timing info for CONSTRUCT vs SELECT on EntityPubCount, EntityGrantCount and CoPIGrantCount. Adding CONSTRUCT queries for PersonGrantCount
This commit is contained in:
parent
60f6b7ef16
commit
ac6baffa53
10 changed files with 284 additions and 21 deletions
|
@ -32,6 +32,8 @@ public class CoPIGrantCountConstructQueryRunner {
|
||||||
|
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
|
|
||||||
|
private long before, after;
|
||||||
|
|
||||||
private Log log = LogFactory.getLog(CoPIGrantCountConstructQueryRunner.class.getName());
|
private Log log = LogFactory.getLog(CoPIGrantCountConstructQueryRunner.class.getName());
|
||||||
|
|
||||||
|
|
||||||
|
@ -181,6 +183,8 @@ public class CoPIGrantCountConstructQueryRunner {
|
||||||
|
|
||||||
Model constructedModel = ModelFactory.createDefaultModel();
|
Model constructedModel = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
|
before = System.currentTimeMillis();
|
||||||
|
|
||||||
for (String queryString : constructQueries) {
|
for (String queryString : constructQueries) {
|
||||||
|
|
||||||
log.debug("CONSTRUCT query string : " + queryString);
|
log.debug("CONSTRUCT query string : " + queryString);
|
||||||
|
@ -204,6 +208,8 @@ public class CoPIGrantCountConstructQueryRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
after = System.currentTimeMillis();
|
||||||
|
log.info("Time taken to execute the CONSTRUCT queries is in milliseconds: " + (after - before) );
|
||||||
|
|
||||||
return constructedModel;
|
return constructedModel;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import com.hp.hpl.jena.iri.IRI;
|
import com.hp.hpl.jena.iri.IRI;
|
||||||
import com.hp.hpl.jena.iri.IRIFactory;
|
import com.hp.hpl.jena.iri.IRIFactory;
|
||||||
|
@ -50,12 +51,14 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CoPIData> {
|
||||||
|
|
||||||
private Model dataSource;
|
private Model dataSource;
|
||||||
|
|
||||||
private Log log;
|
private Log log = LogFactory.getLog(CoPIGrantCountQueryRunner.class.getName());
|
||||||
|
|
||||||
private UniqueIDGenerator nodeIDGenerator;
|
private UniqueIDGenerator nodeIDGenerator;
|
||||||
|
|
||||||
private UniqueIDGenerator edgeIDGenerator;
|
private UniqueIDGenerator edgeIDGenerator;
|
||||||
|
|
||||||
|
private long before, after;
|
||||||
|
|
||||||
private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME = ""
|
private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME = ""
|
||||||
+ "OPTIONAL {"
|
+ "OPTIONAL {"
|
||||||
+ " ?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
+ " ?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
||||||
|
@ -84,7 +87,7 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CoPIData> {
|
||||||
|
|
||||||
this.egoURI = egoURI;
|
this.egoURI = egoURI;
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
this.log = log;
|
// this.log = log;
|
||||||
|
|
||||||
this.nodeIDGenerator = new UniqueIDGenerator();
|
this.nodeIDGenerator = new UniqueIDGenerator();
|
||||||
this.edgeIDGenerator = new UniqueIDGenerator();
|
this.edgeIDGenerator = new UniqueIDGenerator();
|
||||||
|
@ -315,8 +318,7 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CoPIData> {
|
||||||
+ "} "
|
+ "} "
|
||||||
+ "} ";
|
+ "} ";
|
||||||
|
|
||||||
log.debug("COPI QUERY - " + sparqlQuery);
|
// log.debug("COPI QUERY - " + sparqlQuery);
|
||||||
|
|
||||||
//System.out.println("\n\nCOPI QUERY - " + sparqlQuery + "\n\n");
|
//System.out.println("\n\nCOPI QUERY - " + sparqlQuery + "\n\n");
|
||||||
|
|
||||||
return sparqlQuery;
|
return sparqlQuery;
|
||||||
|
@ -351,8 +353,14 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CoPIData> {
|
||||||
throw new MalformedQueryParametersException("URI parameter is either null or empty.");
|
throw new MalformedQueryParametersException("URI parameter is either null or empty.");
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultSet resultSet = executeQuery(generateEgoCoPIquery(this.egoURI),
|
before = System.currentTimeMillis();
|
||||||
this.dataSource);
|
|
||||||
|
ResultSet resultSet = executeQuery(generateEgoCoPIquery(this.egoURI), this.dataSource);
|
||||||
|
|
||||||
|
after = System.currentTimeMillis();
|
||||||
|
|
||||||
|
log.info("Time taken to execute the SELECT queries is in milliseconds: " + (after - before) );
|
||||||
|
|
||||||
return createQueryResult(resultSet);
|
return createQueryResult(resultSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,6 +402,8 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CoPIData> {
|
||||||
|
|
||||||
Set<CoPIEdge> edges = new HashSet<CoPIEdge>();
|
Set<CoPIEdge> edges = new HashSet<CoPIEdge>();
|
||||||
|
|
||||||
|
before = System.currentTimeMillis();
|
||||||
|
|
||||||
while (resultSet.hasNext()) {
|
while (resultSet.hasNext()) {
|
||||||
QuerySolution solution = resultSet.nextSolution();
|
QuerySolution solution = resultSet.nextSolution();
|
||||||
|
|
||||||
|
@ -529,6 +539,9 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CoPIData> {
|
||||||
edgeUniqueIdentifierToVO);
|
edgeUniqueIdentifierToVO);
|
||||||
|
|
||||||
|
|
||||||
|
after = System.currentTimeMillis();
|
||||||
|
log.info("Time taken to iterate through the ResultSet of SELECT queries is in milliseconds: " + (after - before) );
|
||||||
|
|
||||||
return new CoPIData(egoNode, nodes, edges);
|
return new CoPIData(egoNode, nodes, edges);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,8 @@ public class EntityPublicationCountConstructQueryRunner {
|
||||||
|
|
||||||
private Log log = LogFactory.getLog(EntityPublicationCountConstructQueryRunner.class.getName());
|
private Log log = LogFactory.getLog(EntityPublicationCountConstructQueryRunner.class.getName());
|
||||||
|
|
||||||
|
private long before, after;
|
||||||
|
|
||||||
public EntityPublicationCountConstructQueryRunner(String egoURI, DataSource dataSource, Log log){
|
public EntityPublicationCountConstructQueryRunner(String egoURI, DataSource dataSource, Log log){
|
||||||
this.egoURI = egoURI;
|
this.egoURI = egoURI;
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
|
@ -188,6 +190,8 @@ public class EntityPublicationCountConstructQueryRunner {
|
||||||
|
|
||||||
Model constructedModel = ModelFactory.createDefaultModel();
|
Model constructedModel = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
|
before = System.currentTimeMillis();
|
||||||
|
|
||||||
for (String queryString : constructQueries) {
|
for (String queryString : constructQueries) {
|
||||||
|
|
||||||
log.debug("CONSTRUCT query string : " + queryString);
|
log.debug("CONSTRUCT query string : " + queryString);
|
||||||
|
@ -212,6 +216,9 @@ public class EntityPublicationCountConstructQueryRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
after = System.currentTimeMillis();
|
||||||
|
log.info("Time taken to execute the CONSTRUCT queries is in milliseconds: " + (after - before) );
|
||||||
// constructedModel.write(System.out);
|
// constructedModel.write(System.out);
|
||||||
return constructedModel;
|
return constructedModel;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ public class EntityPublicationCountQueryRunner implements QueryRunner<Entity> {
|
||||||
private String entityURI;
|
private String entityURI;
|
||||||
private Model dataSource;
|
private Model dataSource;
|
||||||
private Log log = LogFactory.getLog(EntityPublicationCountQueryRunner.class.getName());
|
private Log log = LogFactory.getLog(EntityPublicationCountQueryRunner.class.getName());
|
||||||
|
private long before, after;
|
||||||
|
|
||||||
private static final String SPARQL_QUERY_COMMON_SELECT_CLAUSE = ""
|
private static final String SPARQL_QUERY_COMMON_SELECT_CLAUSE = ""
|
||||||
+ " (str(?Person) as ?personLit) "
|
+ " (str(?Person) as ?personLit) "
|
||||||
|
@ -85,6 +86,8 @@ public class EntityPublicationCountQueryRunner implements QueryRunner<Entity> {
|
||||||
Map<String, SubEntity> subentityURLToVO = new HashMap<String, SubEntity>();
|
Map<String, SubEntity> subentityURLToVO = new HashMap<String, SubEntity>();
|
||||||
Map<String, SubEntity> personURLToVO = new HashMap<String, SubEntity>();
|
Map<String, SubEntity> personURLToVO = new HashMap<String, SubEntity>();
|
||||||
|
|
||||||
|
before = System.currentTimeMillis();
|
||||||
|
|
||||||
while (resultSet.hasNext()) {
|
while (resultSet.hasNext()) {
|
||||||
|
|
||||||
QuerySolution solution = resultSet.nextSolution();
|
QuerySolution solution = resultSet.nextSolution();
|
||||||
|
@ -202,7 +205,10 @@ public class EntityPublicationCountQueryRunner implements QueryRunner<Entity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: return non-null value
|
//TODO: return non-null value
|
||||||
log.info("Returning entity that contains the following set of subentities: "+entity.getSubEntities().toString());
|
// log.info("Returning entity that contains the following set of subentities: "+entity.getSubEntities().toString());
|
||||||
|
after = System.currentTimeMillis();
|
||||||
|
log.info("Time taken to iterate through the ResultSet of SELECT queries is in milliseconds: " + (after - before) );
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,8 +290,14 @@ public class EntityPublicationCountQueryRunner implements QueryRunner<Entity> {
|
||||||
"URL parameter is either null or empty.");
|
"URL parameter is either null or empty.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
before = System.currentTimeMillis();
|
||||||
|
|
||||||
ResultSet resultSet = executeQuery(this.entityURI, this.dataSource);
|
ResultSet resultSet = executeQuery(this.entityURI, this.dataSource);
|
||||||
|
|
||||||
|
after = System.currentTimeMillis();
|
||||||
|
|
||||||
|
log.info("Time taken to execute the SELECT queries is in milliseconds: " + (after - before) );
|
||||||
|
|
||||||
return createJavaValueObjects(resultSet);
|
return createJavaValueObjects(resultSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -283,7 +283,7 @@ public class EntityPublicationCountRequestHandler implements
|
||||||
yearPubCount.add(currentPubYear);
|
yearPubCount.add(currentPubYear);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("entityJson.getLabel() : " + entityJson.getLabel() + " subOrganizationTypesResult " + subOrganizationTypesResult.toString());
|
//log.info("entityJson.getLabel() : " + entityJson.getLabel() + " subOrganizationTypesResult " + subOrganizationTypesResult.toString());
|
||||||
|
|
||||||
entityJson.setYearToActivityCount(yearPubCount);
|
entityJson.setYearToActivityCount(yearPubCount);
|
||||||
entityJson.getOrganizationType().addAll(subOrganizationTypesResult.get(entityJson.getLabel()));
|
entityJson.getOrganizationType().addAll(subOrganizationTypesResult.get(entityJson.getLabel()));
|
||||||
|
|
|
@ -99,7 +99,7 @@ public class EntitySubOrganizationTypesQueryRunner implements QueryRunner<Map<St
|
||||||
+ "}";
|
+ "}";
|
||||||
|
|
||||||
|
|
||||||
log.info("\n SubOrganizationTypesQuery :" + sparqlQuery);
|
// log.info("\n SubOrganizationTypesQuery :" + sparqlQuery);
|
||||||
|
|
||||||
return sparqlQuery;
|
return sparqlQuery;
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ public class EntitySubOrganizationTypesQueryRunner implements QueryRunner<Map<St
|
||||||
// System.out.println("\n\nSub Organization Label Types Size --> " + subOrganizationLabelToTypes.size());
|
// System.out.println("\n\nSub Organization Label Types Size --> " + subOrganizationLabelToTypes.size());
|
||||||
// System.out.println("\n\nPeople Label Types Size --> " + personLabelToTypes.size());
|
// System.out.println("\n\nPeople Label Types Size --> " + personLabelToTypes.size());
|
||||||
|
|
||||||
log.info("Sub Organization Label Types Size : " + subEntityLabelToTypes.size());
|
// log.info("Sub Organization Label Types Size : " + subEntityLabelToTypes.size());
|
||||||
|
|
||||||
return subEntityLabelToTypes;
|
return subEntityLabelToTypes;
|
||||||
//return (subOrganizationLabelToTypes.size() != 0 )? subOrganizationLabelToTypes : personLabelToTypes ;
|
//return (subOrganizationLabelToTypes.size() != 0 )? subOrganizationLabelToTypes : personLabelToTypes ;
|
||||||
|
|
|
@ -32,6 +32,8 @@ public class EntityGrantCountConstructQueryRunner {
|
||||||
|
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
|
|
||||||
|
private long before, after;
|
||||||
|
|
||||||
private Log log = LogFactory.getLog(EntityGrantCountConstructQueryRunner.class.getName());
|
private Log log = LogFactory.getLog(EntityGrantCountConstructQueryRunner.class.getName());
|
||||||
|
|
||||||
public EntityGrantCountConstructQueryRunner(String egoURI, DataSource dataSource, Log log){
|
public EntityGrantCountConstructQueryRunner(String egoURI, DataSource dataSource, Log log){
|
||||||
|
@ -267,6 +269,8 @@ public class EntityGrantCountConstructQueryRunner {
|
||||||
|
|
||||||
Model constructedModel = ModelFactory.createDefaultModel();
|
Model constructedModel = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
|
before = System.currentTimeMillis();
|
||||||
|
|
||||||
for (String queryString : constructQueries) {
|
for (String queryString : constructQueries) {
|
||||||
|
|
||||||
log.debug("CONSTRUCT query string : " + queryString);
|
log.debug("CONSTRUCT query string : " + queryString);
|
||||||
|
@ -291,8 +295,12 @@ public class EntityGrantCountConstructQueryRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
log.debug("Statements for constructed model of EntityGrantCount : "+ constructedModel.listStatements().toString());
|
|
||||||
// constructedModel.write(System.out);
|
after = System.currentTimeMillis();
|
||||||
|
|
||||||
|
// log.debug("Statements for constructed model of EntityGrantCount : "+ constructedModel.listStatements().toString());
|
||||||
|
log.info("Time taken to execute the CONSTRUCT queries is in milliseconds: " + (after - before) );
|
||||||
|
// constructedModel.write(System.out);
|
||||||
return constructedModel;
|
return constructedModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ public class EntityGrantCountQueryRunner implements QueryRunner<Entity> {
|
||||||
private String entityURI;
|
private String entityURI;
|
||||||
private Model dataSource;
|
private Model dataSource;
|
||||||
private Log log = LogFactory.getLog(EntityGrantCountQueryRunner.class.getName());
|
private Log log = LogFactory.getLog(EntityGrantCountQueryRunner.class.getName());
|
||||||
|
private long before, after;
|
||||||
|
|
||||||
|
|
||||||
private static final String SPARQL_QUERY_COMMON_SELECT_CLAUSE = "SELECT "
|
private static final String SPARQL_QUERY_COMMON_SELECT_CLAUSE = "SELECT "
|
||||||
|
@ -110,6 +111,8 @@ public class EntityGrantCountQueryRunner implements QueryRunner<Entity> {
|
||||||
Map<String, SubEntity> subentityURLToVO = new HashMap<String, SubEntity>();
|
Map<String, SubEntity> subentityURLToVO = new HashMap<String, SubEntity>();
|
||||||
Map<String, SubEntity> personURLToVO = new HashMap<String, SubEntity>();
|
Map<String, SubEntity> personURLToVO = new HashMap<String, SubEntity>();
|
||||||
|
|
||||||
|
before = System.currentTimeMillis();
|
||||||
|
|
||||||
while (resultSet.hasNext()) {
|
while (resultSet.hasNext()) {
|
||||||
// log.info("Checking whether EntityGrantCount produced any resultset against the Constructed Model");
|
// log.info("Checking whether EntityGrantCount produced any resultset against the Constructed Model");
|
||||||
QuerySolution solution = resultSet.nextSolution();
|
QuerySolution solution = resultSet.nextSolution();
|
||||||
|
@ -228,6 +231,8 @@ public class EntityGrantCountQueryRunner implements QueryRunner<Entity> {
|
||||||
entity = new Entity(this.entityURI, "no-label");
|
entity = new Entity(this.entityURI, "no-label");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
after = System.currentTimeMillis();
|
||||||
|
log.info("Time taken to iterate through the ResultSet of SELECT queries is in milliseconds: " + (after - before) );
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,8 +327,14 @@ public class EntityGrantCountQueryRunner implements QueryRunner<Entity> {
|
||||||
"URL parameter is either null or empty.");
|
"URL parameter is either null or empty.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
before = System.currentTimeMillis();
|
||||||
|
|
||||||
ResultSet resultSet = executeQuery(this.entityURI, this.dataSource);
|
ResultSet resultSet = executeQuery(this.entityURI, this.dataSource);
|
||||||
|
|
||||||
|
after = System.currentTimeMillis();
|
||||||
|
|
||||||
|
log.info("Time taken to execute the SELECT queries is in milliseconds: " + (after - before) );
|
||||||
|
|
||||||
return createJavaValueObjects(resultSet);
|
return createJavaValueObjects(resultSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -279,7 +279,7 @@ public class EntityGrantCountRequestHandler implements
|
||||||
yearGrantCount.add(currentGrantYear);
|
yearGrantCount.add(currentGrantYear);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("entityJson.getLabel() : " + entityJson.getLabel() + " subOrganizationTypesResult " + subOrganizationTypesResult.toString());
|
// log.info("entityJson.getLabel() : " + entityJson.getLabel() + " subOrganizationTypesResult " + subOrganizationTypesResult.toString());
|
||||||
|
|
||||||
entityJson.setYearToActivityCount(yearGrantCount);
|
entityJson.setYearToActivityCount(yearGrantCount);
|
||||||
entityJson.getOrganizationType().addAll(subOrganizationTypesResult.get(entityJson.getLabel()));
|
entityJson.getOrganizationType().addAll(subOrganizationTypesResult.get(entityJson.getLabel()));
|
||||||
|
|
|
@ -0,0 +1,206 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.persongrantcount;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.iri.IRI;
|
||||||
|
import com.hp.hpl.jena.iri.IRIFactory;
|
||||||
|
import com.hp.hpl.jena.iri.Violation;
|
||||||
|
import com.hp.hpl.jena.query.DataSource;
|
||||||
|
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.Syntax;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
|
||||||
|
|
||||||
|
public class PersonGrantCountConstructQueryRunner {
|
||||||
|
|
||||||
|
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
|
||||||
|
|
||||||
|
private String egoURI;
|
||||||
|
|
||||||
|
private DataSource dataSource;
|
||||||
|
|
||||||
|
private Log log = LogFactory.getLog(PersonGrantCountConstructQueryRunner.class.getName());
|
||||||
|
|
||||||
|
public PersonGrantCountConstructQueryRunner(String egoURI, DataSource dataSource, Log log){
|
||||||
|
this.egoURI = egoURI;
|
||||||
|
this.dataSource = dataSource;
|
||||||
|
//this.log = log;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String generateConstructQueryForInvestigatorLabel(String queryURI) {
|
||||||
|
|
||||||
|
String sparqlQuery =
|
||||||
|
"CONSTRUCT { "
|
||||||
|
+ "<"+queryURI+ "> rdfs:label ?investigatorLabel ."
|
||||||
|
+ "}"
|
||||||
|
+ "WHERE {"
|
||||||
|
+ "<"+queryURI+ "> rdfs:label ?investigatorLabel "
|
||||||
|
+ "}";
|
||||||
|
|
||||||
|
return sparqlQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String generateConstructQueryForInvestigatorGrants(String queryURI){
|
||||||
|
|
||||||
|
String sparqlQuery = ""
|
||||||
|
+ "CONSTRUCT { "
|
||||||
|
+ "<"+queryURI+ "> ?preboundProperty ?Role . "
|
||||||
|
+ "?Role core:roleIn ?Grant ."
|
||||||
|
+ "?Grant rdfs:label ?GrantLabel "
|
||||||
|
+ "} "
|
||||||
|
+ "WHERE { "
|
||||||
|
+ "<"+queryURI+ "> ?preboundProperty ?Role . "
|
||||||
|
+ "?Role core:roleIn ?Grant ."
|
||||||
|
+ "?Grant rdfs:label ?GrantLabel "
|
||||||
|
+ "} ";
|
||||||
|
|
||||||
|
return sparqlQuery;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private String generateConstructQueryForDateTimeValueofRole(String queryURI){
|
||||||
|
|
||||||
|
String sparqlQuery =
|
||||||
|
"CONSTRUCT { "
|
||||||
|
+ "<"+queryURI+ "> ?preboundProperty ?Role . "
|
||||||
|
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
||||||
|
+ "?dateTimeIntervalValue core:start ?startDate . "
|
||||||
|
+ "?startDate core:dateTime ?startDateTimeValue . "
|
||||||
|
+ "?dateTimeIntervalValue core:end ?endDate . "
|
||||||
|
+ "?endDate core:dateTime ?endDateTimeValue . "
|
||||||
|
+ "}"
|
||||||
|
+ "WHERE { "
|
||||||
|
+ "{"
|
||||||
|
+ "<"+queryURI+ "> ?preboundProperty ?Role . "
|
||||||
|
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
||||||
|
+ "?dateTimeIntervalValue core:start ?startDate . "
|
||||||
|
+ "?startDate core:dateTime ?startDateTimeValue . "
|
||||||
|
+ "} UNION "
|
||||||
|
+ "{"
|
||||||
|
+ "<"+queryURI+ "> ?preboundProperty ?Role . "
|
||||||
|
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
|
||||||
|
+ "?dateTimeIntervalValue core:end ?endDate . "
|
||||||
|
+ "?endDate core:dateTime ?endDateTimeValue . "
|
||||||
|
+ "}"
|
||||||
|
+ "}";
|
||||||
|
|
||||||
|
return sparqlQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String generateConstructQueryForDateTimeValueofGrant(String queryURI){
|
||||||
|
|
||||||
|
String sparqlQuery =
|
||||||
|
"CONSTRUCT { "
|
||||||
|
+ "<"+queryURI+ "> ?preboundProperty ?Role . "
|
||||||
|
+ "?Role core:roleIn ?Grant ."
|
||||||
|
+ "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
|
||||||
|
+ "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
|
||||||
|
+ "?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
|
||||||
|
+ "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
|
||||||
|
+ "?endDateForGrant core:dateTime ?endDateTimeValueForGrant . "
|
||||||
|
+ "}"
|
||||||
|
+ "WHERE { "
|
||||||
|
+ "{"
|
||||||
|
+ "<"+queryURI+ "> ?preboundProperty ?Role . "
|
||||||
|
+ "?Role core:roleIn ?Grant ."
|
||||||
|
+ "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
|
||||||
|
+ "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
|
||||||
|
+ "?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
|
||||||
|
+ "} UNION "
|
||||||
|
+ "{"
|
||||||
|
+ "<"+queryURI+ "> ?preboundProperty ?Role . "
|
||||||
|
+ "?Role core:roleIn ?Grant ."
|
||||||
|
+ "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
|
||||||
|
+ "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
|
||||||
|
+ "?endDateForGrant core:dateTime ?endDateTimeValueForGrant . "
|
||||||
|
+ "}"
|
||||||
|
+ "}";
|
||||||
|
|
||||||
|
return sparqlQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Model executeQuery(Set<String> constructQueries, DataSource dataSource) {
|
||||||
|
|
||||||
|
Model constructedModel = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
|
for (String queryString : constructQueries) {
|
||||||
|
|
||||||
|
log.debug("CONSTRUCT query string : " + queryString);
|
||||||
|
|
||||||
|
Query query = null;
|
||||||
|
|
||||||
|
try{
|
||||||
|
query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery() + queryString, SYNTAX);
|
||||||
|
}catch(Throwable th){
|
||||||
|
log.error("Could not create CONSTRUCT SPARQL query for query " +
|
||||||
|
"string. " + th.getMessage());
|
||||||
|
log.error(queryString);
|
||||||
|
}
|
||||||
|
|
||||||
|
QueryExecution qe = QueryExecutionFactory.create(
|
||||||
|
query, dataSource);
|
||||||
|
try {
|
||||||
|
qe.execConstruct(constructedModel);
|
||||||
|
} finally {
|
||||||
|
qe.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return constructedModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Model getConstructedModel()
|
||||||
|
throws MalformedQueryParametersException {
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(this.egoURI)) {
|
||||||
|
/*
|
||||||
|
* To test for the validity of the URI submitted.
|
||||||
|
* */
|
||||||
|
IRIFactory iRIFactory = IRIFactory.jenaImplementation();
|
||||||
|
IRI iri = iRIFactory.create(this.egoURI);
|
||||||
|
if (iri.hasViolation(false)) {
|
||||||
|
String errorMsg = ((Violation) iri.violations(false).next()).getShortMessage();
|
||||||
|
log.error("Person Grant Count Construct Query " + errorMsg);
|
||||||
|
throw new MalformedQueryParametersException(
|
||||||
|
"URI provided for an individual is malformed.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new MalformedQueryParametersException("URI parameter is either null or empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<String> constructQueries = new HashSet<String>();
|
||||||
|
|
||||||
|
populateConstructQueries(constructQueries);
|
||||||
|
|
||||||
|
Model model = executeQuery(constructQueries,
|
||||||
|
this.dataSource);
|
||||||
|
|
||||||
|
return model;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void populateConstructQueries(Set<String> constructQueries) {
|
||||||
|
|
||||||
|
constructQueries.add(generateConstructQueryForInvestigatorLabel(this.egoURI));
|
||||||
|
constructQueries.add(generateConstructQueryForInvestigatorGrants(this.egoURI));
|
||||||
|
constructQueries.add(generateConstructQueryForDateTimeValueofRole(this.egoURI));
|
||||||
|
constructQueries.add(generateConstructQueryForDateTimeValueofGrant(this.egoURI));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue