1. Person publication sparkline seems to work fine with new sparql query so made similar changes in coauthorship sparql query handler.
2. Refactored some redundant code.
This commit is contained in:
parent
b231488675
commit
73ebc88e95
4 changed files with 48 additions and 58 deletions
|
@ -37,9 +37,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.visutils.UniqueIDGenerator
|
|||
|
||||
|
||||
/**
|
||||
* Very dumb name of the class. change it.
|
||||
* @author cdtank
|
||||
*
|
||||
*/
|
||||
public class QueryHandler {
|
||||
|
||||
|
@ -306,6 +304,16 @@ public class QueryHandler {
|
|||
biboDocument.setPublicationYear(publicationYearNode.toString());
|
||||
}
|
||||
|
||||
RDFNode publicationYearMonthNode = solution.get(QueryFieldLabels.DOCUMENT_PUBLICATION_YEAR_MONTH);
|
||||
if (publicationYearMonthNode != null) {
|
||||
biboDocument.setPublicationYearMonth(publicationYearMonthNode.toString());
|
||||
}
|
||||
|
||||
RDFNode publicationDateNode = solution.get(QueryFieldLabels.DOCUMENT_PUBLICATION_DATE);
|
||||
if (publicationDateNode != null) {
|
||||
biboDocument.setPublicationDate(publicationDateNode.toString());
|
||||
}
|
||||
|
||||
return biboDocument;
|
||||
}
|
||||
|
||||
|
@ -351,13 +359,19 @@ public class QueryHandler {
|
|||
+ " (str(?documentMoniker) as ?" + QueryFieldLabels.DOCUMENT_MONIKER + ") "
|
||||
+ " (str(?documentBlurb) as ?" + QueryFieldLabels.DOCUMENT_BLURB + ") "
|
||||
+ " (str(?publicationYear) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_YEAR + ") "
|
||||
+ " (str(?publicationYearMonth) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_YEAR_MONTH + ") "
|
||||
+ " (str(?publicationDate) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_DATE + ") "
|
||||
+ "WHERE { "
|
||||
+ "<" + queryURI + "> rdf:type foaf:Person ; vivo:authorOf ?document ; rdfs:label ?authorLabel. "
|
||||
+ "<" + queryURI + "> rdf:type foaf:Person ; rdfs:label ?authorLabel ; core:authorInAuthorship ?authorshipNode . "
|
||||
+ "?authorshipNode rdf:type core:Authorship ; core:linkedInformationResource ?document . "
|
||||
+ "?document rdf:type bibo:Document . "
|
||||
+ "?document rdfs:label ?documentLabel . "
|
||||
+ "?document vivo:hasAuthor ?coAuthorPerson . "
|
||||
+ "?document core:informationResourceInAuthorship ?coAuthorshipNode . "
|
||||
+ "?coAuthorshipNode core:linkedAuthor ?coAuthorPerson . "
|
||||
+ "?coAuthorPerson rdfs:label ?coAuthorPersonLabel . "
|
||||
+ "OPTIONAL { ?document vivo:publicationYear ?publicationYear } . "
|
||||
+ "OPTIONAL { ?document core:year ?publicationYear } . "
|
||||
+ "OPTIONAL { ?document core:yearMonth ?publicationYearMonth } . "
|
||||
+ "OPTIONAL { ?document core:date ?publicationDate } . "
|
||||
+ "OPTIONAL { ?document vitro:moniker ?documentMoniker } . "
|
||||
+ "OPTIONAL { ?document vitro:blurb ?documentBlurb } . "
|
||||
+ "OPTIONAL { ?document vitro:description ?documentDescription } "
|
||||
|
@ -403,6 +417,13 @@ public class QueryHandler {
|
|||
/*
|
||||
* Create a map from the year to number of publications. Use the BiboDocument's
|
||||
* parsedPublicationYear to populate the data.
|
||||
*
|
||||
* I am pushing the logic to check for validity of year in "getPublicationYear" itself
|
||||
* because,
|
||||
* 1. We will be using getPub... multiple times & this will save us duplication of code
|
||||
* 2. If we change the logic of validity of a pub year we would not have to make changes
|
||||
* all throughout the codebase.
|
||||
* 3. We are asking for a publication year & we should get a proper one or NOT at all.
|
||||
* */
|
||||
Map<String, Integer> yearToPublicationCount = new TreeMap<String, Integer>();
|
||||
|
||||
|
@ -413,9 +434,7 @@ public class QueryHandler {
|
|||
* that particular year.
|
||||
* */
|
||||
String publicationYear;
|
||||
if (curr.getPublicationYear() != null
|
||||
&& curr.getPublicationYear().length() != 0
|
||||
&& curr.getPublicationYear().trim().length() != 0) {
|
||||
if (curr.getPublicationYear() != null) {
|
||||
publicationYear = curr.getPublicationYear();
|
||||
} else {
|
||||
publicationYear = curr.getParsedPublicationYear();
|
||||
|
@ -432,7 +451,6 @@ public class QueryHandler {
|
|||
|
||||
}
|
||||
|
||||
// System.out.println("****************************\n" + yearToPublicationCount);
|
||||
return yearToPublicationCount;
|
||||
}
|
||||
|
||||
|
|
|
@ -208,6 +208,16 @@ public class QueryHandler {
|
|||
biboDocument.setPublicationYear(publicationYearNode.toString());
|
||||
}
|
||||
|
||||
RDFNode publicationYearMonthNode = solution.get(QueryFieldLabels.DOCUMENT_PUBLICATION_YEAR_MONTH);
|
||||
if (publicationYearMonthNode != null) {
|
||||
biboDocument.setPublicationYearMonth(publicationYearMonthNode.toString());
|
||||
}
|
||||
|
||||
RDFNode publicationDateNode = solution.get(QueryFieldLabels.DOCUMENT_PUBLICATION_DATE);
|
||||
if (publicationDateNode != null) {
|
||||
biboDocument.setPublicationDate(publicationDateNode.toString());
|
||||
}
|
||||
|
||||
return biboDocument;
|
||||
}
|
||||
|
||||
|
@ -320,47 +330,4 @@ public class QueryHandler {
|
|||
return createJavaValueObjects(resultSet);
|
||||
}
|
||||
|
||||
public Map<String, Integer> getYearToPublicationCount(
|
||||
Set<BiboDocument> authorDocuments) {
|
||||
|
||||
/*
|
||||
* Create a map from the year to number of publications. Use the BiboDocument's
|
||||
* parsedPublicationYear to populate the data.
|
||||
* */
|
||||
Map<String, Integer> yearToPublicationCount = new TreeMap<String, Integer>();
|
||||
|
||||
for (BiboDocument curr : authorDocuments) {
|
||||
|
||||
/*
|
||||
* Increment the count because there is an entry already available for
|
||||
* that particular year.
|
||||
* */
|
||||
String publicationYear;
|
||||
if (curr.getPublicationYear() != null
|
||||
&& curr.getPublicationYear().length() != 0
|
||||
&& curr.getPublicationYear().trim().length() != 0) {
|
||||
publicationYear = curr.getPublicationYear();
|
||||
} else {
|
||||
publicationYear = curr.getParsedPublicationYear();
|
||||
}
|
||||
|
||||
if (yearToPublicationCount.containsKey(publicationYear)) {
|
||||
yearToPublicationCount.put(publicationYear,
|
||||
yearToPublicationCount
|
||||
.get(publicationYear) + 1);
|
||||
|
||||
} else {
|
||||
yearToPublicationCount.put(publicationYear, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// System.out.println("****************************\n" + yearToPublicationCount);
|
||||
return yearToPublicationCount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ public class VisualizationRequestHandler {
|
|||
for (VivoEmployee currentEmployee : employees) {
|
||||
|
||||
Map<String, Integer> currentEmployeeYearToPublicationCount =
|
||||
queryManager.getYearToPublicationCount(currentEmployee.getAuthorDocuments());
|
||||
UtilityFunctions.getYearToPublicationCount(currentEmployee.getAuthorDocuments());
|
||||
|
||||
if (currentEmployeeYearToPublicationCount.size() > 0) {
|
||||
|
||||
|
|
|
@ -27,11 +27,16 @@ public class UtilityFunctions {
|
|||
/*
|
||||
* Increment the count because there is an entry already available for
|
||||
* that particular year.
|
||||
*
|
||||
* I am pushing the logic to check for validity of year in "getPublicationYear" itself
|
||||
* because,
|
||||
* 1. We will be using getPub... multiple times & this will save us duplication of code
|
||||
* 2. If we change the logic of validity of a pub year we would not have to make changes
|
||||
* all throughout the codebase.
|
||||
* 3. We are asking for a publication year & we should get a proper one or NOT at all.
|
||||
* */
|
||||
String publicationYear;
|
||||
if (curr.getPublicationYear() != null
|
||||
&& curr.getPublicationYear().length() != 0
|
||||
&& curr.getPublicationYear().trim().length() != 0) {
|
||||
if (curr.getPublicationYear() != null) {
|
||||
publicationYear = curr.getPublicationYear();
|
||||
} else {
|
||||
publicationYear = curr.getParsedPublicationYear();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue