NIHVIVO- 1993

Testing CONSTRUCT + SELECT for CoPIGrantCount, EntityPubCount, EntityGrantCount and EntitySubOrganizationTypesCount.
This commit is contained in:
bkoniden 2011-02-08 21:44:17 +00:00
parent c2a0816ec1
commit 4299483b81
13 changed files with 1133 additions and 74 deletions

View file

@ -0,0 +1,252 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.coprincipalinvestigator;
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 CoPIGrantCountConstructQueryRunner {
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private String egoURI;
private DataSource dataSource;
private Log log = LogFactory.getLog(CoPIGrantCountConstructQueryRunner.class.getName());
private static final String SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING =
"?Role core:roleIn ?Grant . "
+ "?Grant rdfs:label ?GrantLabel . "
+ "?Grant core:relatedRole ?RelatedRole . ";
public CoPIGrantCountConstructQueryRunner(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 generateConstructQueryForInvestigatorRoleOfProperty(String queryURI){
String sparqlQuery =
"CONSTRUCT { "
+ "<"+queryURI+ "> ?preboundProperty ?Role . "
+ SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
+ "?RelatedRole core:investigatorRoleOf ?coInvestigator ."
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . "
+ "}"
+ "WHERE { "
+ "<"+queryURI+ "> ?preboundProperty ?Role . "
+ SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
+ "?RelatedRole core:investigatorRoleOf ?coInvestigator ."
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . "
+ "}";
return sparqlQuery;
}
private String generateConstructQueryForPrincipalInvestigatorRoleOfProperty(String queryURI){
String sparqlQuery =
"CONSTRUCT { "
+ "<"+queryURI+ "> ?preboundProperty ?Role . "
+ SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
+ "?RelatedRole core:principalInvestigatorRoleOf ?coInvestigator ."
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . "
+ "}"
+ "WHERE { "
+ "<"+queryURI+ "> ?preboundProperty ?Role . "
+ SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
+ "?RelatedRole core:principalInvestigatorRoleOf ?coInvestigator ."
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . "
+ "}";
return sparqlQuery;
}
private String generateConstructQueryForCoPrincipalInvestigatorRoleOfProperty(String queryURI){
String sparqlQuery =
"CONSTRUCT { "
+ "<"+queryURI+ "> ?preboundProperty ?Role . "
+ SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
+ "?RelatedRole core:co-PrincipalInvestigatorRoleOf ?coInvestigator ."
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . "
+ "}"
+ "WHERE { "
+ "<"+queryURI+ "> ?preboundProperty ?Role . "
+ SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
+ "?RelatedRole core:co-PrincipalInvestigatorRoleOf ?coInvestigator ."
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . "
+ "}";
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("Ego Co-PI Vis 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(generateConstructQueryForInvestigatorRoleOfProperty(this.egoURI));
constructQueries.add(generateConstructQueryForCoPrincipalInvestigatorRoleOfProperty(this.egoURI));
constructQueries.add(generateConstructQueryForPrincipalInvestigatorRoleOfProperty(this.egoURI));
constructQueries.add(generateConstructQueryForDateTimeValueofRole(this.egoURI));
constructQueries.add(generateConstructQueryForDateTimeValueofGrant(this.egoURI));
}
}

View file

@ -24,6 +24,7 @@ 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.Syntax;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.RDFNode;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
@ -47,7 +48,7 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CoPIData> {
private String egoURI;
private DataSource dataSource;
private Model dataSource;
private Log log;
@ -79,7 +80,7 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CoPIData> {
public CoPIGrantCountQueryRunner(String egoURI,
DataSource dataSource, Log log) {
Model dataSource, Log log) {
this.egoURI = egoURI;
this.dataSource = dataSource;
@ -322,7 +323,7 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CoPIData> {
}
private ResultSet executeQuery(String queryText, DataSource dataSource) {
private ResultSet executeQuery(String queryText, Model dataSource) {
QueryExecution queryExecution = null;
Query query = QueryFactory.create(queryText, SYNTAX);

View file

@ -12,6 +12,7 @@ import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import com.hp.hpl.jena.query.DataSource;
import com.hp.hpl.jena.rdf.model.Model;
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
@ -46,7 +47,10 @@ public class CoPIGrantCountRequestHandler implements VisualizationRequestHandler
String egoURI = vitroRequest.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
String visMode = vitroRequest.getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY);
QueryRunner<CoPIData> queryManager = new CoPIGrantCountQueryRunner(egoURI, dataSource, log);
CoPIGrantCountConstructQueryRunner constructQueryRunner = new CoPIGrantCountConstructQueryRunner(egoURI, dataSource, log);
Model constructedModel = constructQueryRunner.getConstructedModel();
QueryRunner<CoPIData> queryManager = new CoPIGrantCountQueryRunner(egoURI, constructedModel, log);
CoPIData PINodesAndEdges = queryManager.getQueryResult();

View file

@ -10,6 +10,7 @@ import org.apache.commons.logging.Log;
import com.hp.hpl.jena.query.DataSource;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.RDFNode;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels;
@ -93,11 +94,16 @@ public class EntityComparisonUtilityFunctions {
public static Map<String, Set<String>> getSubEntityTypes(Log log,
DataSource dataSource, String subjectOrganization)
throws MalformedQueryParametersException {
EntitySubOrganizationTypesConstructQueryRunner constructQueryRunnerForSubOrganizationTypes = new EntitySubOrganizationTypesConstructQueryRunner(subjectOrganization, dataSource, log) ;
Model constructedModelForSubOrganizationTypes = constructQueryRunnerForSubOrganizationTypes.getConstructedModel();
QueryRunner<Map<String, Set<String>>> queryManagerForsubOrganisationTypes = new EntitySubOrganizationTypesQueryRunner(
subjectOrganization, dataSource, log);
subjectOrganization, constructedModelForSubOrganizationTypes, log);
Map<String, Set<String>> subOrganizationTypesResult = queryManagerForsubOrganisationTypes
.getQueryResult();
return subOrganizationTypesResult;
}

View file

@ -0,0 +1,258 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitycomparison;
import java.util.LinkedHashSet;
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 EntityPublicationCountConstructQueryRunner {
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private String egoURI;
private DataSource dataSource;
private Log log = LogFactory.getLog(EntityPublicationCountConstructQueryRunner.class.getName());
public EntityPublicationCountConstructQueryRunner(String egoURI, DataSource dataSource, Log log){
this.egoURI = egoURI;
this.dataSource = dataSource;
//this.log = log;
}
private String generateConstructQueryForOrganizationLabel(String queryURI) {
String sparqlQuery =
"CONSTRUCT { "
+ "<"+queryURI+ "> rdfs:label ?organizationLabel ."
+ "}"
+ "WHERE {"
+ "<"+queryURI+ "> rdfs:label ?organizationLabel "
+ "}";
return sparqlQuery;
}
private String generateConstructQueryForSubOrganizations(String queryURI){
String sparqlQuery =
"CONSTRUCT { "
+ "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . "
+ "?subOrganization rdfs:label ?subOrganizationLabel . "
+ "?subOrganization core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person core:authorInAuthorship ?Resource . "
+ "?Person rdfs:label ?PersonLabel . "
+ "?Resource core:linkedInformationResource ?Document . "
+ "?Document rdf:type bibo:Document . "
+ "?Document rdfs:label ?DocumentLabel "
+"}"
+ "WHERE { "
+ "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . "
+ "?subOrganization rdfs:label ?subOrganizationLabel . "
+ "?subOrganization core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person core:authorInAuthorship ?Resource . "
+ "?Person rdfs:label ?PersonLabel . "
+ "?Resource core:linkedInformationResource ?Document . "
+ "?Document rdf:type bibo:Document . "
+ "?Document rdfs:label ?DocumentLabel "
+ "}" ;
return sparqlQuery;
}
private String generateConstructQueryForPersons(String queryURI){
String sparqlQuery =
"CONSTRUCT { "
+ "<"+queryURI+ "> core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person core:authorInAuthorship ?Resource . "
+ "?Person rdfs:label ?PersonLabel . "
+ "?Resource core:linkedInformationResource ?Document . "
+ "?Document rdf:type bibo:Document . "
+ "?Document rdfs:label ?DocumentLabel "
+"}"
+ "WHERE { "
+ "<"+queryURI+ "> core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person core:authorInAuthorship ?Resource . "
+ "?Person rdfs:label ?PersonLabel . "
+ "?Resource core:linkedInformationResource ?Document . "
+ "?Document rdf:type bibo:Document . "
+ "?Document rdfs:label ?DocumentLabel "
+ "}" ;
return sparqlQuery;
}
private String generateConstructQueryForDocumentDateTimeValueOneLevelDeep(String queryURI){
String sparqlQuery =
"CONSTRUCT { "
+ "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . "
+ "?subOrganization core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person core:authorInAuthorship ?Resource . "
+ "?Resource core:linkedInformationResource ?Document . "
+ "?Document rdf:type bibo:Document . "
+ "?Document core:dateTimeValue ?dateTimeValue . "
+ "?dateTimeValue core:dateTime ?publicationDate . "
+ "?Document core:year ?publicationYearUsing_1_1_property "
+"}"
+ "WHERE { "
+ "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . "
+ "?subOrganization core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person core:authorInAuthorship ?Resource . "
+ "?Resource core:linkedInformationResource ?Document . "
+ "?Document rdf:type bibo:Document . "
+ "{"
+ "?Document core:dateTimeValue ?dateTimeValue . "
+ "?dateTimeValue core:dateTime ?publicationDate "
+ "}"
+ "UNION "
+ "{"
+ "?Document core:year ?publicationYearUsing_1_1_property "
+ "}"
+ "}" ;
return sparqlQuery;
}
private String generateConstructQueryForDocumentDateTimeValue(String queryURI){
String sparqlQuery =
"CONSTRUCT { "
+ "<"+queryURI+ "> core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person core:authorInAuthorship ?Resource . "
+ "?Resource core:linkedInformationResource ?Document . "
+ "?Document rdf:type bibo:Document . "
+ "?Document core:dateTimeValue ?dateTimeValue . "
+ "?dateTimeValue core:dateTime ?publicationDate . "
+ "?Document core:year ?publicationYearUsing_1_1_property "
+"}"
+ "WHERE { "
+ "<"+queryURI+ "> core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person core:authorInAuthorship ?Resource . "
+ "?Resource core:linkedInformationResource ?Document . "
+ "?Document rdf:type bibo:Document . "
+ "{"
+ "?Document core:dateTimeValue ?dateTimeValue . "
+ "?dateTimeValue core:dateTime ?publicationDate "
+ "}"
+ "UNION "
+ "{"
+ "?Document core:year ?publicationYearUsing_1_1_property "
+ "}"
+ "}" ;
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);
//log.info("query: "+ queryString);
}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();
}
}
// constructedModel.write(System.out);
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("Entity Pub 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 LinkedHashSet<String>();
populateConstructQueries(constructQueries);
Model model = executeQuery(constructQueries,
this.dataSource);
return model;
}
private void populateConstructQueries(Set<String> constructQueries) {
constructQueries.add(generateConstructQueryForOrganizationLabel(this.egoURI));
constructQueries.add(generateConstructQueryForSubOrganizations(this.egoURI));
constructQueries.add(generateConstructQueryForPersons(this.egoURI));
constructQueries.add(generateConstructQueryForDocumentDateTimeValueOneLevelDeep(this.egoURI));
constructQueries.add(generateConstructQueryForDocumentDateTimeValue(this.egoURI));
}
}

View file

@ -12,7 +12,6 @@ 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;
@ -21,6 +20,8 @@ import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.Syntax;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Model;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels;
@ -44,18 +45,16 @@ public class EntityPublicationCountQueryRunner implements QueryRunner<Entity> {
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private String entityURI;
private DataSource dataSource;
private Model dataSource;
private Log log = LogFactory.getLog(EntityPublicationCountQueryRunner.class.getName());
private static final String SPARQL_QUERY_COMMON_SELECT_CLAUSE = ""
+ " (str(?Person) as ?personLit) "
+ " (str(?PersonLabel) as ?personLabelLit) "
+ " (str(?SecondaryPositionLabel) as ?SecondaryPositionLabelLit)"
+ " (str(?Document) as ?documentLit) "
+ " (str(?DocumentLabel) as ?documentLabelLit) "
+ " (str(?publicationDate) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_DATE + ") "
+ " (str(?publicationYearUsing_1_1_property) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_YEAR_USING_1_1_PROPERTY + ") "
+ " (str(?StartYear) as ?StartYearLit)";
+ " (str(?publicationYearUsing_1_1_property) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_YEAR_USING_1_1_PROPERTY + ") ";
private static final String SPARQL_QUERY_COMMON_WHERE_CLAUSE = ""
@ -63,8 +62,7 @@ public class EntityPublicationCountQueryRunner implements QueryRunner<Entity> {
+ " rdfs:label ?DocumentLabel ."
+ "OPTIONAL { ?Document core:dateTimeValue ?dateTimeValue . "
+ " ?dateTimeValue core:dateTime ?publicationDate } ."
+ "OPTIONAL { ?Document core:year ?publicationYearUsing_1_1_property } ."
+ "OPTIONAL { ?SecondaryPosition core:startYear ?StartYear } .";
+ "OPTIONAL { ?Document core:year ?publicationYearUsing_1_1_property } ." ;
private static String ENTITY_LABEL;
private static String ENTITY_URL;
@ -72,7 +70,7 @@ public class EntityPublicationCountQueryRunner implements QueryRunner<Entity> {
private static String SUBENTITY_URL;
public EntityPublicationCountQueryRunner(String entityURI,
DataSource dataSource, Log log) {
Model dataSource, Log log) {
this.entityURI = entityURI;
this.dataSource = dataSource;
@ -208,7 +206,7 @@ public class EntityPublicationCountQueryRunner implements QueryRunner<Entity> {
return entity;
}
private ResultSet executeQuery(String queryURI, DataSource dataSource) {
private ResultSet executeQuery(String queryURI, Model dataSource) {
QueryExecution queryExecution = null;
Query query = QueryFactory.create(
@ -240,23 +238,20 @@ public class EntityPublicationCountQueryRunner implements QueryRunner<Entity> {
+ " (str(?subOrganizationLabel) as ?subOrganizationLabelLit) "
+ SPARQL_QUERY_COMMON_SELECT_CLAUSE + " (str(<" + queryURI
+ ">) as ?" + ENTITY_URL + ") "
+ "WHERE { " + "<" + queryURI + "> rdf:type foaf:Organization ;"
+ " rdfs:label ?organizationLabel ."
+ "WHERE { " + "<" + queryURI + "> rdfs:label ?organizationLabel ."
+ "{ "
+ "<" + queryURI + "> core:hasSubOrganization ?subOrganization ."
+ "?subOrganization rdfs:label ?subOrganizationLabel ; core:organizationForPosition ?Position . "
+ " ?Position rdf:type core:Position ; core:positionForPerson ?Person ."
+ " ?Person core:authorInAuthorship ?Resource ; rdfs:label ?PersonLabel ; core:personInPosition ?SecondaryPosition . "
+ " ?Position core:positionForPerson ?Person ."
+ " ?Person core:authorInAuthorship ?Resource ; rdfs:label ?PersonLabel . "
+ " ?Resource core:linkedInformationResource ?Document . "
+ " ?SecondaryPosition rdfs:label ?SecondaryPositionLabel ."
+ SPARQL_QUERY_COMMON_WHERE_CLAUSE + "}"
+ "UNION "
+ "{ "
+ "<" + queryURI + "> core:organizationForPosition ?Position ."
+ " ?Position rdf:type core:Position ; core:positionForPerson ?Person ."
+ " ?Person core:authorInAuthorship ?Resource ; rdfs:label ?PersonLabel ; core:personInPosition ?SecondaryPosition . "
+ " ?Position core:positionForPerson ?Person ."
+ " ?Person core:authorInAuthorship ?Resource ; rdfs:label ?PersonLabel . "
+ " ?Resource core:linkedInformationResource ?Document ."
+ " ?SecondaryPosition rdfs:label ?SecondaryPositionLabel ."
+ SPARQL_QUERY_COMMON_WHERE_CLAUSE + "}"
+ "}";

View file

@ -19,6 +19,8 @@ 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.rdf.model.Model;
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
@ -91,17 +93,21 @@ public class EntityPublicationCountRequestHandler implements
}
private ResponseValues getSubjectEntityAndGenerateResponse(
VitroRequest vitroRequest, Log log, DataSource dataSource,
String subjectEntityURI)
throws MalformedQueryParametersException {
EntityPublicationCountConstructQueryRunner constructQueryRunner = new EntityPublicationCountConstructQueryRunner(subjectEntityURI, dataSource, log);
Model constructedModel = constructQueryRunner.getConstructedModel();
QueryRunner<Entity> queryManager = new EntityPublicationCountQueryRunner(
subjectEntityURI, dataSource, log);
subjectEntityURI, constructedModel, log);
Entity entity = queryManager.getQueryResult();
if (entity.getEntityLabel().equals("no-label")) {
return prepareStandaloneErrorResponse(vitroRequest, subjectEntityURI);
@ -136,8 +142,11 @@ public class EntityPublicationCountRequestHandler implements
String entityURI = vitroRequest
.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
EntityPublicationCountConstructQueryRunner constructQueryRunner = new EntityPublicationCountConstructQueryRunner(entityURI, dataSource, log);
Model constructedModel = constructQueryRunner.getConstructedModel();
QueryRunner<Entity> queryManager = new EntityPublicationCountQueryRunner(
entityURI, dataSource, log);
entityURI, constructedModel, log);
Entity entity = queryManager.getQueryResult();

View file

@ -0,0 +1,178 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitycomparison;
import java.util.HashSet;
import java.util.LinkedHashSet;
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 EntitySubOrganizationTypesConstructQueryRunner {
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private String egoURI;
private DataSource dataSource;
private Log log = LogFactory.getLog(EntitySubOrganizationTypesConstructQueryRunner.class.getName());
public EntitySubOrganizationTypesConstructQueryRunner(String egoURI, DataSource dataSource, Log log){
this.egoURI = egoURI;
this.dataSource = dataSource;
//this.log = log;
}
private String generateConstructQueryForOrganizationLabel(String queryURI) {
String sparqlQuery =
"CONSTRUCT { "
+ "<"+queryURI+ "> rdfs:label ?organizationLabel ."
+ "}"
+ "WHERE {"
+ "<"+queryURI+ "> rdfs:label ?organizationLabel "
+ "}";
return sparqlQuery;
}
private String generateConstructQueryForSubOrganizationTypes(String queryURI){
String sparqlQuery =
"CONSTRUCT { "
+ "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . "
+ "?subOrganization rdfs:label ?subOrganizationLabel . "
+ "?subOrganization rdf:type ?subOrganizationType . "
+ "?subOrganization core:organizationForPosition ?Position . "
+ "?subOrganizationType rdfs:label ?subOrganizationTypeLabel . "
+ "?Position core:positionForPerson ?Person ."
+ "?Person rdfs:label ?PersonLabel ."
+ "?Person rdf:type ?PersonType . "
+ "?PersonType rdfs:label ?PersonTypeLabel "
+"}"
+ "WHERE { "
+ "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . "
+ "?subOrganization rdfs:label ?subOrganizationLabel . "
+ "?subOrganization rdf:type ?subOrganizationType . "
+ "?subOrganization core:organizationForPosition ?Position . "
+ "?subOrganizationType rdfs:label ?subOrganizationTypeLabel . "
+ "?Position core:positionForPerson ?Person "
+ "}" ;
return sparqlQuery;
}
private String generateConstructQueryForPersonTypes(String queryURI){
String sparqlQuery =
"CONSTRUCT { "
+ "<"+queryURI+ "> core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person ."
+ "?Person rdfs:label ?PersonLabel ."
+ "?Person rdf:type ?PersonType . "
+ "?PersonType rdfs:label ?PersonTypeLabel "
+"}"
+ "WHERE { "
+ "<"+queryURI+ "> core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person ."
+ "?Person rdfs:label ?PersonLabel ."
+ "?Person rdf:type ?PersonType . "
+ "?PersonType rdfs:label ?PersonTypeLabel "
+ "}" ;
return sparqlQuery;
}
private Model executeQuery(Set<String> constructQueries, DataSource dataSource) {
Model constructedModel = ModelFactory.createDefaultModel();
for (String queryString : constructQueries) {
// log.info("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("Ego Co-PI Vis 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 LinkedHashSet<String>();
populateConstructQueries(constructQueries);
Model model = executeQuery(constructQueries,
this.dataSource);
model.write(System.out);
return model;
}
private void populateConstructQueries(Set<String> constructQueries) {
constructQueries.add(generateConstructQueryForOrganizationLabel(this.egoURI));
constructQueries.add(generateConstructQueryForSubOrganizationTypes(this.egoURI));
constructQueries.add(generateConstructQueryForPersonTypes(this.egoURI));
}
}

View file

@ -20,6 +20,8 @@ import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.Syntax;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Model;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels;
@ -39,7 +41,7 @@ public class EntitySubOrganizationTypesQueryRunner implements QueryRunner<Map<St
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private String entityURI;
private DataSource dataSource;
private Model dataSource;
private Log log = LogFactory.getLog(EntitySubOrganizationTypesQueryRunner.class.getName());
private static final String SPARQL_QUERY_SELECT_CLAUSE = ""
@ -53,14 +55,14 @@ public class EntitySubOrganizationTypesQueryRunner implements QueryRunner<Map<St
public EntitySubOrganizationTypesQueryRunner(String entityURI,
DataSource dataSource, Log log){
Model dataSource, Log log){
this.entityURI = entityURI;
this.dataSource = dataSource;
// this.log = log;
}
private ResultSet executeQuery(String queryURI, DataSource dataSource) {
private ResultSet executeQuery(String queryURI, Model dataSource) {
QueryExecution queryExecution = null;
Query query = QueryFactory.create(
@ -79,25 +81,25 @@ public class EntitySubOrganizationTypesQueryRunner implements QueryRunner<Map<St
+ " WHERE { "
+ "<"
+ queryURI
+ "> rdf:type foaf:Organization ;"
+ " rdfs:label ?organizationLabel . "
+ "> rdfs:label ?organizationLabel . "
+ "{ "
+ "<"+ queryURI + "> core:hasSubOrganization ?subOrganization . "
+ "?subOrganization rdfs:label ?subOrganizationLabel ; rdf:type ?subOrganizationType ; core:organizationForPosition ?Position . "
+ "?subOrganization rdfs:label ?subOrganizationLabel ; rdf:type ?subOrganizationType ;"
+ " core:organizationForPosition ?Position . "
+ "?subOrganizationType rdfs:label ?subOrganizationTypeLabel . "
+ "?Position rdf:type core:Position ; core:positionForPerson ?Person ."
+ "?Position core:positionForPerson ?Person ."
+ "}"
+ "UNION "
+ "{ "
+ "<"+ queryURI + "> core:organizationForPosition ?Position . "
+ "?Position rdf:type core:Position ; core:positionForPerson ?Person . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person rdfs:label ?PersonLabel ; rdf:type ?PersonType . "
+ "?PersonType rdfs:label ??PersonTypeLabel . "
+ "?PersonType rdfs:label ?PersonTypeLabel . "
+ "}"
+ "}";
log.debug("\nThe sparql query is :\n" + sparqlQuery);
log.info("\n SubOrganizationTypesQuery :" + sparqlQuery);
return sparqlQuery;
@ -105,8 +107,8 @@ public class EntitySubOrganizationTypesQueryRunner implements QueryRunner<Map<St
private Map<String, Set<String>> createJavaValueObjects(ResultSet resultSet) {
/*Map<String, Set<String>> subOrganizationLabelToTypes = new HashMap<String, Set<String>>();
Map<String, Set<String>> personLabelToTypes = new HashMap<String, Set<String>>();*/
// Map<String, Set<String>> subOrganizationLabelToTypes = new HashMap<String, Set<String>>();
// Map<String, Set<String>> personLabelToTypes = new HashMap<String, Set<String>>();
Map<String, Set<String>> subEntityLabelToTypes = new HashMap<String, Set<String>>();
while(resultSet.hasNext()){

View file

@ -0,0 +1,342 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.entitygrantcount;
import java.util.LinkedHashSet;
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 EntityGrantCountConstructQueryRunner {
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private String egoURI;
private DataSource dataSource;
private Log log = LogFactory.getLog(EntityGrantCountConstructQueryRunner.class.getName());
public EntityGrantCountConstructQueryRunner(String egoURI, DataSource dataSource, Log log){
this.egoURI = egoURI;
this.dataSource = dataSource;
//this.log = log;
}
private String generateConstructQueryForOrganizationLabel(String queryURI) {
String sparqlQuery =
"CONSTRUCT { "
+ "<"+queryURI+ "> rdfs:label ?organizationLabel ."
+ "}"
+ "WHERE {"
+ "<"+queryURI+ "> rdfs:label ?organizationLabel "
+ "}";
return sparqlQuery;
}
private String generateConstructQueryForDateTimeValueofRoleForOneLevelDeep(String queryURI){
String sparqlQuery =
"CONSTRUCT { "
+ "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . "
+ "?subOrganization core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person ?preboundProperty ?Role . "
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
+ "?dateTimeIntervalValue core:start ?startDate . "
+ "?startDate core:dateTime ?startDateTimeValue . "
+ "?dateTimeIntervalValue core:end ?endDate . "
+ "?endDate core:dateTime ?endDateTimeValue . "
+ "}"
+ "WHERE { "
+ "{"
+ "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . "
+ "?subOrganization core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person ?preboundProperty ?Role . "
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
+ "?dateTimeIntervalValue core:start ?startDate . "
+ "?startDate core:dateTime ?startDateTimeValue . "
+ "} UNION "
+ "{"
+ "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . "
+ "?subOrganization core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person ?preboundProperty ?Role . "
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
+ "?dateTimeIntervalValue core:end ?endDate . "
+ "?endDate core:dateTime ?endDateTimeValue . "
+ "}"
+ "}";
return sparqlQuery;
}
private String generateConstructQueryForDateTimeValueofGrantForOneLevelDeep(String queryURI){
String sparqlQuery =
"CONSTRUCT { "
+ "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . "
+ "?subOrganization core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person ?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+ "> core:hasSubOrganization ?subOrganization . "
+ "?subOrganization core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person ?preboundProperty ?Role . "
+ "?Role core:roleIn ?Grant ."
+ "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
+ "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
+ "?startDateForGrant core:dateTime ?startDateTimeValueForGrant "
+ "} UNION "
+ "{"
+ "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . "
+ "?subOrganization core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person ?preboundProperty ?Role . "
+ "?Role core:roleIn ?Grant ."
+ "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
+ "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
+ "?endDateForGrant core:dateTime ?endDateTimeValueForGrant "
+ "}"
+ "}";
return sparqlQuery;
}
private String generateConstructQueryForDateTimeValueofRole(String queryURI){
String sparqlQuery =
"CONSTRUCT { "
+ "<"+queryURI+ "> core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person ?preboundProperty ?Role . "
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
+ "?dateTimeIntervalValue core:start ?startDate . "
+ "?startDate core:dateTime ?startDateTimeValue . "
+ "?dateTimeIntervalValue core:end ?endDate . "
+ "?endDate core:dateTime ?endDateTimeValue "
+ "}"
+ "WHERE { "
+ "{"
+ "<"+queryURI+ "> core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person ?preboundProperty ?Role . "
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
+ "?dateTimeIntervalValue core:start ?startDate . "
+ "?startDate core:dateTime ?startDateTimeValue "
+ "} UNION "
+ "{"
+ "<"+queryURI+ "> core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person ?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+ "> core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person ?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+ "> core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person ?preboundProperty ?Role . "
+ "?Role core:roleIn ?Grant ."
+ "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
+ "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
+ "?startDateForGrant core:dateTime ?startDateTimeValueForGrant "
+ "} UNION "
+ "{"
+ "<"+queryURI+ "> core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person ?preboundProperty ?Role . "
+ "?Role core:roleIn ?Grant ."
+ "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
+ "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
+ "?endDateForGrant core:dateTime ?endDateTimeValueForGrant "
+ "}"
+ "}";
return sparqlQuery;
}
private String generateConstructQueryForSubOrganizations(String queryURI){
String sparqlQuery =
"CONSTRUCT { "
+ "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . "
+ "?subOrganization rdfs:label ?subOrganizationLabel . "
+ "?subOrganization core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person rdfs:label ?PersonLabel ."
+ "?Person ?preboundProperty ?Role . "
+ "?Role core:roleIn ?Grant ."
+ "?Grant rdfs:label ?GrantLabel "
+"}"
+ "WHERE { "
+ "<"+queryURI+ "> core:hasSubOrganization ?subOrganization . "
+ "?subOrganization rdfs:label ?subOrganizationLabel . "
+ "?subOrganization core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person rdfs:label ?PersonLabel ."
+ "?Person ?preboundProperty ?Role . "
+ "?Role core:roleIn ?Grant ."
+ "?Grant rdfs:label ?GrantLabel "
+ "}" ;
return sparqlQuery;
}
private String generateConstructQueryForPersons(String queryURI){
String sparqlQuery =
"CONSTRUCT { "
+ "<"+queryURI+ "> core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person rdfs:label ?PersonLabel ."
+ "?Person ?preboundProperty ?Role . "
+ "?Role core:roleIn ?Grant ."
+ "?Grant rdfs:label ?GrantLabel "
+"}"
+ "WHERE { "
+ "<"+queryURI+ "> core:organizationForPosition ?Position . "
+ "?Position core:positionForPerson ?Person . "
+ "?Person rdfs:label ?PersonLabel ."
+ "?Person ?preboundProperty ?Role . "
+ "?Role core:roleIn ?Grant ."
+ "?Grant rdfs:label ?GrantLabel "
+ "}" ;
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);
// log.info("query: "+ queryString);
}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();
}
}
log.debug("Statements for constructed model of EntityGrantCount : "+ constructedModel.listStatements().toString());
// constructedModel.write(System.out);
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("Entity 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 LinkedHashSet<String>();
populateConstructQueries(constructQueries);
Model model = executeQuery(constructQueries,
this.dataSource);
return model;
}
private void populateConstructQueries(Set<String> constructQueries) {
constructQueries.add(generateConstructQueryForOrganizationLabel(this.egoURI));
constructQueries.add(generateConstructQueryForSubOrganizations(this.egoURI));
constructQueries.add(generateConstructQueryForPersons(this.egoURI));
constructQueries.add(generateConstructQueryForDateTimeValueofRoleForOneLevelDeep(this.egoURI));
constructQueries.add(generateConstructQueryForDateTimeValueofRole(this.egoURI));
constructQueries.add(generateConstructQueryForDateTimeValueofGrantForOneLevelDeep(this.egoURI));
constructQueries.add(generateConstructQueryForDateTimeValueofGrant(this.egoURI));
}
}

View file

@ -20,13 +20,14 @@ 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.Syntax;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.RDFNode;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Entity;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Grant;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.Entity;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects.SubEntity;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.QueryRunner;
@ -44,7 +45,7 @@ public class EntityGrantCountQueryRunner implements QueryRunner<Entity> {
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private String entityURI;
private DataSource dataSource;
private Model dataSource;
private Log log = LogFactory.getLog(EntityGrantCountQueryRunner.class.getName());
@ -54,7 +55,6 @@ public class EntityGrantCountQueryRunner implements QueryRunner<Entity> {
+ " (str(?subOrganizationLabel) as ?subOrganizationLabelLit) "
+ " (str(?Person) as ?personLit) "
+ " (str(?PersonLabel) as ?personLabelLit) "
+ " (str(?SecondaryPositionLabel) as ?SecondaryPositionLabelLit)"
+ " (str(?Grant) as ?grantLit) "
+ " (str(?GrantLabel) as ?grantLabelLit) "
+ " (str(?startDateTimeValue) as ?grantStartDateLit) "
@ -63,7 +63,6 @@ public class EntityGrantCountQueryRunner implements QueryRunner<Entity> {
+ " (str(?endDateTimeValueForGrant) as ?grantEndDateForGrantLit) " ;
private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME = " "
+ " ?SecondaryPosition rdfs:label ?SecondaryPositionLabel . "
+ " ?Role core:roleIn ?Grant . "
+ " ?Grant rdfs:label ?GrantLabel . "
+ "OPTIONAL {"
@ -77,7 +76,6 @@ public class EntityGrantCountQueryRunner implements QueryRunner<Entity> {
+ "}" ;
private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME = " "
+ " ?SecondaryPosition rdfs:label ?SecondaryPositionLabel . "
+ " ?Role core:roleIn ?Grant . "
+ " ?Grant rdfs:label ?GrantLabel . "
+ "OPTIONAL {"
@ -98,10 +96,10 @@ public class EntityGrantCountQueryRunner implements QueryRunner<Entity> {
public EntityGrantCountQueryRunner(String entityURI,
DataSource dataSource, Log log) {
Model constructedModel, Log log) {
this.entityURI = entityURI;
this.dataSource = dataSource;
this.dataSource = constructedModel;
}
@ -113,7 +111,7 @@ public class EntityGrantCountQueryRunner implements QueryRunner<Entity> {
Map<String, SubEntity> personURLToVO = new HashMap<String, SubEntity>();
while (resultSet.hasNext()) {
// log.info("Checking whether EntityGrantCount produced any resultset against the Constructed Model");
QuerySolution solution = resultSet.nextSolution();
if (entity == null) {
@ -197,9 +195,7 @@ public class EntityGrantCountQueryRunner implements QueryRunner<Entity> {
personURLToVO.put(personURLNode.toString(), person);
}
RDFNode personLabelNode = solution
.get(QueryFieldLabels.PERSON_LABEL);
RDFNode personLabelNode = solution.get(QueryFieldLabels.PERSON_LABEL);
if (personLabelNode != null) {
person.setIndividualLabel(personLabelNode.toString());
}
@ -235,12 +231,12 @@ public class EntityGrantCountQueryRunner implements QueryRunner<Entity> {
return entity;
}
private ResultSet executeQuery(String queryURI, DataSource dataSource) {
private ResultSet executeQuery(String queryURI, Model dataSource2) {
QueryExecution queryExecution = null;
Query query = QueryFactory.create(
getSparqlQuery(queryURI), SYNTAX);
queryExecution = QueryExecutionFactory.create(query, dataSource);
queryExecution = QueryExecutionFactory.create(query, dataSource2);
return queryExecution.execSelect();
}
@ -249,57 +245,56 @@ public class EntityGrantCountQueryRunner implements QueryRunner<Entity> {
String sparqlQuery = QueryConstants.getSparqlPrefixQuery()
+ SPARQL_QUERY_COMMON_SELECT_CLAUSE + " (str(<" + queryURI
+ ">) as ?" + ENTITY_URL + ") "
+ "WHERE { " + "<" + queryURI + "> rdf:type foaf:Organization ;"
+ " rdfs:label ?organizationLabel ."
+ "WHERE { " + "<" + queryURI + "> rdfs:label ?organizationLabel ."
+ "{ "
+ "<" + queryURI + "> core:hasSubOrganization ?subOrganization ."
+ " ?subOrganization rdfs:label ?subOrganizationLabel ; core:organizationForPosition ?Position . "
+ " ?Position rdf:type core:Position ; core:positionForPerson ?Person ."
+ " ?Person core:hasCo-PrincipalInvestigatorRole ?Role ; rdfs:label ?PersonLabel ; core:personInPosition ?SecondaryPosition . "
+ " ?Position core:positionForPerson ?Person ."
+ " ?Person core:hasCo-PrincipalInvestigatorRole ?Role ; rdfs:label ?PersonLabel ."
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}"
+ "UNION "
+ "{ "
+ "<" + queryURI + "> core:hasSubOrganization ?subOrganization . "
+ " ?subOrganization rdfs:label ?subOrganizationLabel ; core:organizationForPosition ?Position . "
+ " ?Position rdf:type core:Position ; core:positionForPerson ?Person ."
+ " ?Person core:hasPrincipalInvestigatorRole ?Role ; rdfs:label ?PersonLabel ; core:personInPosition ?SecondaryPosition . "
+ " ?Position core:positionForPerson ?Person ."
+ " ?Person core:hasPrincipalInvestigatorRole ?Role ; rdfs:label ?PersonLabel . "
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}"
+ "UNION "
+ "{ "
+ "<" + queryURI + "> core:hasSubOrganization ?subOrganization . "
+ " ?subOrganization rdfs:label ?subOrganizationLabel ; core:organizationForPosition ?Position . "
+ " ?Position rdf:type core:Position ; core:positionForPerson ?Person ."
+ " ?Person core:hasInvestigatorRole ?Role ; rdfs:label ?PersonLabel ; core:personInPosition ?SecondaryPosition . "
+ " ?Position core:positionForPerson ?Person ."
+ " ?Person core:hasInvestigatorRole ?Role ; rdfs:label ?PersonLabel . "
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}"
+ "UNION "
+ "{ "
+ "<" + queryURI + "> core:organizationForPosition ?Position . "
+ " ?Position rdf:type core:Position ; core:positionForPerson ?Person ."
+ " ?Person core:hasCo-PrincipalInvestigatorRole ?Role ; rdfs:label ?PersonLabel ; core:personInPosition ?SecondaryPosition . "
+ " ?Position core:positionForPerson ?Person ."
+ " ?Person core:hasCo-PrincipalInvestigatorRole ?Role ; rdfs:label ?PersonLabel . "
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}"
+ "UNION "
+ "{ "
+ "<" + queryURI + "> core:organizationForPosition ?Position . "
+ " ?Position rdf:type core:Position ; core:positionForPerson ?Person ."
+ " ?Person core:hasPrincipalInvestigatorRole ?Role ; rdfs:label ?PersonLabel ; core:personInPosition ?SecondaryPosition . "
+ " ?Position core:positionForPerson ?Person ."
+ " ?Person core:hasPrincipalInvestigatorRole ?Role ; rdfs:label ?PersonLabel . "
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}"
+ "UNION "
+ "{ "
+ "<" + queryURI + "> core:organizationForPosition ?Position . "
+ " ?Position rdf:type core:Position ; core:positionForPerson ?Person ."
+ " ?Person core:hasInvestigatorRole ?Role ; rdfs:label ?PersonLabel ; core:personInPosition ?SecondaryPosition . "
+ " ?Position core:positionForPerson ?Person ."
+ " ?Person core:hasInvestigatorRole ?Role ; rdfs:label ?PersonLabel . "
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME + "}"
+ " } ";
//System.out.println("\n\nEntity Grant Count query is: "+ sparqlQuery);
log.debug("\nThe sparql query is :\n" + sparqlQuery);
// log.info("\nThe sparql query is :\n" + sparqlQuery);
return sparqlQuery;

View file

@ -12,12 +12,14 @@ import java.util.Set;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.google.gson.Gson;
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.rdf.model.Model;
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
@ -40,6 +42,8 @@ import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.Visual
public class EntityGrantCountRequestHandler implements
VisualizationRequestHandler {
private Log log = LogFactory.getLog(EntityGrantCountRequestHandler.class.getName());
@Override
public ResponseValues generateStandardVisualization(
VitroRequest vitroRequest, Log log, DataSource dataSource)
@ -100,8 +104,11 @@ public class EntityGrantCountRequestHandler implements
String entityURI = vitroRequest
.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
EntityGrantCountConstructQueryRunner constructQueryRunner = new EntityGrantCountConstructQueryRunner(entityURI, dataSource, log);
Model constructedModel = constructQueryRunner.getConstructedModel();
QueryRunner<Entity> queryManager = new EntityGrantCountQueryRunner(
entityURI, dataSource, log);
entityURI, constructedModel, log);
Entity entity = queryManager.getQueryResult();
@ -124,8 +131,11 @@ public class EntityGrantCountRequestHandler implements
String subjectEntityURI)
throws MalformedQueryParametersException {
EntityGrantCountConstructQueryRunner constructQueryRunner = new EntityGrantCountConstructQueryRunner(subjectEntityURI, dataSource, log);
Model constructedModel = constructQueryRunner.getConstructedModel();
QueryRunner<Entity> queryManager = new EntityGrantCountQueryRunner(
subjectEntityURI, dataSource, log);
subjectEntityURI, constructedModel, log);
Entity entity = queryManager.getQueryResult();
@ -269,6 +279,8 @@ public class EntityGrantCountRequestHandler implements
yearGrantCount.add(currentGrantYear);
}
log.info("entityJson.getLabel() : " + entityJson.getLabel() + " subOrganizationTypesResult " + subOrganizationTypesResult.toString());
entityJson.setYearToActivityCount(yearGrantCount);
entityJson.getOrganizationType().addAll(subOrganizationTypesResult.get(entityJson.getLabel()));

View file

@ -13,6 +13,7 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import com.hp.hpl.jena.query.DataSource;
import com.hp.hpl.jena.rdf.model.Model;
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
@ -22,6 +23,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.visualization.freemarker.Visu
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.coauthorship.CoAuthorshipQueryRunner;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.coauthorship.CoAuthorshipVisCodeGenerator;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.coprincipalinvestigator.CoPIGrantCountConstructQueryRunner;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.coprincipalinvestigator.CoPIGrantCountQueryRunner;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.coprincipalinvestigator.CoPIVisCodeGenerator;
import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.persongrantcount.PersonGrantCountQueryRunner;
@ -84,7 +86,10 @@ public class PersonLevelRequestHandler implements VisualizationRequestHandler {
if (VisualizationFrameworkConstants.COPI_VIS_MODE.equalsIgnoreCase(visMode)){
QueryRunner<CoPIData> coPIQueryManager = new CoPIGrantCountQueryRunner(egoURI, dataSource, log);
CoPIGrantCountConstructQueryRunner constructQueryRunner = new CoPIGrantCountConstructQueryRunner(egoURI, dataSource, log);
Model constructedModel = constructQueryRunner.getConstructedModel();
QueryRunner<CoPIData> coPIQueryManager = new CoPIGrantCountQueryRunner(egoURI, constructedModel, log);
QueryRunner<Set<Grant>> grantQueryManager = new PersonGrantCountQueryRunner(egoURI, dataSource, log);