From 628d7615f3f191b7d78e73ad3b1a72ab18ce934c Mon Sep 17 00:00:00 2001 From: bkoniden Date: Thu, 20 Jan 2011 18:44:13 +0000 Subject: [PATCH] Resolving the following: (NIH-1804) Do investigator grants show up in visualizations of just principal-investigator? (NIH - 1826) Make sparql queries for Grants related visualizations compliant to 1.2 for the date property Made changes to the grant queries to include core:dateTime property. --- .../CoPIGrantCountQueryRunner.java | 143 ++++++++++-------- .../EntityGrantCountQueryRunner.java | 17 ++- .../PersonGrantCountQueryRunner.java | 47 +++--- 3 files changed, 122 insertions(+), 85 deletions(-) diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountQueryRunner.java index 60b09801..1d10788b 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/coprincipalinvestigator/CoPIGrantCountQueryRunner.java @@ -55,6 +55,17 @@ public class CoPIGrantCountQueryRunner implements QueryRunner { private UniqueIDGenerator edgeIDGenerator; + private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK = "" + + "OPTIONAL {" + + "?Grant core:dateTimeInterval ?dateTimeIntervalValue . " + + "?dateTimeIntervalValue core:start ?startDate . " + + "?startDate core:dateTime ?startDateTimeValue . " + + "OPTIONAL {" + + "?dateTimeIntervalValue core:end ?endDate . " + + "?endDate core:dateTime ?endDateTimeValue . " + + "}" + + "}" ; + public CoPIGrantCountQueryRunner(String egoURI, DataSource dataSource, Log log) { @@ -76,8 +87,8 @@ public class CoPIGrantCountQueryRunner implements QueryRunner { + " (str(?PILabel) as ?" + QueryFieldLabels.PI_LABEL + ") " + " (str(?Grant) as ?" + QueryFieldLabels.GRANT_URL + ") " + " (str(?GrantLabel) as ?" + QueryFieldLabels.GRANT_LABEL + ") " - + " (str(?GrantStartDate) as ?" + QueryFieldLabels.GRANT_START_DATE + ") " - + " (str(?GrantEndDate) as ?" + QueryFieldLabels.GRANT_END_DATE + ") " + + " (str(?startDateTimeValue) as ?grantStartDateLit) " + + " (str(?endDateTimeValue) as ?grantEndDateLit) " + " (str(?CoPI) as ?" + QueryFieldLabels.CO_PI_URL + ") " + " (str(?CoPILabel) as ?" + QueryFieldLabels.CO_PI_LABEL + ") " + "WHERE " @@ -97,58 +108,34 @@ public class CoPIGrantCountQueryRunner implements QueryRunner { + "?CoPI rdfs:label ?CoPILabel . " - + "OPTIONAL { ?Grant core:startDate ?GrantStartDate } . " - - + "OPTIONAL { ?Grant core:endDate ?GrantEndDate } . " - - + "} " + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK + + + "} " + "UNION " - - + "{ " + +// + "{ " +// + "<" + queryURI + "> rdfs:label ?PILabel . " + + "{ " - + "<" + queryURI + "> core:hasPrincipalInvestigatorRole ?Role . " + + "<" + queryURI + "> core:hasCo-PrincipalInvestigatorRole ?Role . " + "?Role core:roleIn ?Grant . " - + "?Grant rdfs:label ?GrantLabel ; " - - + "core:relatedRole ?RelatedRole . " + + "?Grant rdfs:label ?GrantLabel ; " - + "?RelatedRole core:principalInvestigatorRoleOf ?CoPI . " - - + "?CoPI rdfs:label ?CoPILabel . " - - + "OPTIONAL { ?Grant core:startDate ?GrantStartDate } . " - - + "OPTIONAL { ?Grant core:endDate ?GrantEndDate } . " - - + "} " - - + "UNION " - - + "{ " - - + "<" + queryURI + "> core:hasPrincipalInvestigatorRole ?Role . " - - + "?Role core:roleIn ?Grant . " - - + "?Grant rdfs:label ?GrantLabel ; " - + "core:relatedRole ?RelatedRole . " + "?RelatedRole core:investigatorRoleOf ?CoPI . " + "?CoPI rdfs:label ?CoPILabel . " - + "OPTIONAL { ?Grant core:startDate ?GrantStartDate } . " - - + "OPTIONAL { ?Grant core:endDate ?GrantEndDate } . " - - + "} " - + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK + + + "} " + + "UNION " - + + "{ " + "<" + queryURI + "> core:hasCo-PrincipalInvestigatorRole ?Role . " @@ -166,10 +153,51 @@ public class CoPIGrantCountQueryRunner implements QueryRunner { + "OPTIONAL { ?Grant core:startDate ?GrantStartDate } . " + "OPTIONAL { ?Grant core:endDate ?GrantEndDate } . " - + + "} " + "UNION " + + + + "{ " + + + "<" + queryURI + "> core:hasPrincipalInvestigatorRole ?Role . " + + + "?Role core:roleIn ?Grant . " + + + "?Grant rdfs:label ?GrantLabel ; " + + + "core:relatedRole ?RelatedRole . " + + + "?RelatedRole core:principalInvestigatorRoleOf ?CoPI . " + + + "?CoPI rdfs:label ?CoPILabel . " + + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK + + + "} " + + + "UNION " + + + "{ " + + + "<" + queryURI + "> core:hasPrincipalInvestigatorRole ?Role . " + + + "?Role core:roleIn ?Grant . " + + + "?Grant rdfs:label ?GrantLabel ; " + + + "core:relatedRole ?RelatedRole . " + + + "?RelatedRole core:investigatorRoleOf ?CoPI . " + + + "?CoPI rdfs:label ?CoPILabel . " + + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK + + + "} " + + + "UNION " + "{ " @@ -185,16 +213,15 @@ public class CoPIGrantCountQueryRunner implements QueryRunner { + "?CoPI rdfs:label ?CoPILabel . " - + "OPTIONAL { ?Grant core:startDate ?GrantStartDate } . " - - + "OPTIONAL { ?Grant core:endDate ?GrantEndDate } . " - + "} " + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK + + + "} " + "UNION " + "{ " - + "<" + queryURI + "> core:hasPrincipalInvestigatorRole ?Role . " + + "<" + queryURI + "> core:hasInvestigatorRole ?Role . " + "?Role core:roleIn ?Grant . " @@ -206,10 +233,10 @@ public class CoPIGrantCountQueryRunner implements QueryRunner { + "?CoPI rdfs:label ?CoPILabel . " - + "OPTIONAL { ?Grant core:startDate ?GrantStartDate } . " - - + "OPTIONAL { ?Grant core:endDate ?GrantEndDate } . " - + "} " + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK + + + "} " + + "UNION " + "{ " @@ -226,10 +253,9 @@ public class CoPIGrantCountQueryRunner implements QueryRunner { + "?CoPI rdfs:label ?CoPILabel . " - + "OPTIONAL { ?Grant core:startDate ?GrantStartDate } . " - - + "OPTIONAL { ?Grant core:endDate ?GrantEndDate } . " - + "} " + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK + + + "} " + "UNION " @@ -247,15 +273,14 @@ public class CoPIGrantCountQueryRunner implements QueryRunner { + "?CoPI rdfs:label ?CoPILabel . " - + "OPTIONAL { ?Grant core:startDate ?GrantStartDate } . " - - + "OPTIONAL { ?Grant core:endDate ?GrantEndDate } . " - + "} " + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK + + + "} " + "} "; 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; } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountQueryRunner.java index 990f348e..eab8875e 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/entitygrantcount/EntityGrantCountQueryRunner.java @@ -56,15 +56,22 @@ public class EntityGrantCountQueryRunner implements QueryRunner { + " (str(?SecondaryPositionLabel) as ?SecondaryPositionLabelLit)" + " (str(?Grant) as ?grantLit) " + " (str(?GrantLabel) as ?grantLabelLit) " - + " (str(?GrantStartDate) as ?grantStartDateLit) " - + " (str(?GrantEndDate) as ?grantEndDateLit) "; + + " (str(?startDateTimeValue) as ?grantStartDateLit) " + + " (str(?endDateTimeValue) as ?grantEndDateLit) "; private static final String SPARQL_QUERY_COMMON_WHERE_CLAUSE = " " + " ?SecondaryPosition rdfs:label ?SecondaryPositionLabel . " + " ?Role core:roleIn ?Grant . " + " ?Grant rdfs:label ?GrantLabel . " - + " OPTIONAL { ?Grant core:startDate ?GrantStartDate } . " - + " OPTIONAL { ?Grant core:endDate ?GrantEndDate } ."; + + "OPTIONAL {" + + "?Grant core:dateTimeInterval ?dateTimeIntervalValue . " + + "?dateTimeIntervalValue core:start ?startDate . " + + "?startDate core:dateTime ?startDateTimeValue . " + + "OPTIONAL {" + + "?dateTimeIntervalValue core:end ?endDate . " + + "?endDate core:dateTime ?endDateTimeValue . " + + "}" + + "}" ; private static String ENTITY_LABEL = QueryFieldLabels.ORGANIZATION_LABEL; @@ -240,7 +247,7 @@ public class EntityGrantCountQueryRunner implements QueryRunner { + SPARQL_QUERY_COMMON_WHERE_CLAUSE + "}" + " } "; - //System.out.println("\n\nEntity Grant Count query is: "+ sparqlQuery); + System.out.println("\n\nEntity Grant Count query is: "+ sparqlQuery); log.debug("\nThe sparql query is :\n" + sparqlQuery); diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/persongrantcount/PersonGrantCountQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/persongrantcount/PersonGrantCountQueryRunner.java index 5a869ce2..d938c7e0 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/persongrantcount/PersonGrantCountQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/persongrantcount/PersonGrantCountQueryRunner.java @@ -53,8 +53,19 @@ public class PersonGrantCountQueryRunner implements QueryRunner>{ + "SELECT (str(?PILabel) as ?PILabelLit) " + "(str(?Grant) as ?grantLit)" + "(str(?GrantLabel) as ?grantLabelLit)" - + "(str(?GrantStartDate) as ?grantStartDateLit)" - + "(str(?GrantEndDate) as ?grantEndDateLit)" ; + + " (str(?startDateTimeValue) as ?grantStartDateLit) " + + " (str(?endDateTimeValue) as ?grantEndDateLit) "; + + private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK = "" + + "OPTIONAL {" + + "?Grant core:dateTimeInterval ?dateTimeIntervalValue . " + + "?dateTimeIntervalValue core:start ?startDate . " + + "?startDate core:dateTime ?startDateTimeValue . " + + "OPTIONAL {" + + "?dateTimeIntervalValue core:end ?endDate . " + + "?endDate core:dateTime ?endDateTimeValue . " + + "}" + + "}" ; public PersonGrantCountQueryRunner(String personURI, DataSource dataSource, Log log){ @@ -135,11 +146,10 @@ public class PersonGrantCountQueryRunner implements QueryRunner>{ + "?Role core:roleIn ?Grant . " + "?Grant rdfs:label ?GrantLabel . " - - + "OPTIONAL { ?Grant core:startDate ?GrantStartDate } . " - - + "OPTIONAL { ?Grant core:endDate ?GrantEndDate } . " - + "} " + + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK + + + "} " + "UNION " @@ -150,13 +160,10 @@ public class PersonGrantCountQueryRunner implements QueryRunner>{ + "?Role core:roleIn ?Grant . " + "?Grant rdfs:label ?GrantLabel . " - - + "OPTIONAL { ?Grant core:startDate ?GrantStartDate } . " - - + "OPTIONAL { ?Grant core:endDate ?GrantEndDate } . " - - - + "} " + + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK + + + "} " + "UNION " @@ -167,17 +174,15 @@ public class PersonGrantCountQueryRunner implements QueryRunner>{ + "?Role core:roleIn ?Grant . " + "?Grant rdfs:label ?GrantLabel . " - - + "OPTIONAL { ?Grant core:startDate ?GrantStartDate } . " - - + "OPTIONAL { ?Grant core:endDate ?GrantEndDate } . " - - - + "} " + + + SPARQL_QUERY_COMMON_OPTIONAL_BLOCK + + + "} " + "} "; log.debug("SPARQL query for person grant count -> \n"+ sparqlQuery); + System.out.println("SPARQL query for person grant count -> \n"+ sparqlQuery); return sparqlQuery; }