NIHVIVO-1940

- Modified the grant queries to use role's dateTime as a general rule and default to grant's dateTime when role's dateTime is not available.
This commit is contained in:
bkoniden 2011-01-31 19:18:51 +00:00
parent 4653edf55b
commit 98231b0ce3
5 changed files with 168 additions and 35 deletions

View file

@ -117,5 +117,8 @@ public class QueryFieldLabels {
public static final String GRANT_LABEL = "grantLabelLit";
public static final String GRANT_START_DATE = "grantStartDateLit";
public static final String GRANT_END_DATE = "grantEndDateLit";
public static final String GRANT_START_DATE_FOR_GRANT = "grantStartDateForGrantLit";
public static final String GRANT_END_DATE_FOR_GRANT = "grantEndDateForGrantLit";
}

View file

@ -55,16 +55,28 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CoPIData> {
private UniqueIDGenerator edgeIDGenerator;
private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK = ""
+ "OPTIONAL {"
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME = ""
+ "OPTIONAL {"
+ " ?Role core:dateTimeInterval ?dateTimeIntervalValue . "
+ "?dateTimeIntervalValue core:start ?startDate . "
+ "?startDate core:dateTime ?startDateTimeValue . "
+ "OPTIONAL {"
+ "?dateTimeIntervalValue core:end ?endDate . "
+ "?endDate core:dateTime ?endDateTimeValue . "
+ "}"
+ "}" ;
+ "} . " ;
private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME = ""
+ "OPTIONAL {"
+ " ?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
+ "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
+ "?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
+ "OPTIONAL {"
+ "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
+ "?endDateForGrant core:dateTime ?endDateTimeValueForGrant . "
+ "}"
+ "}" ;
public CoPIGrantCountQueryRunner(String egoURI,
DataSource dataSource, Log log) {
@ -89,6 +101,8 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CoPIData> {
+ " (str(?GrantLabel) as ?" + QueryFieldLabels.GRANT_LABEL + ") "
+ " (str(?startDateTimeValue) as ?grantStartDateLit) "
+ " (str(?endDateTimeValue) as ?grantEndDateLit) "
+ " (str(?startDateTimeValueForGrant) as ?grantStartDateForGrantLit) "
+ " (str(?endDateTimeValueForGrant) as ?grantEndDateForGrantLit) "
+ " (str(?CoPI) as ?" + QueryFieldLabels.CO_PI_URL + ") "
+ " (str(?CoPILabel) as ?" + QueryFieldLabels.CO_PI_LABEL + ") "
+ "WHERE "
@ -108,7 +122,9 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CoPIData> {
+ "?CoPI rdfs:label ?CoPILabel . "
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME
+ "} "
@ -128,7 +144,10 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CoPIData> {
+ "?CoPI rdfs:label ?CoPILabel . "
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME
+ "} "
@ -148,7 +167,10 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CoPIData> {
+ "?CoPI rdfs:label ?CoPILabel . "
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME
+ "} "
@ -169,7 +191,10 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CoPIData> {
+ "?CoPI rdfs:label ?CoPILabel . "
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME
+ "} "
@ -189,7 +214,10 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CoPIData> {
+ "?CoPI rdfs:label ?CoPILabel . "
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME
+ "} "
@ -209,7 +237,10 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CoPIData> {
+ "?CoPI rdfs:label ?CoPILabel . "
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME
+ "} "
@ -229,7 +260,10 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CoPIData> {
+ "?CoPI rdfs:label ?CoPILabel . "
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME
+ "} "
@ -249,7 +283,10 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CoPIData> {
+ "?CoPI rdfs:label ?CoPILabel . "
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME
+ "} "
@ -269,7 +306,10 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CoPIData> {
+ "?CoPI rdfs:label ?CoPILabel . "
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME
+ "} "
+ "} ";
@ -609,12 +649,21 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CoPIData> {
RDFNode grantStartYear = solution.get(QueryFieldLabels.GRANT_START_DATE);
if (grantStartYear != null) {
grant.setGrantStartDate(grantStartYear.toString());
}else{
grantStartYear = solution.get(QueryFieldLabels.GRANT_START_DATE_FOR_GRANT);
if(grantStartYear != null){
grant.setGrantStartDate(grantStartYear.toString());
}
}
RDFNode grantEndDate = solution.get(QueryFieldLabels
.GRANT_END_DATE);
RDFNode grantEndDate = solution.get(QueryFieldLabels.GRANT_END_DATE);
if (grantEndDate != null) {
grant.setGrantEndDate(grantEndDate.toString());
}else{
grantEndDate = solution.get(QueryFieldLabels.GRANT_END_DATE_FOR_GRANT);
if(grantEndDate != null){
grant.setGrantEndDate(grantEndDate.toString());
}
}
return grant;

View file

@ -57,21 +57,37 @@ public class EntityGrantCountQueryRunner implements QueryRunner<Entity> {
+ " (str(?Grant) as ?grantLit) "
+ " (str(?GrantLabel) as ?grantLabelLit) "
+ " (str(?startDateTimeValue) as ?grantStartDateLit) "
+ " (str(?endDateTimeValue) as ?grantEndDateLit) ";
+ " (str(?endDateTimeValue) as ?grantEndDateLit) "
+ " (str(?startDateTimeValueForGrant) as ?grantStartDateForGrantLit) "
+ " (str(?endDateTimeValueForGrant) as ?grantEndDateForGrantLit) " ;
private static final String SPARQL_QUERY_COMMON_WHERE_CLAUSE = " "
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 {"
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
+ " ?Role core:dateTimeInterval ?dateTimeIntervalValue . "
+ "?dateTimeIntervalValue core:start ?startDate . "
+ "?startDate core:dateTime ?startDateTimeValue . "
+ "OPTIONAL {"
+ "?dateTimeIntervalValue core:end ?endDate . "
+ "?endDate core:dateTime ?endDateTimeValue . "
+ "}"
+ "}" ;
+ "}" ;
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 {"
+ " ?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
+ "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
+ "?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
+ "OPTIONAL {"
+ "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
+ "?endDateForGrant core:dateTime ?endDateTimeValueForGrant . "
+ "}"
+ "}" ;
private static String ENTITY_LABEL = QueryFieldLabels.ORGANIZATION_LABEL;
@ -125,11 +141,21 @@ public class EntityGrantCountQueryRunner implements QueryRunner<Entity> {
RDFNode grantStartDateNode = solution.get(QueryFieldLabels.GRANT_START_DATE);
if(grantStartDateNode != null){
grant.setGrantStartDate(grantStartDateNode.toString());
}else {
grantStartDateNode = solution.get(QueryFieldLabels.GRANT_START_DATE_FOR_GRANT);
if(grantStartDateNode != null){
grant.setGrantStartDate(grantStartDateNode.toString());
}
}
RDFNode grantEndDateNode = solution.get(QueryFieldLabels.GRANT_END_DATE);
if(grantEndDateNode != null){
grant.setGrantEndDate(grantEndDateNode.toString());
}else {
grantEndDateNode = solution.get(QueryFieldLabels.GRANT_END_DATE_FOR_GRANT);
if(grantEndDateNode != null){
grant.setGrantEndDate(grantEndDateNode.toString());
}
}
}
@ -212,39 +238,45 @@ public class EntityGrantCountQueryRunner implements QueryRunner<Entity> {
+ " ?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 . "
+ SPARQL_QUERY_COMMON_WHERE_CLAUSE + "}"
+ 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 . "
+ SPARQL_QUERY_COMMON_WHERE_CLAUSE + "}"
+ 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 . "
+ SPARQL_QUERY_COMMON_WHERE_CLAUSE + "}"
+ 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 . "
+ SPARQL_QUERY_COMMON_WHERE_CLAUSE + "}"
+ 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 . "
+ SPARQL_QUERY_COMMON_WHERE_CLAUSE + "}"
+ 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 . "
+ SPARQL_QUERY_COMMON_WHERE_CLAUSE + "}"
+ 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);

View file

@ -50,23 +50,39 @@ public class PersonGrantCountQueryRunner implements QueryRunner<Set<Grant>>{
private Log log;
private static final String SPARQL_QUERY_COMMON_SELECT_CLAUSE = ""
+ "SELECT (str(?PILabel) as ?PILabelLit) "
+ "(str(?Grant) as ?grantLit)"
+ "(str(?GrantLabel) as ?grantLabelLit)"
+ " SELECT (str(?PILabel) as ?PILabelLit) "
+ " (str(?Grant) as ?grantLit)"
+ " (str(?GrantLabel) as ?grantLabelLit)"
+ " (str(?startDateTimeValue) as ?grantStartDateLit) "
+ " (str(?endDateTimeValue) as ?grantEndDateLit) ";
+ " (str(?endDateTimeValue) as ?grantEndDateLit) "
+ " (str(?startDateTimeValueForGrant) as ?grantStartDateForGrantLit) "
+ " (str(?endDateTimeValueForGrant) as ?grantEndDateForGrantLit) ";
private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK = ""
+ "OPTIONAL {"
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME = ""
+ "OPTIONAL {"
+ " ?Role core:dateTimeInterval ?dateTimeIntervalValue . "
+ "?dateTimeIntervalValue core:start ?startDate . "
+ "?startDate core:dateTime ?startDateTimeValue . "
+ "OPTIONAL {"
+ "?dateTimeIntervalValue core:end ?endDate . "
+ "?endDate core:dateTime ?endDateTimeValue . "
+ "}"
+ "} . " ;
private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME = ""
+ "OPTIONAL {"
+ " ?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
+ "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
+ "?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
+ "OPTIONAL {"
+ "?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
+ "?endDateForGrant core:dateTime ?endDateTimeValueForGrant . "
+ "}"
+ "}" ;
public PersonGrantCountQueryRunner(String personURI, DataSource dataSource, Log log){
this.personURI = personURI;
@ -90,11 +106,21 @@ public class PersonGrantCountQueryRunner implements QueryRunner<Set<Grant>>{
RDFNode grantStartDateNode = solution.get(QueryFieldLabels.GRANT_START_DATE);
if(grantStartDateNode != null){
grant.setGrantStartDate(grantStartDateNode.toString());
}else {
grantStartDateNode = solution.get(QueryFieldLabels.GRANT_START_DATE_FOR_GRANT);
if(grantStartDateNode != null){
grant.setGrantStartDate(grantStartDateNode.toString());
}
}
RDFNode grantEndDateNode = solution.get(QueryFieldLabels.GRANT_END_DATE);
if(grantEndDateNode != null){
grant.setGrantEndDate(grantEndDateNode.toString());
}else {
grantEndDateNode = solution.get(QueryFieldLabels.GRANT_END_DATE_FOR_GRANT);
if(grantEndDateNode != null){
grant.setGrantEndDate(grantEndDateNode.toString());
}
}
/*
@ -147,7 +173,9 @@ public class PersonGrantCountQueryRunner implements QueryRunner<Set<Grant>>{
+ "?Grant rdfs:label ?GrantLabel . "
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME
+ "} "
@ -161,7 +189,10 @@ public class PersonGrantCountQueryRunner implements QueryRunner<Set<Grant>>{
+ "?Grant rdfs:label ?GrantLabel . "
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME
+ "} "
@ -175,7 +206,10 @@ public class PersonGrantCountQueryRunner implements QueryRunner<Set<Grant>>{
+ "?Grant rdfs:label ?GrantLabel . "
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME
+ SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_GRANT_DATE_TIME
+ "} "

View file

@ -63,7 +63,22 @@ public class Grant extends Individual {
}
}
@Override
public boolean equals(Object other){
boolean result = false;
if (other instanceof Grant){
Grant grant = (Grant) other;
result = (this.getIndividualLabel().equals(grant.getIndividualLabel())
&& this.getIndividualURI().equals(grant.getIndividualURI()));
}
return result;
}
@Override
public int hashCode(){
return(41*(getIndividualLabel().hashCode() + 41*(getIndividualURI().hashCode())));
}
public String getGrantStartDate() {
return grantStartDate;