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:
cdtank 2010-07-15 05:09:21 +00:00
parent b231488675
commit 73ebc88e95
4 changed files with 48 additions and 58 deletions

View file

@ -37,9 +37,7 @@ import edu.cornell.mannlib.vitro.webapp.visualization.visutils.UniqueIDGenerator
/** /**
* Very dumb name of the class. change it.
* @author cdtank * @author cdtank
*
*/ */
public class QueryHandler { public class QueryHandler {
@ -306,6 +304,16 @@ public class QueryHandler {
biboDocument.setPublicationYear(publicationYearNode.toString()); 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; return biboDocument;
} }
@ -351,13 +359,19 @@ public class QueryHandler {
+ " (str(?documentMoniker) as ?" + QueryFieldLabels.DOCUMENT_MONIKER + ") " + " (str(?documentMoniker) as ?" + QueryFieldLabels.DOCUMENT_MONIKER + ") "
+ " (str(?documentBlurb) as ?" + QueryFieldLabels.DOCUMENT_BLURB + ") " + " (str(?documentBlurb) as ?" + QueryFieldLabels.DOCUMENT_BLURB + ") "
+ " (str(?publicationYear) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_YEAR + ") " + " (str(?publicationYear) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_YEAR + ") "
+ " (str(?publicationYearMonth) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_YEAR_MONTH + ") "
+ " (str(?publicationDate) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_DATE + ") "
+ "WHERE { " + "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 rdf:type bibo:Document . "
+ "?document rdfs:label ?documentLabel . " + "?document rdfs:label ?documentLabel . "
+ "?document vivo:hasAuthor ?coAuthorPerson . " + "?document core:informationResourceInAuthorship ?coAuthorshipNode . "
+ "?coAuthorPerson rdfs:label ?coAuthorPersonLabel . " + "?coAuthorshipNode core:linkedAuthor ?coAuthorPerson . "
+ "OPTIONAL { ?document vivo:publicationYear ?publicationYear } . " + "?coAuthorPerson rdfs:label ?coAuthorPersonLabel . "
+ "OPTIONAL { ?document core:year ?publicationYear } . "
+ "OPTIONAL { ?document core:yearMonth ?publicationYearMonth } . "
+ "OPTIONAL { ?document core:date ?publicationDate } . "
+ "OPTIONAL { ?document vitro:moniker ?documentMoniker } . " + "OPTIONAL { ?document vitro:moniker ?documentMoniker } . "
+ "OPTIONAL { ?document vitro:blurb ?documentBlurb } . " + "OPTIONAL { ?document vitro:blurb ?documentBlurb } . "
+ "OPTIONAL { ?document vitro:description ?documentDescription } " + "OPTIONAL { ?document vitro:description ?documentDescription } "
@ -403,7 +417,14 @@ public class QueryHandler {
/* /*
* Create a map from the year to number of publications. Use the BiboDocument's * Create a map from the year to number of publications. Use the BiboDocument's
* parsedPublicationYear to populate the data. * 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>(); Map<String, Integer> yearToPublicationCount = new TreeMap<String, Integer>();
for (BiboDocument curr : authorDocuments) { for (BiboDocument curr : authorDocuments) {
@ -413,9 +434,7 @@ public class QueryHandler {
* that particular year. * that particular year.
* */ * */
String publicationYear; String publicationYear;
if (curr.getPublicationYear() != null if (curr.getPublicationYear() != null) {
&& curr.getPublicationYear().length() != 0
&& curr.getPublicationYear().trim().length() != 0) {
publicationYear = curr.getPublicationYear(); publicationYear = curr.getPublicationYear();
} else { } else {
publicationYear = curr.getParsedPublicationYear(); publicationYear = curr.getParsedPublicationYear();
@ -432,7 +451,6 @@ public class QueryHandler {
} }
// System.out.println("****************************\n" + yearToPublicationCount);
return yearToPublicationCount; return yearToPublicationCount;
} }

View file

@ -208,6 +208,16 @@ public class QueryHandler {
biboDocument.setPublicationYear(publicationYearNode.toString()); 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; return biboDocument;
} }
@ -320,47 +330,4 @@ public class QueryHandler {
return createJavaValueObjects(resultSet); 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;
}
} }

View file

@ -95,7 +95,7 @@ public class VisualizationRequestHandler {
for (VivoEmployee currentEmployee : employees) { for (VivoEmployee currentEmployee : employees) {
Map<String, Integer> currentEmployeeYearToPublicationCount = Map<String, Integer> currentEmployeeYearToPublicationCount =
queryManager.getYearToPublicationCount(currentEmployee.getAuthorDocuments()); UtilityFunctions.getYearToPublicationCount(currentEmployee.getAuthorDocuments());
if (currentEmployeeYearToPublicationCount.size() > 0) { if (currentEmployeeYearToPublicationCount.size() > 0) {

View file

@ -27,11 +27,16 @@ public class UtilityFunctions {
/* /*
* Increment the count because there is an entry already available for * Increment the count because there is an entry already available for
* that particular year. * 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; String publicationYear;
if (curr.getPublicationYear() != null if (curr.getPublicationYear() != null) {
&& curr.getPublicationYear().length() != 0
&& curr.getPublicationYear().trim().length() != 0) {
publicationYear = curr.getPublicationYear(); publicationYear = curr.getPublicationYear();
} else { } else {
publicationYear = curr.getParsedPublicationYear(); publicationYear = curr.getParsedPublicationYear();