diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/coauthorship/CoAuthorshipQueryRunner.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/coauthorship/CoAuthorshipQueryRunner.java index eb623ce2..77265876 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/coauthorship/CoAuthorshipQueryRunner.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/coauthorship/CoAuthorshipQueryRunner.java @@ -13,7 +13,12 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import com.hp.hpl.jena.query.QueryExecution; +import com.hp.hpl.jena.query.QueryExecutionFactory; +import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.ResultSetFactory; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException; import edu.cornell.mannlib.vitro.webapp.rdfservice.ResultSetConsumer; @@ -217,7 +222,7 @@ public class CoAuthorshipQueryRunner implements QueryRunner { } public CollaborationData getCollaborationData() { - return new CoAuthorshipData(egoNode, nodes, edges); + return new CoAuthorshipData(egoNode, nodes, edges, biboDocumentURLToVO); } private Activity createDocumentVO(QuerySolution solution, String documentURL) { @@ -372,37 +377,70 @@ public class CoAuthorshipQueryRunner implements QueryRunner { private String generateEgoCoAuthorshipSparqlQuery(String queryURI) { String sparqlQuery = QueryConstants.getSparqlPrefixQuery() - + "SELECT \n" - + " (str(<" + queryURI + ">) as ?" + QueryFieldLabels.AUTHOR_URL + ") \n" - + " (str(?authorLabel) as ?" + QueryFieldLabels.AUTHOR_LABEL + ") \n" - + " (str(?coAuthorPerson) as ?" + QueryFieldLabels.CO_AUTHOR_URL + ") \n" - + " (str(?coAuthorPersonLabel) as ?" + QueryFieldLabels.CO_AUTHOR_LABEL + ") \n" - + " (str(?document) as ?" + QueryFieldLabels.DOCUMENT_URL + ") \n" - + " (str(?publicationDate) as ?" - + QueryFieldLabels.DOCUMENT_PUBLICATION_DATE + ") \n" - + "WHERE { \n" - + "<" + queryURI + "> rdf:type foaf:Person ;" - + " rdfs:label ?authorLabel ;" - + " core:relatedBy ?authorshipNode . \n" - + "?authorshipNode rdf:type core:Authorship ;" - + " core:relates ?document . \n" - + "?document rdf:type bibo:Document ; \n" - + "core:relatedBy ?coAuthorshipNode . \n" - + "?coAuthorshipNode rdf:type core:Authorship ; \n" - + "core:relates ?coAuthorPerson . \n" - + "?coAuthorPerson rdf:type foaf:Person ; \n" - + "rdfs:label ?coAuthorPersonLabel . \n" - + "OPTIONAL { ?document core:dateTimeValue ?dateTimeValue . \n" - + " OPTIONAL { ?dateTimeValue core:dateTime ?publicationDate . } } .\n" - + "} \n" - + "ORDER BY ?document ?coAuthorPerson\n"; + + "PREFIX local: \n" + + "SELECT \n" + + " (str(<" + queryURI + ">) as ?" + QueryFieldLabels.AUTHOR_URL + ") \n" + + " (str(?authorLabel) as ?" + QueryFieldLabels.AUTHOR_LABEL + ") \n" + + " (str(?coAuthorPerson) as ?" + QueryFieldLabels.CO_AUTHOR_URL + ") \n" + + " (str(?coAuthorPersonLabel) as ?" + QueryFieldLabels.CO_AUTHOR_LABEL + ") \n" + + " (str(?document) as ?" + QueryFieldLabels.DOCUMENT_URL + ") \n" + + " (str(?publicationDate) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_DATE + ") \n" + + "WHERE { \n" + + " <" + queryURI + "> local:authorLabel ?authorLabel ;" + + " local:authorOf ?document . \n" + + " ?document local:coAuthor ?coAuthorPerson . \n" + + " ?coAuthorPerson rdfs:label ?coAuthorPersonLabel . \n" + + " OPTIONAL { ?document local:publicationDate ?publicationDate . } \n" + + "} \n" + + "ORDER BY ?document ?coAuthorPerson\n"; log.debug("COAUTHORSHIP QUERY - " + sparqlQuery); return sparqlQuery; } - + private String generateEgoCoAuthorshipSparqlConstruct(String queryURI) { + String sparqlConstruct = QueryConstants.getSparqlPrefixQuery() + + "PREFIX local: \n" + + "CONSTRUCT\n" + + "{\n" + + " <" + queryURI + "> local:authorLabel ?authorLabel .\n" + + " <" + queryURI + "> local:authorOf ?document .\n" + + " ?document local:publicationDate ?publicationDate .\n" + + " ?document local:coAuthor ?coAuthorPerson .\n" + + " ?coAuthorPerson rdfs:label ?coAuthorPersonLabel .\n" + + "}\n" + + "WHERE\n" + + "{\n" + + " {\n" + + " <" + queryURI + "> rdf:type foaf:Person ;" + + " rdfs:label ?authorLabel ;" + + " core:relatedBy ?authorshipNode . \n" + + " ?authorshipNode rdf:type core:Authorship ;" + + " core:relates ?document . \n" + + " ?document rdf:type ; \n" + + " core:relatedBy ?coAuthorshipNode . \n" + + " ?coAuthorshipNode rdf:type core:Authorship ; \n" + + " core:relates ?coAuthorPerson . \n" + + " ?coAuthorPerson rdf:type foaf:Person ; \n" + + " rdfs:label ?coAuthorPersonLabel . \n" + + " }\n" + + " UNION\n" + + " {\n" + + " <" + queryURI + "> rdf:type foaf:Person ;" + + " rdfs:label ?authorLabel ;" + + " core:relatedBy ?authorshipNode . \n" + + " ?authorshipNode rdf:type core:Authorship ;" + + " core:relates ?document . \n" + + " ?document core:dateTimeValue ?dateTimeValue . \n" + + " ?dateTimeValue core:dateTime ?publicationDate . \n" + + " }\n" + + "}\n" + ; + + return sparqlConstruct; + } + public CollaborationData getQueryResult() throws MalformedQueryParametersException { @@ -450,8 +488,15 @@ public class CoAuthorshipQueryRunner implements QueryRunner { } try { - QueryResultConsumer consumer = new QueryResultConsumer(); - rdfService.sparqlSelectQuery(generateEgoCoAuthorshipSparqlQuery(this.egoURI), consumer); + Model constructedModel = ModelFactory.createDefaultModel(); + rdfService.sparqlConstructQuery(generateEgoCoAuthorshipSparqlConstruct(this.egoURI), constructedModel); + QueryResultConsumer consumer = new QueryResultConsumer(); + QueryExecution qe = QueryExecutionFactory.create(generateEgoCoAuthorshipSparqlQuery(this.egoURI), constructedModel); + try { + consumer.processResultSet(qe.execSelect()); + } finally { + qe.close(); + } data = consumer.getCollaborationData(); } catch (RDFServiceException e) { log.error("Unable to execute query", e); diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/collaborationutils/CoAuthorshipData.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/collaborationutils/CoAuthorshipData.java index 31cab024..e1e220f0 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/collaborationutils/CoAuthorshipData.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/collaborationutils/CoAuthorshipData.java @@ -1,21 +1,29 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ package edu.cornell.mannlib.vitro.webapp.visualization.collaborationutils; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; +import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Activity; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Collaboration; import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Collaborator; public class CoAuthorshipData extends CollaborationData { + private Map documentMap = new HashMap<>(); public CoAuthorshipData(Collaborator egoCollaborator, - Set collaborators, Set collaborations) { + Set collaborators, Set collaborations, Map documentMap) { super(egoCollaborator, collaborators, collaborations); + this.documentMap = documentMap; } - + + public Map getDocuments() { + return documentMap; + } + public Set> initializeEdgeSchema() { Set> edgeSchema = new HashSet>(); diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/personlevel/PersonLevelRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/personlevel/PersonLevelRequestHandler.java index 3484e7bc..d9610cf3 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/personlevel/PersonLevelRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/personlevel/PersonLevelRequestHandler.java @@ -5,6 +5,7 @@ package edu.cornell.mannlib.vitro.webapp.visualization.personlevel; import java.util.HashMap; import java.util.Map; +import edu.cornell.mannlib.vitro.webapp.visualization.collaborationutils.CoAuthorshipData; import org.apache.commons.logging.Log; import com.hp.hpl.jena.query.Dataset; @@ -169,25 +170,29 @@ public class PersonLevelRequestHandler implements VisualizationRequestHandler { new CoAuthorshipQueryRunner(egoURI, vitroRequest.getRDFService(), log); CollaborationData coAuthorshipData = coAuthorshipQueryManager.getQueryResult(); - - /* - * When the front-end for the person level vis has to be displayed we render couple of - * sparklines. This will prepare all the data for the sparklines & other requested + + /* + * When the front-end for the person level vis has to be displayed we render couple of + * sparklines. This will prepare all the data for the sparklines & other requested * files. * */ - SubEntity person = new SubEntity(egoURI, - UtilityFunctions - .getIndividualLabelFromDAO(vitroRequest, egoURI)); + SubEntity person = new SubEntity(egoURI, + UtilityFunctions + .getIndividualLabelFromDAO(vitroRequest, egoURI)); + + Map publicationsToURI; + if (coAuthorshipData instanceof CoAuthorshipData) { + publicationsToURI = ((CoAuthorshipData)coAuthorshipData).getDocuments(); + } else { + publicationsToURI = SelectOnModelUtilities.getPublicationsForPerson(dataset, person, false); + } - Map publicationsToURI = SelectOnModelUtilities.getPublicationsForPerson(dataset, person, false); - /* * Create a map from the year to number of publications. Use the BiboDocument's * parsedPublicationYear to populate the data. * */ - Map yearToPublicationCount = - UtilityFunctions.getYearToActivityCount(publicationsToURI.values()); - + Map yearToPublicationCount = + UtilityFunctions.getYearToActivityCount(publicationsToURI.values()); /* * Computations required to generate HTML for the sparklines & related context. * */