[VIVO-1031] Improve re-use of data in coauthorship query
This commit is contained in:
parent
7cf8a6eb8f
commit
84d2811512
3 changed files with 100 additions and 42 deletions
|
@ -13,7 +13,12 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
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.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.RDFService;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.ResultSetConsumer;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.ResultSetConsumer;
|
||||||
|
@ -217,7 +222,7 @@ public class CoAuthorshipQueryRunner implements QueryRunner<CollaborationData> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public CollaborationData getCollaborationData() {
|
public CollaborationData getCollaborationData() {
|
||||||
return new CoAuthorshipData(egoNode, nodes, edges);
|
return new CoAuthorshipData(egoNode, nodes, edges, biboDocumentURLToVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Activity createDocumentVO(QuerySolution solution, String documentURL) {
|
private Activity createDocumentVO(QuerySolution solution, String documentURL) {
|
||||||
|
@ -372,37 +377,70 @@ public class CoAuthorshipQueryRunner implements QueryRunner<CollaborationData> {
|
||||||
private String generateEgoCoAuthorshipSparqlQuery(String queryURI) {
|
private String generateEgoCoAuthorshipSparqlQuery(String queryURI) {
|
||||||
|
|
||||||
String sparqlQuery = QueryConstants.getSparqlPrefixQuery()
|
String sparqlQuery = QueryConstants.getSparqlPrefixQuery()
|
||||||
+ "SELECT \n"
|
+ "PREFIX local: <http://localhost/>\n"
|
||||||
+ " (str(<" + queryURI + ">) as ?" + QueryFieldLabels.AUTHOR_URL + ") \n"
|
+ "SELECT \n"
|
||||||
+ " (str(?authorLabel) as ?" + QueryFieldLabels.AUTHOR_LABEL + ") \n"
|
+ " (str(<" + queryURI + ">) as ?" + QueryFieldLabels.AUTHOR_URL + ") \n"
|
||||||
+ " (str(?coAuthorPerson) as ?" + QueryFieldLabels.CO_AUTHOR_URL + ") \n"
|
+ " (str(?authorLabel) as ?" + QueryFieldLabels.AUTHOR_LABEL + ") \n"
|
||||||
+ " (str(?coAuthorPersonLabel) as ?" + QueryFieldLabels.CO_AUTHOR_LABEL + ") \n"
|
+ " (str(?coAuthorPerson) as ?" + QueryFieldLabels.CO_AUTHOR_URL + ") \n"
|
||||||
+ " (str(?document) as ?" + QueryFieldLabels.DOCUMENT_URL + ") \n"
|
+ " (str(?coAuthorPersonLabel) as ?" + QueryFieldLabels.CO_AUTHOR_LABEL + ") \n"
|
||||||
+ " (str(?publicationDate) as ?"
|
+ " (str(?document) as ?" + QueryFieldLabels.DOCUMENT_URL + ") \n"
|
||||||
+ QueryFieldLabels.DOCUMENT_PUBLICATION_DATE + ") \n"
|
+ " (str(?publicationDate) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_DATE + ") \n"
|
||||||
+ "WHERE { \n"
|
+ "WHERE { \n"
|
||||||
+ "<" + queryURI + "> rdf:type foaf:Person ;"
|
+ " <" + queryURI + "> local:authorLabel ?authorLabel ;"
|
||||||
+ " rdfs:label ?authorLabel ;"
|
+ " local:authorOf ?document . \n"
|
||||||
+ " core:relatedBy ?authorshipNode . \n"
|
+ " ?document local:coAuthor ?coAuthorPerson . \n"
|
||||||
+ "?authorshipNode rdf:type core:Authorship ;"
|
+ " ?coAuthorPerson rdfs:label ?coAuthorPersonLabel . \n"
|
||||||
+ " core:relates ?document . \n"
|
+ " OPTIONAL { ?document local:publicationDate ?publicationDate . } \n"
|
||||||
+ "?document rdf:type bibo:Document ; \n"
|
+ "} \n"
|
||||||
+ "core:relatedBy ?coAuthorshipNode . \n"
|
+ "ORDER BY ?document ?coAuthorPerson\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";
|
|
||||||
|
|
||||||
log.debug("COAUTHORSHIP QUERY - " + sparqlQuery);
|
log.debug("COAUTHORSHIP QUERY - " + sparqlQuery);
|
||||||
|
|
||||||
return sparqlQuery;
|
return sparqlQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String generateEgoCoAuthorshipSparqlConstruct(String queryURI) {
|
||||||
|
String sparqlConstruct = QueryConstants.getSparqlPrefixQuery()
|
||||||
|
+ "PREFIX local: <http://localhost/>\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 <http://purl.obolibrary.org/obo/IAO_0000030> ; \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()
|
public CollaborationData getQueryResult()
|
||||||
throws MalformedQueryParametersException {
|
throws MalformedQueryParametersException {
|
||||||
|
|
||||||
|
@ -450,8 +488,15 @@ public class CoAuthorshipQueryRunner implements QueryRunner<CollaborationData> {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
QueryResultConsumer consumer = new QueryResultConsumer();
|
Model constructedModel = ModelFactory.createDefaultModel();
|
||||||
rdfService.sparqlSelectQuery(generateEgoCoAuthorshipSparqlQuery(this.egoURI), consumer);
|
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();
|
data = consumer.getCollaborationData();
|
||||||
} catch (RDFServiceException e) {
|
} catch (RDFServiceException e) {
|
||||||
log.error("Unable to execute query", e);
|
log.error("Unable to execute query", e);
|
||||||
|
|
|
@ -1,21 +1,29 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
package edu.cornell.mannlib.vitro.webapp.visualization.collaborationutils;
|
package edu.cornell.mannlib.vitro.webapp.visualization.collaborationutils;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
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.Collaboration;
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Collaborator;
|
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Collaborator;
|
||||||
|
|
||||||
public class CoAuthorshipData extends CollaborationData {
|
public class CoAuthorshipData extends CollaborationData {
|
||||||
|
private Map<String, Activity> documentMap = new HashMap<>();
|
||||||
|
|
||||||
public CoAuthorshipData(Collaborator egoCollaborator,
|
public CoAuthorshipData(Collaborator egoCollaborator,
|
||||||
Set<Collaborator> collaborators, Set<Collaboration> collaborations) {
|
Set<Collaborator> collaborators, Set<Collaboration> collaborations, Map<String, Activity> documentMap) {
|
||||||
super(egoCollaborator, collaborators, collaborations);
|
super(egoCollaborator, collaborators, collaborations);
|
||||||
|
this.documentMap = documentMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, Activity> getDocuments() {
|
||||||
|
return documentMap;
|
||||||
|
}
|
||||||
|
|
||||||
public Set<Map<String, String>> initializeEdgeSchema() {
|
public Set<Map<String, String>> initializeEdgeSchema() {
|
||||||
|
|
||||||
Set<Map<String, String>> edgeSchema = new HashSet<Map<String, String>>();
|
Set<Map<String, String>> edgeSchema = new HashSet<Map<String, String>>();
|
||||||
|
|
|
@ -5,6 +5,7 @@ package edu.cornell.mannlib.vitro.webapp.visualization.personlevel;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.visualization.collaborationutils.CoAuthorshipData;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
|
@ -169,25 +170,29 @@ public class PersonLevelRequestHandler implements VisualizationRequestHandler {
|
||||||
new CoAuthorshipQueryRunner(egoURI, vitroRequest.getRDFService(), log);
|
new CoAuthorshipQueryRunner(egoURI, vitroRequest.getRDFService(), log);
|
||||||
|
|
||||||
CollaborationData coAuthorshipData = coAuthorshipQueryManager.getQueryResult();
|
CollaborationData coAuthorshipData = coAuthorshipQueryManager.getQueryResult();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* When the front-end for the person level vis has to be displayed we render couple of
|
* 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
|
* sparklines. This will prepare all the data for the sparklines & other requested
|
||||||
* files.
|
* files.
|
||||||
* */
|
* */
|
||||||
SubEntity person = new SubEntity(egoURI,
|
SubEntity person = new SubEntity(egoURI,
|
||||||
UtilityFunctions
|
UtilityFunctions
|
||||||
.getIndividualLabelFromDAO(vitroRequest, egoURI));
|
.getIndividualLabelFromDAO(vitroRequest, egoURI));
|
||||||
|
|
||||||
|
Map<String, Activity> publicationsToURI;
|
||||||
|
if (coAuthorshipData instanceof CoAuthorshipData) {
|
||||||
|
publicationsToURI = ((CoAuthorshipData)coAuthorshipData).getDocuments();
|
||||||
|
} else {
|
||||||
|
publicationsToURI = SelectOnModelUtilities.getPublicationsForPerson(dataset, person, false);
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, Activity> publicationsToURI = SelectOnModelUtilities.getPublicationsForPerson(dataset, person, false);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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.
|
||||||
* */
|
* */
|
||||||
Map<String, Integer> yearToPublicationCount =
|
Map<String, Integer> yearToPublicationCount =
|
||||||
UtilityFunctions.getYearToActivityCount(publicationsToURI.values());
|
UtilityFunctions.getYearToActivityCount(publicationsToURI.values());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Computations required to generate HTML for the sparklines & related context.
|
* Computations required to generate HTML for the sparklines & related context.
|
||||||
* */
|
* */
|
||||||
|
|
Loading…
Add table
Reference in a new issue