1. Modified code so that the Node Co-author names can be captured properly.

2. Also changed the way I selected min or max published year. 
1. Added a graphml exporter for the co-author vis.
This commit is contained in:
cdtank 2010-06-25 21:02:25 +00:00
parent 41dfb27bd0
commit ff351a8dce
8 changed files with 633 additions and 48 deletions

View file

@ -46,10 +46,10 @@ public class TestJava {
} }
Map<String, Integer> yearToPublicationCount = new TreeMap<String, Integer>(); Map<String, Integer> yearToPublicationCount = new TreeMap<String, Integer>();
yearToPublicationCount.put("2003", 5); // yearToPublicationCount.put("2003", 5);
yearToPublicationCount.put("2001", 5); // yearToPublicationCount.put("2001", 5);
yearToPublicationCount.put("2002", 5); // yearToPublicationCount.put("2002", 5);
yearToPublicationCount.put("2090", 7); // yearToPublicationCount.put("2090", 7);
yearToPublicationCount.put("Unknown", 6); yearToPublicationCount.put("Unknown", 6);
Node egoNode; Node egoNode;
@ -78,17 +78,31 @@ public class TestJava {
} }
} }
System.out.println(biboDocumentURLToCoAuthors); System.out.println(yearToPublicationCount);
System.out.println( new HashMap<String, Integer>(){{ Map<String, Integer> saHashMap = new HashMap<String, Integer>(){{
put("sdsd", 4); put("sdsd", 4);
}});
}};
System.out.println(saHashMap.keySet());
Set<String> keySet = new HashSet<String>(yearToPublicationCount.keySet());
keySet.remove("Unknown");
try {
System.out.println(Collections.min(keySet));
} catch (Exception e) {
}
System.out.println(yearToPublicationCount.get("44454454"));
System.out.println(Collections.min(yearToPublicationCount.keySet()));
String emptyString = ""; String emptyString = "";
System.out.println(emptyString.isEmpty()); System.out.println(emptyString.isEmpty());
System.out.println(yearToPublicationCount);
// System.out.println(Collections.max(yearToPublicationCount.keySet())); // System.out.println(Collections.max(yearToPublicationCount.keySet()));
// System.out.println(Collections.min(yearToPublicationCount.keySet())); // System.out.println(Collections.min(yearToPublicationCount.keySet()));

View file

@ -0,0 +1,327 @@
package edu.cornell.mannlib.vitro.webapp.visualization.coauthorship;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;
import java.util.Set;
import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationController;
import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationFrameworkConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Edge;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Node;
public class CoAuthorshipGraphMLWriter {
private StringBuilder coAuthorshipGraphMLContent;
public final String GRAPHML_HEADER = ""
+ " <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ " <graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\"\n"
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
+ " xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns\n"
+ " http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">\n\n";
private final String GRAPHML_FOOTER = "</graphml>";
public CoAuthorshipGraphMLWriter(VisVOContainer visVOContainer) {
coAuthorshipGraphMLContent = createCoAuthorshipGraphMLContent(visVOContainer);
}
private StringBuilder createCoAuthorshipGraphMLContent(
VisVOContainer visVOContainer) {
StringBuilder graphMLContent = new StringBuilder();
graphMLContent.append(GRAPHML_HEADER);
/*
* We are side-effecting "graphMLContent" object in this method since creating
* another String object to hold key definition data will be redundant & will
* not serve the purpose.
* */
generateKeyDefinitionContent(visVOContainer, graphMLContent);
/*
* Used to generate graph content. It will contain both the nodes & edge information.
* We are side-effecting "graphMLContent".
* */
generateGraphContent(visVOContainer, graphMLContent);
graphMLContent.append(GRAPHML_FOOTER);
return graphMLContent;
}
private void generateGraphContent(VisVOContainer visVOContainer,
StringBuilder graphMLContent) {
graphMLContent.append("\n<graph edgedefault=\"undirected\">\n");
generateNodeSectionContent(visVOContainer, graphMLContent);
generateEdgeSectionContent(visVOContainer, graphMLContent);
graphMLContent.append("</graph>\n");
}
private void generateEdgeSectionContent(VisVOContainer visVOContainer,
StringBuilder graphMLContent) {
graphMLContent.append("<!-- edges -->\n");
Set<Edge> edges = visVOContainer.getEdges();
for (Edge currentEdge : edges) {
/*
* This method actually creates the XML code for a single edge. "graphMLContent"
* is being side-effected.
* */
getEdgeContent(graphMLContent, currentEdge);
}
}
private void getEdgeContent(StringBuilder graphMLContent, Edge currentEdge) {
graphMLContent.append("<edge "
+ "id=\"" + currentEdge.getEdgeID() + "\" "
+ "source=\"" + currentEdge.getSourceNode().getNodeID() + "\" "
+ "target=\"" + currentEdge.getTargetNode().getNodeID() + "\" "
+ ">\n");
graphMLContent.append("\t<data key=\"collaborator1\">" + currentEdge.getSourceNode().getNodeName() + "</data>\n");
graphMLContent.append("\t<data key=\"collaborator2\">" + currentEdge.getTargetNode().getNodeName() + "</data>\n");
graphMLContent.append("\t<data key=\"number_of_coauthored_works\">"
+ currentEdge.getNumOfCoAuthoredWorks()
+ "</data>\n");
if (currentEdge.getEarliestCollaborationYearCount() != null) {
/*
* There is no clean way of getting the map contents in java even though
* we are sure to have only one entry on the map. So using the for loop.
* I am feeling dirty just about now.
* */
for (Map.Entry<String, Integer> publicationInfo :
currentEdge.getEarliestCollaborationYearCount().entrySet()) {
graphMLContent.append("\t<data key=\"earliest_collaboration\">"
+ publicationInfo.getKey()
+ "</data>\n");
graphMLContent.append("\t<data key=\"num_earliest_collaboration\">"
+ publicationInfo.getValue()
+ "</data>\n");
}
}
if (currentEdge.getLatestCollaborationYearCount() != null) {
for (Map.Entry<String, Integer> publicationInfo :
currentEdge.getLatestCollaborationYearCount().entrySet()) {
graphMLContent.append("\t<data key=\"latest_collaboration\">"
+ publicationInfo.getKey()
+ "</data>\n");
graphMLContent.append("\t<data key=\"num_latest_collaboration\">"
+ publicationInfo.getValue()
+ "</data>\n");
}
}
if (currentEdge.getUnknownCollaborationYearCount() != null) {
graphMLContent.append("\t<data key=\"num_unknown_collaboration\">"
+ currentEdge.getUnknownCollaborationYearCount()
+ "</data>\n");
}
graphMLContent.append("</edge>\n");
}
private void generateNodeSectionContent(VisVOContainer visVOContainer,
StringBuilder graphMLContent) {
graphMLContent.append("<!-- nodes -->\n");
Node egoNode = visVOContainer.getEgoNode();
Set<Node> authorNodes = visVOContainer.getNodes();
/*
* This method actually creates the XML code for a single node. "graphMLContent"
* is being side-effected. The egoNode is added first because this is the "requirement"
* of the co-author vis. Ego should always come first.
*
* */
getNodeContent(graphMLContent, egoNode);
for (Node currNode : authorNodes) {
/*
* We have already printed the Ego Node info.
* */
if (currNode != egoNode) {
getNodeContent(graphMLContent, currNode);
}
}
}
private void getNodeContent(StringBuilder graphMLContent, Node node) {
String profileURL = null;
try {
profileURL = "/individual?"
+ VisualizationFrameworkConstants.INDIVIDUAL_URI_URL_HANDLE
+ "=" + URLEncoder.encode(node.getNodeURL(),
VisualizationController
.URL_ENCODING_SCHEME).toString();
} catch (UnsupportedEncodingException e) {
System.err.println("URL Encoding ERRor. Move this to use log.error ASAP");
}
graphMLContent.append("<node id=\"" + node.getNodeID() + "\">\n");
graphMLContent.append("\t<data key=\"url\">" + node.getNodeURL() + "</data>\n");
graphMLContent.append("\t<data key=\"name\">" + node.getNodeName() + "</data>\n");
if (profileURL != null) {
graphMLContent.append("\t<data key=\"profile_url\">" + profileURL + "</data>\n");
}
graphMLContent.append("\t<data key=\"number_of_authored_works\">"
+ node.getNumOfAuthoredWorks()
+ "</data>\n");
if (node.getEarliestPublicationYearCount() != null) {
/*
* There is no clean way of getting the map contents in java even though
* we are sure to have only one entry on the map. So using the for loop.
* I am feeling dirty just about now.
* */
for (Map.Entry<String, Integer> publicationInfo :
node.getEarliestPublicationYearCount().entrySet()) {
graphMLContent.append("\t<data key=\"earliest_publication\">"
+ publicationInfo.getKey()
+ "</data>\n");
graphMLContent.append("\t<data key=\"num_earliest_publication\">"
+ publicationInfo.getValue()
+ "</data>\n");
}
}
if (node.getLatestPublicationYearCount() != null) {
for (Map.Entry<String, Integer> publicationInfo :
node.getLatestPublicationYearCount().entrySet()) {
graphMLContent.append("\t<data key=\"latest_publication\">"
+ publicationInfo.getKey()
+ "</data>\n");
graphMLContent.append("\t<data key=\"num_latest_publication\">"
+ publicationInfo.getValue()
+ "</data>\n");
}
}
if (node.getUnknownPublicationYearCount() != null) {
graphMLContent.append("\t<data key=\"num_unknown_publication\">"
+ node.getUnknownPublicationYearCount()
+ "</data>\n");
}
graphMLContent.append("</node>\n");
}
private void generateKeyDefinitionContent(VisVOContainer visVOContainer,
StringBuilder graphMLContent) {
/*
* Generate the key definition content for node.
* */
getKeyDefinitionFromSchema(visVOContainer.getNodeSchema(), graphMLContent);
/*
* Generate the key definition content for edge.
* */
getKeyDefinitionFromSchema(visVOContainer.getEdgeSchema(), graphMLContent);
}
private void getKeyDefinitionFromSchema(Set<Map<String, String>> schema,
StringBuilder graphMLContent) {
for (Map<String, String> currentNodeSchemaAttribute : schema) {
graphMLContent.append("\n<key ");
for (Map.Entry<String, String> currentAttributeKey : currentNodeSchemaAttribute.entrySet()) {
graphMLContent.append(currentAttributeKey.getKey()
+ "=\"" + currentAttributeKey.getValue()
+ "\" ");
}
if (currentNodeSchemaAttribute.containsKey("default")) {
graphMLContent.append(">\n");
graphMLContent.append("<default>");
graphMLContent.append(currentNodeSchemaAttribute.get("default"));
graphMLContent.append("</default>\n");
graphMLContent.append("</key>\n");
} else {
graphMLContent.append("/>\n");
}
}
}
}

View file

@ -331,7 +331,7 @@ public class QueryHandler {
+ " (str(<" + queryURI + ">) as ?" + QueryFieldLabels.AUTHOR_URL + ") " + " (str(<" + queryURI + ">) as ?" + QueryFieldLabels.AUTHOR_URL + ") "
+ " (str(?authorLabel) as ?" + QueryFieldLabels.AUTHOR_LABEL + ") " + " (str(?authorLabel) as ?" + QueryFieldLabels.AUTHOR_LABEL + ") "
+ " (str(?coAuthorPerson) as ?" + QueryFieldLabels.CO_AUTHOR_URL + ") " + " (str(?coAuthorPerson) as ?" + QueryFieldLabels.CO_AUTHOR_URL + ") "
+ " (str(?coAuthorLabel) as ?" + QueryFieldLabels.CO_AUTHOR_LABEL + ") " + " (str(?coAuthorPersonLabel) as ?" + QueryFieldLabels.CO_AUTHOR_LABEL + ") "
+ " (str(?document) as ?" + QueryFieldLabels.DOCUMENT_URL + ") " + " (str(?document) as ?" + QueryFieldLabels.DOCUMENT_URL + ") "
+ " (str(?documentLabel) as ?" + QueryFieldLabels.DOCUMENT_LABEL + ") " + " (str(?documentLabel) as ?" + QueryFieldLabels.DOCUMENT_LABEL + ") "
+ " (str(?documentMoniker) as ?" + QueryFieldLabels.DOCUMENT_MONIKER + ") " + " (str(?documentMoniker) as ?" + QueryFieldLabels.DOCUMENT_MONIKER + ") "

View file

@ -1,5 +1,8 @@
package edu.cornell.mannlib.vitro.webapp.visualization.coauthorship; package edu.cornell.mannlib.vitro.webapp.visualization.coauthorship;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set; import java.util.Set;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Edge; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Edge;
@ -10,7 +13,9 @@ public class VisVOContainer {
private Set<Node> nodes; private Set<Node> nodes;
private Set<Edge> edges; private Set<Edge> edges;
private Node egoNode; private Node egoNode;
private Set<Map<String, String>> NODE_SCHEMA;
private Set<Map<String, String>> EDGE_SCHEMA;
public VisVOContainer(Node egoNode, Set<Node> nodes, Set<Edge> edges) { public VisVOContainer(Node egoNode, Set<Node> nodes, Set<Edge> edges) {
this.egoNode = egoNode; this.egoNode = egoNode;
this.nodes = nodes; this.nodes = nodes;
@ -29,4 +34,199 @@ public class VisVOContainer {
return egoNode; return egoNode;
} }
/*
* Node Schema for graphML
* */
public Set<Map<String, String>> getNodeSchema() {
if (NODE_SCHEMA == null) {
NODE_SCHEMA = initializeNodeSchema();
}
return NODE_SCHEMA;
}
/*
* Edge Schema for graphML
* */
public Set<Map<String, String>> getEdgeSchema() {
if (EDGE_SCHEMA == null) {
EDGE_SCHEMA = initializeEdgeSchema();
}
return EDGE_SCHEMA;
}
private Set<Map<String, String>> initializeEdgeSchema() {
Set<Map<String, String>> edgeSchema = new HashSet<Map<String,String>>();
Map<String, String> schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "collaborator1");
schemaAttributes.put("for", "edge");
schemaAttributes.put("attr.name", "collaborator1");
schemaAttributes.put("attr.type", "string");
edgeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "collaborator2");
schemaAttributes.put("for", "edge");
schemaAttributes.put("attr.name", "collaborator2");
schemaAttributes.put("attr.type", "string");
edgeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "number_of_coauthored_works");
schemaAttributes.put("for", "edge");
schemaAttributes.put("attr.name", "number_of_coauthored_works");
schemaAttributes.put("attr.type", "int");
edgeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "earliest_collaboration");
schemaAttributes.put("for", "edge");
schemaAttributes.put("attr.name", "earliest_collaboration");
schemaAttributes.put("attr.type", "int");
edgeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "num_earliest_collaboration");
schemaAttributes.put("for", "edge");
schemaAttributes.put("attr.name", "num_earliest_collaboration");
schemaAttributes.put("attr.type", "int");
edgeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "latest_collaboration");
schemaAttributes.put("for", "edge");
schemaAttributes.put("attr.name", "latest_collaboration");
schemaAttributes.put("attr.type", "int");
edgeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "num_latest_collaboration");
schemaAttributes.put("for", "edge");
schemaAttributes.put("attr.name", "num_latest_collaboration");
schemaAttributes.put("attr.type", "int");
edgeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "num_unknown_collaboration");
schemaAttributes.put("for", "edge");
schemaAttributes.put("attr.name", "num_unknown_collaboration");
schemaAttributes.put("attr.type", "int");
edgeSchema.add(schemaAttributes);
return edgeSchema;
}
private Set<Map<String, String>> initializeNodeSchema() {
Set<Map<String, String>> nodeSchema = new HashSet<Map<String,String>>();
Map<String, String> schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "url");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "url");
schemaAttributes.put("attr.type", "string");
nodeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "name");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "name");
schemaAttributes.put("attr.type", "string");
nodeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "profile_url");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "profile_url");
schemaAttributes.put("attr.type", "string");
nodeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "number_of_authored_works");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "number_of_authored_works");
schemaAttributes.put("attr.type", "int");
nodeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "earliest_publication");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "earliest_publication");
schemaAttributes.put("attr.type", "int");
nodeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "num_earliest_publication");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "num_earliest_publication");
schemaAttributes.put("attr.type", "int");
nodeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "latest_publication");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "latest_publication");
schemaAttributes.put("attr.type", "int");
nodeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "num_latest_publication");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "num_latest_publication");
schemaAttributes.put("attr.type", "int");
nodeSchema.add(schemaAttributes);
schemaAttributes = new LinkedHashMap<String, String>();
schemaAttributes.put("id", "num_unknown_publication");
schemaAttributes.put("for", "node");
schemaAttributes.put("attr.name", "num_unknown_publication");
schemaAttributes.put("attr.type", "int");
nodeSchema.add(schemaAttributes);
return nodeSchema;
}
} }

View file

@ -352,7 +352,7 @@ public class VisualizationRequestHandler {
+ "\n\tLatest Publication - " + egoNode.getLatestPublicationYearCount() + "\n\tLatest Publication - " + egoNode.getLatestPublicationYearCount()
+ "\n\tUnknown Publication - " + egoNode.getUnknownPublicationYearCount()); + "\n\tUnknown Publication - " + egoNode.getUnknownPublicationYearCount());
authorNodes.remove(egoNode); // authorNodes.remove(egoNode);
for (Node currNode : authorNodes) { for (Node currNode : authorNodes) {
@ -360,7 +360,9 @@ public class VisualizationRequestHandler {
printWriter.append(currNode.getNodeID() + " - " + currNode.getNodeName() + " -> " + currNode.getNodeURL() + "\n"); printWriter.append(currNode.getNodeID() + " - " + currNode.getNodeName() + " -> " + currNode.getNodeURL() + "\n");
printWriter.append("\tEarliest Publication - " + currNode.getEarliestPublicationYearCount() printWriter.append("\tEarliest Publication - " + currNode.getEarliestPublicationYearCount()
+ "\n\tLatest Publication - " + currNode.getLatestPublicationYearCount() + "\n\tLatest Publication - " + currNode.getLatestPublicationYearCount()
+ "\n\tUnknown Publication - " + currNode.getUnknownPublicationYearCount()); + "\n\tUnknown Publication - " + currNode.getUnknownPublicationYearCount()
+ "\n\tTotal Publications - " + currNode.getNumOfAuthoredWorks());
} }
@ -371,7 +373,8 @@ public class VisualizationRequestHandler {
+ currentEdge.getTargetNode().getNodeName() + "\n"); + currentEdge.getTargetNode().getNodeName() + "\n");
printWriter.append("\tEarliest Collaboration - " + currentEdge.getEarliestCollaborationYearCount() printWriter.append("\tEarliest Collaboration - " + currentEdge.getEarliestCollaborationYearCount()
+ "\n\tLatest Collaboration - " + currentEdge.getLatestCollaborationYearCount() + "\n\tLatest Collaboration - " + currentEdge.getLatestCollaborationYearCount()
+ "\n\tUnknown Collaboration - " + currentEdge.getUnknownCollaborationYearCount()); + "\n\tUnknown Collaboration - " + currentEdge.getUnknownCollaborationYearCount()
+ "\n\tTotal Collaboration - " + currentEdge.getNumOfCoAuthoredWorks());
} }

View file

@ -23,7 +23,7 @@ public class QueryFieldLabels {
* Co-Author related field labels * Co-Author related field labels
* */ * */
public static final String CO_AUTHOR_URL = "coAuthPersonLit"; public static final String CO_AUTHOR_URL = "coAuthPersonLit";
public static final String CO_AUTHOR_LABEL = "coAuthorLabelLit"; public static final String CO_AUTHOR_LABEL = "coAuthPersonLabelLit";
/* /*
* College related field labels * College related field labels

View file

@ -67,16 +67,27 @@ public class Edge {
yearToPublicationCount = VOUtils.getYearToPublicationCount(collaboratorDocuments); yearToPublicationCount = VOUtils.getYearToPublicationCount(collaboratorDocuments);
} }
final String earliestYear = Collections.min(yearToPublicationCount.keySet()); /*
final Integer earliestYearPubCount = yearToPublicationCount.get(earliestYear); * We do not want to consider the default publication year when we are checking
* for the min or max publication year.
* */
Set<String> yearsToBeConsidered = new HashSet<String>(yearToPublicationCount.keySet());
yearsToBeConsidered.remove(VOConstants.DEFAULT_PUBLICATION_YEAR);
/* /*
* If there is no minimum year available then we should imply so by returning a "null". * There can be a case when the only publication the author has no attached year to it
* so essentially an "Unknown". In that case Collections.max or min will throw an
* NoSuchElementException.
*
* If there is no maximum year available then we should imply so by returning a "null".
* */ * */
if (!earliestYear.equalsIgnoreCase(VOConstants.DEFAULT_PUBLICATION_YEAR)) { if (yearsToBeConsidered.size() > 0) {
final String earliestYear = Collections.min(yearsToBeConsidered);
final Integer earliestYearPubCount = yearToPublicationCount.get(earliestYear);
return new HashMap<String, Integer>(){{ return new HashMap<String, Integer>(){{
put(earliestYear, earliestYearPubCount); put(earliestYear, earliestYearPubCount);
}}; }};
} else { } else {
return null; return null;
} }
@ -88,36 +99,45 @@ public class Edge {
yearToPublicationCount = VOUtils.getYearToPublicationCount(collaboratorDocuments); yearToPublicationCount = VOUtils.getYearToPublicationCount(collaboratorDocuments);
} }
final String latestYear = Collections.max(yearToPublicationCount.keySet()); /*
final Integer latestYearPubCount = yearToPublicationCount.get(latestYear); * We do not want to consider the default publication year when we are checking
* for the min or max publication year.
* */
Set<String> yearsToBeConsidered = new HashSet<String>(yearToPublicationCount.keySet());
yearsToBeConsidered.remove(VOConstants.DEFAULT_PUBLICATION_YEAR);
/* /*
* There can be a case when the only publication the author has no attached year to it
* so essentially an "Unknown". In that case Collections.max or min will throw an
* NoSuchElementException.
*
* If there is no maximum year available then we should imply so by returning a "null". * If there is no maximum year available then we should imply so by returning a "null".
* */ * */
if (!latestYear.equalsIgnoreCase(VOConstants.DEFAULT_PUBLICATION_YEAR)) { if (yearsToBeConsidered.size() > 0) {
final String latestYear = Collections.max(yearsToBeConsidered);
final Integer latestYearPubCount = yearToPublicationCount.get(latestYear);
return new HashMap<String, Integer>(){{ return new HashMap<String, Integer>(){{
put(latestYear, latestYearPubCount); put(latestYear, latestYearPubCount);
}}; }};
} else { } else {
return null; return null;
} }
} }
@SuppressWarnings("serial") @SuppressWarnings("serial")
public Map<String, Integer> getUnknownCollaborationYearCount() { public Integer getUnknownCollaborationYearCount() {
if (yearToPublicationCount == null) { if (yearToPublicationCount == null) {
yearToPublicationCount = VOUtils.getYearToPublicationCount(collaboratorDocuments); yearToPublicationCount = VOUtils.getYearToPublicationCount(collaboratorDocuments);
} }
final Integer unknownYearPubCount = yearToPublicationCount.get(VOConstants.DEFAULT_PUBLICATION_YEAR); Integer unknownYearPubCount = yearToPublicationCount.get(VOConstants.DEFAULT_PUBLICATION_YEAR);
/* /*
* If there is no unknown year available then we should imply so by returning a "null". * If there is no unknown year available then we should imply so by returning a "null".
* */ * */
if (unknownYearPubCount != null) { if (unknownYearPubCount != null) {
return new HashMap<String, Integer>(){{ return unknownYearPubCount;
put(VOConstants.DEFAULT_PUBLICATION_YEAR, unknownYearPubCount);
}};
} else { } else {
return null; return null;
} }

View file

@ -66,18 +66,30 @@ public class Node extends Individual {
public Map<String, Integer> getEarliestPublicationYearCount() { public Map<String, Integer> getEarliestPublicationYearCount() {
if (yearToPublicationCount == null) { if (yearToPublicationCount == null) {
yearToPublicationCount = VOUtils.getYearToPublicationCount(authorDocuments); yearToPublicationCount = VOUtils.getYearToPublicationCount(authorDocuments);
System.out.println("early - " + yearToPublicationCount);
} }
final String earliestYear = Collections.min(yearToPublicationCount.keySet()); /*
final Integer earliestYearPubCount = yearToPublicationCount.get(earliestYear); * We do not want to consider the default publication year when we are checking
* for the min or max publication year.
* */
Set<String> yearsToBeConsidered = new HashSet<String>(yearToPublicationCount.keySet());
yearsToBeConsidered.remove(VOConstants.DEFAULT_PUBLICATION_YEAR);
/* /*
* If there is no minimum year available then we should imply so by returning a "null". * There can be a case when the only publication the author has no attached year to it
* so essentially an "Unknown". In that case Collections.max or min will throw an
* NoSuchElementException.
*
* If there is no maximum year available then we should imply so by returning a "null".
* */ * */
if (!earliestYear.equalsIgnoreCase(VOConstants.DEFAULT_PUBLICATION_YEAR)) { if (yearsToBeConsidered.size() > 0) {
final String earliestYear = Collections.min(yearsToBeConsidered);
final Integer earliestYearPubCount = yearToPublicationCount.get(earliestYear);
return new HashMap<String, Integer>(){{ return new HashMap<String, Integer>(){{
put(earliestYear, earliestYearPubCount); put(earliestYear, earliestYearPubCount);
}}; }};
} else { } else {
return null; return null;
} }
@ -89,36 +101,45 @@ public class Node extends Individual {
yearToPublicationCount = VOUtils.getYearToPublicationCount(authorDocuments); yearToPublicationCount = VOUtils.getYearToPublicationCount(authorDocuments);
} }
final String latestYear = Collections.max(yearToPublicationCount.keySet()); /*
final Integer latestYearPubCount = yearToPublicationCount.get(latestYear); * We do not want to consider the default publication year when we are checking
* for the min or max publication year.
* */
Set<String> yearsToBeConsidered = new HashSet<String>(yearToPublicationCount.keySet());
yearsToBeConsidered.remove(VOConstants.DEFAULT_PUBLICATION_YEAR);
/* /*
* There can be a case when the only publication the author has no attached year to it
* so essentially an "Unknown". In that case Collections.max or min will throw an
* NoSuchElementException.
*
* If there is no maximum year available then we should imply so by returning a "null". * If there is no maximum year available then we should imply so by returning a "null".
* */ * */
if (!latestYear.equalsIgnoreCase(VOConstants.DEFAULT_PUBLICATION_YEAR)) { if (yearsToBeConsidered.size() > 0) {
final String latestYear = Collections.max(yearsToBeConsidered);
final Integer latestYearPubCount = yearToPublicationCount.get(latestYear);
return new HashMap<String, Integer>(){{ return new HashMap<String, Integer>(){{
put(latestYear, latestYearPubCount); put(latestYear, latestYearPubCount);
}}; }};
} else { } else {
return null; return null;
} }
} }
@SuppressWarnings("serial") public Integer getUnknownPublicationYearCount() {
public Map<String, Integer> getUnknownPublicationYearCount() {
if (yearToPublicationCount == null) { if (yearToPublicationCount == null) {
yearToPublicationCount = VOUtils.getYearToPublicationCount(authorDocuments); yearToPublicationCount = VOUtils.getYearToPublicationCount(authorDocuments);
} }
final Integer unknownYearPubCount = yearToPublicationCount.get(VOConstants.DEFAULT_PUBLICATION_YEAR); Integer unknownYearPubCount = yearToPublicationCount.get(VOConstants.DEFAULT_PUBLICATION_YEAR);
/* /*
* If there is no unknown year available then we should imply so by returning a "null". * If there is no unknown year available then we should imply so by returning a "null".
* */ * */
if (unknownYearPubCount != null) { if (unknownYearPubCount != null) {
return new HashMap<String, Integer>(){{ return unknownYearPubCount;
put(VOConstants.DEFAULT_PUBLICATION_YEAR, unknownYearPubCount);
}};
} else { } else {
return null; return null;
} }