From e41a4522f746f428b774253187447e7db0320773 Mon Sep 17 00:00:00 2001 From: bkoniden Date: Fri, 11 Feb 2011 19:47:28 +0000 Subject: [PATCH] Removed publication_year_using_1_1_property from the queries for better response times with visualizations and fixed the issue with publications with unknown dates not appearing with temporal vis for publications. --- .../coauthorship/CoAuthorshipQueryRunner.java | 36 +- ...yPublicationCountConstructQueryRunner.java | 225 +++++++------ .../EntityPublicationCountQueryRunner.java | 10 +- ...OrganizationTypesConstructQueryRunner.java | 3 - .../PersonGrantCountConstructQueryRunner.java | 315 +++++++++--------- ...nPublicationCountConstructQueryRunner.java | 41 --- .../PersonPublicationCountQueryRunner.java | 48 +-- .../freemarker/valueobjects/BiboDocument.java | 42 +-- 8 files changed, 310 insertions(+), 410 deletions(-) delete mode 100644 src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personpubcount/PersonPublicationCountConstructQueryRunner.java diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coauthorship/CoAuthorshipQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coauthorship/CoAuthorshipQueryRunner.java index 6961f87a..c7b70b94 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coauthorship/CoAuthorshipQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coauthorship/CoAuthorshipQueryRunner.java @@ -361,21 +361,6 @@ public class CoAuthorshipQueryRunner implements QueryRunner { BiboDocument biboDocument = new BiboDocument(documentURL); - RDFNode documentLabelNode = solution.get(QueryFieldLabels.DOCUMENT_LABEL); - if (documentLabelNode != null) { - biboDocument.setDocumentLabel(documentLabelNode.toString()); - } - - RDFNode documentBlurbNode = solution.get(QueryFieldLabels.DOCUMENT_BLURB); - if (documentBlurbNode != null) { - biboDocument.setDocumentBlurb(documentBlurbNode.toString()); - } - - RDFNode documentMonikerNode = solution.get(QueryFieldLabels.DOCUMENT_MONIKER); - if (documentMonikerNode != null) { - biboDocument.setDocumentMoniker(documentMonikerNode.toString()); - } - RDFNode publicationDateNode = solution.get(QueryFieldLabels.DOCUMENT_PUBLICATION_DATE); if (publicationDateNode != null) { biboDocument.setPublicationDate(publicationDateNode.toString()); @@ -384,10 +369,10 @@ public class CoAuthorshipQueryRunner implements QueryRunner { /* * This is being used so that date in the data from pre-1.2 ontology can be captured. * */ - RDFNode publicationYearUsing_1_1_PropertyNode = solution.get(QueryFieldLabels.DOCUMENT_PUBLICATION_YEAR_USING_1_1_PROPERTY); - if (publicationYearUsing_1_1_PropertyNode != null) { - biboDocument.setPublicationYear(publicationYearUsing_1_1_PropertyNode.toString()); - } +// RDFNode publicationYearUsing_1_1_PropertyNode = solution.get(QueryFieldLabels.DOCUMENT_PUBLICATION_YEAR_USING_1_1_PROPERTY); +// if (publicationYearUsing_1_1_PropertyNode != null) { +// biboDocument.setPublicationYear(publicationYearUsing_1_1_PropertyNode.toString()); +// } return biboDocument; } @@ -412,31 +397,24 @@ public class CoAuthorshipQueryRunner implements QueryRunner { + " (str(?coAuthorPerson) as ?" + QueryFieldLabels.CO_AUTHOR_URL + ") \n" + " (str(?coAuthorPersonLabel) as ?" + QueryFieldLabels.CO_AUTHOR_LABEL + ") \n" + " (str(?document) as ?" + QueryFieldLabels.DOCUMENT_URL + ") \n" - + " (str(?documentLabel) as ?" + QueryFieldLabels.DOCUMENT_LABEL + ") \n" - + " (str(?documentMoniker) as ?" + QueryFieldLabels.DOCUMENT_MONIKER + ") \n" - + " (str(?documentBlurb) as ?" + QueryFieldLabels.DOCUMENT_BLURB + ") \n" + " (str(?publicationDate) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_DATE + ") \n" - + " (str(?publicationYearUsing_1_1_property) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_YEAR_USING_1_1_PROPERTY + ") \n" + // + " (str(?publicationYearUsing_1_1_property) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_YEAR_USING_1_1_PROPERTY + ") \n" + "WHERE { \n" + "<" + queryURI + "> rdf:type foaf:Person ;" + " rdfs:label ?authorLabel ;" + " core:authorInAuthorship ?authorshipNode . \n" + "?authorshipNode rdf:type core:Authorship ;" + " core:linkedInformationResource ?document . \n" - + "?document rdfs:label ?documentLabel . \n" + "?document core:informationResourceInAuthorship ?coAuthorshipNode . \n" + "?coAuthorshipNode core:linkedAuthor ?coAuthorPerson . \n" + "?coAuthorPerson rdfs:label ?coAuthorPersonLabel . \n" + "OPTIONAL { ?document core:dateTimeValue ?dateTimeValue . \n" + " ?dateTimeValue core:dateTime ?publicationDate } .\n" - + "OPTIONAL { ?document core:year ?publicationYearUsing_1_1_property } .\n" - + "OPTIONAL { ?document vitro:moniker ?documentMoniker } . \n" - + "OPTIONAL { ?document vitro:blurb ?documentBlurb } . \n" - + "OPTIONAL { ?document vitro:description ?documentDescription } \n" + // + "OPTIONAL { ?document core:year ?publicationYearUsing_1_1_property } .\n" + "} \n" + "ORDER BY ?document ?coAuthorPerson\n"; -// System.out.println("COAUTHORSHIP QUERY - " + sparqlQuery); + log.debug("COAUTHORSHIP QUERY - " + sparqlQuery); return sparqlQuery; } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountConstructQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountConstructQueryRunner.java index 9700c5b1..4a99ce63 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountConstructQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountConstructQueryRunner.java @@ -67,18 +67,33 @@ public class EntityPublicationCountConstructQueryRunner { + "?Person rdfs:label ?PersonLabel . " + "?Resource core:linkedInformationResource ?Document . " + "?Document rdf:type bibo:Document . " - + "?Document rdfs:label ?DocumentLabel " + + "?Document rdfs:label ?DocumentLabel . " + + "?Document core:dateTimeValue ?dateTimeValue . " + + "?dateTimeValue core:dateTime ?publicationDate . " +// + "?Document core:year ?publicationYearUsing_1_1_property " +"}" + "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 " + + "{" + + "<"+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 " + + "}" + + "UNION " + + "{" + + "?Document core:dateTimeValue ?dateTimeValue . " + + "?dateTimeValue core:dateTime ?publicationDate " + + "}" +// + "UNION " +// + "{" +// + "?Document core:year ?publicationYearUsing_1_1_property " +// + "}" + + "}" ; @@ -97,16 +112,31 @@ public class EntityPublicationCountConstructQueryRunner { + "?Person rdfs:label ?PersonLabel . " + "?Resource core:linkedInformationResource ?Document . " + "?Document rdf:type bibo:Document . " - + "?Document rdfs:label ?DocumentLabel " + + "?Document rdfs:label ?DocumentLabel . " + + "?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 . " - + "?Person rdfs:label ?PersonLabel . " - + "?Resource core:linkedInformationResource ?Document . " - + "?Document rdf:type bibo:Document . " - + "?Document rdfs:label ?DocumentLabel " + + "{" + + "<"+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 " + + "}" + + "UNION" + + "{" + + "?Document core:dateTimeValue ?dateTimeValue . " + + "?dateTimeValue core:dateTime ?publicationDate " + + "}" +// + "UNION " +// + "{" +// + "?Document core:year ?publicationYearUsing_1_1_property " +// + "}" + + "}" ; @@ -114,93 +144,90 @@ public class EntityPublicationCountConstructQueryRunner { } - 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 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 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 constructQueries, Dataset Dataset) { Model constructedModel = ModelFactory.createDefaultModel(); - - before = System.currentTimeMillis(); for (String queryString : constructQueries) { - + before = System.currentTimeMillis(); log.debug("CONSTRUCT query string : " + queryString); Query query = null; try{ - query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery() + queryString, SYNTAX); - //log.info("query: "+ queryString); + query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery() + queryString, SYNTAX); }catch(Throwable th){ log.error("Could not create CONSTRUCT SPARQL query for query " + "string. " + th.getMessage()); @@ -209,16 +236,16 @@ public class EntityPublicationCountConstructQueryRunner { QueryExecution qe = QueryExecutionFactory.create( query, Dataset); + try { qe.execConstruct(constructedModel); } finally { qe.close(); } - + + after = System.currentTimeMillis(); + log.debug("Time taken to execute the CONSTRUCT queries is in milliseconds: " + (after - before) ); } - - after = System.currentTimeMillis(); - log.info("Time taken to execute the CONSTRUCT queries is in milliseconds: " + (after - before) ); // constructedModel.write(System.out); return constructedModel; } @@ -258,8 +285,8 @@ public class EntityPublicationCountConstructQueryRunner { 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)); +// constructQueries.add(generateConstructQueryForDocumentDateTimeValueOneLevelDeep(this.egoURI)); +// constructQueries.add(generateConstructQueryForDocumentDateTimeValue(this.egoURI)); } } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountQueryRunner.java index 95770e7e..474b8609 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntityPublicationCountQueryRunner.java @@ -108,11 +108,11 @@ public class EntityPublicationCountQueryRunner implements QueryRunner { biboDocument = new BiboDocument(documentNode.toString()); biboDocumentURLToVO.put(documentNode.toString(), biboDocument); - RDFNode documentLabelNode = solution - .get(QueryFieldLabels.DOCUMENT_LABEL); - if (documentLabelNode != null) { - biboDocument.setDocumentLabel(documentLabelNode.toString()); - } +// RDFNode documentLabelNode = solution +// .get(QueryFieldLabels.DOCUMENT_LABEL); +// if (documentLabelNode != null) { +// biboDocument.setDocumentLabel(documentLabelNode.toString()); +// } RDFNode publicationDateNode = solution.get(QueryFieldLabels.DOCUMENT_PUBLICATION_DATE); if (publicationDateNode != null) { diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesConstructQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesConstructQueryRunner.java index 65ef14ba..2225f030 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesConstructQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitycomparison/EntitySubOrganizationTypesConstructQueryRunner.java @@ -53,9 +53,6 @@ public class EntitySubOrganizationTypesConstructQueryRunner { } private String generateConstructQueryForSubOrganizationTypes(String queryURI){ - - //bdc34: this query was lacking the personLabel, personType, and personTypeLabel in the WHERE clause - //it seems like they are needed since they are referenced in the CONSTRUCT clause. String sparqlQuery = diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/persongrantcount/PersonGrantCountConstructQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/persongrantcount/PersonGrantCountConstructQueryRunner.java index 5443dd4d..cfa3da61 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/persongrantcount/PersonGrantCountConstructQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/persongrantcount/PersonGrantCountConstructQueryRunner.java @@ -12,7 +12,7 @@ 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.Dataset; import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecutionFactory; @@ -26,181 +26,188 @@ import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryP 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; - } + protected static final Syntax SYNTAX = Syntax.syntaxARQ; + + private String egoURI; + + private Dataset Dataset; + + private Log log = LogFactory.getLog(PersonGrantCountConstructQueryRunner.class.getName()); + + public PersonGrantCountConstructQueryRunner(String egoURI, Dataset Dataset, Log log){ + this.egoURI = egoURI; + this.Dataset = Dataset; + //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 generateConstructQueryForInvestigatorGrants(String queryURI, String preboundProperty){ + + 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 constructQueries, DataSource dataSource) { - + } + + private String generateConstructQueryForDateTimeValueofRole(String queryURI, String preboundProperty){ + + 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 preboundProperty){ + + 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 constructQueries, Dataset Dataset) { + 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){ + long start = System.currentTimeMillis(); + 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); + query, Dataset); try { qe.execConstruct(constructedModel); } finally { qe.close(); } - - } + log.debug("time to run construct: " + (System.currentTimeMillis() - start)); + } - return constructedModel; - } - - public Model getConstructedModel() - throws MalformedQueryParametersException { + 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 (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."); + "URI provided for an individual is malformed."); } } else { throw new MalformedQueryParametersException("URI parameter is either null or empty."); } - - Set constructQueries = new HashSet(); - - populateConstructQueries(constructQueries); - - Model model = executeQuery(constructQueries, - this.dataSource); - - return model; - - } + + Set constructQueries = new HashSet(); + + populateConstructQueries(constructQueries); + + Model model = executeQuery(constructQueries, + this.Dataset); + + return model; + + } - private void populateConstructQueries(Set constructQueries) { - - constructQueries.add(generateConstructQueryForInvestigatorLabel(this.egoURI)); - constructQueries.add(generateConstructQueryForInvestigatorGrants(this.egoURI)); - constructQueries.add(generateConstructQueryForDateTimeValueofRole(this.egoURI)); - constructQueries.add(generateConstructQueryForDateTimeValueofGrant(this.egoURI)); - - - } - -} + private void populateConstructQueries(Set constructQueries) { + + constructQueries.add(generateConstructQueryForInvestigatorLabel(this.egoURI)); + + constructQueries.add(generateConstructQueryForInvestigatorGrants(this.egoURI, " core:hasInvestigatorRole ")); + constructQueries.add(generateConstructQueryForDateTimeValueofRole(this.egoURI, " core:hasInvestigatorRole ")); + constructQueries.add(generateConstructQueryForDateTimeValueofGrant(this.egoURI, " core:hasInvestigatorRole ")); + + constructQueries.add(generateConstructQueryForInvestigatorGrants(this.egoURI, " core:hasPrincipalInvestigatorRole ")); + constructQueries.add(generateConstructQueryForDateTimeValueofRole(this.egoURI, " core:hasPrincipalInvestigatorRole ")); + constructQueries.add(generateConstructQueryForDateTimeValueofGrant(this.egoURI, " core:hasPrincipalInvestigatorRole ")); + + constructQueries.add(generateConstructQueryForInvestigatorGrants(this.egoURI, " core:hasCo-PrincipalInvestigatorRole ")); + constructQueries.add(generateConstructQueryForDateTimeValueofRole(this.egoURI, " core:hasCo-PrincipalInvestigatorRole ")); + constructQueries.add(generateConstructQueryForDateTimeValueofGrant(this.egoURI, " core:hasCo-PrincipalInvestigatorRole ")); + } + +} \ No newline at end of file diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personpubcount/PersonPublicationCountConstructQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personpubcount/PersonPublicationCountConstructQueryRunner.java deleted file mode 100644 index b2b42a6e..00000000 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personpubcount/PersonPublicationCountConstructQueryRunner.java +++ /dev/null @@ -1,41 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.personpubcount; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import com.hp.hpl.jena.query.Dataset; -import com.hp.hpl.jena.query.Syntax; - -public class PersonPublicationCountConstructQueryRunner { - - protected static final Syntax SYNTAX = Syntax.syntaxARQ; - - private String egoURI; - - private Dataset Dataset; - - private Log log = LogFactory.getLog(PersonPublicationCountConstructQueryRunner.class.getName()); - - private long before, after; - - public PersonPublicationCountConstructQueryRunner(String egoURI, Dataset Dataset, Log log){ - this.egoURI = egoURI; - this.Dataset = Dataset; - //this.log = log; - } - - private String generateConstructQueryForAuthorLabel(String queryURI) { - - String sparqlQuery = - "CONSTRUCT { " - + "<"+queryURI+ "> rdfs:label ?authorLabel ." - + "}" - + "WHERE {" - + "<"+queryURI+ "> rdfs:label ?authorLabel ." - + "}"; - - return sparqlQuery; - } -} diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personpubcount/PersonPublicationCountQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personpubcount/PersonPublicationCountQueryRunner.java index 21e965b7..0bc56c2b 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personpubcount/PersonPublicationCountQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/personpubcount/PersonPublicationCountQueryRunner.java @@ -53,22 +53,15 @@ public class PersonPublicationCountQueryRunner implements QueryRunner