[VIVO-1031] Use streaming result set for co- visualisations
This commit is contained in:
parent
208f103629
commit
8fc40fcf98
2 changed files with 457 additions and 485 deletions
|
@ -16,6 +16,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
import com.hp.hpl.jena.query.ResultSetFactory;
|
import com.hp.hpl.jena.query.ResultSetFactory;
|
||||||
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 net.sf.jga.algorithms.Unique;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.jena.iri.IRI;
|
import org.apache.jena.iri.IRI;
|
||||||
|
@ -23,7 +25,6 @@ import org.apache.jena.iri.IRIFactory;
|
||||||
import org.apache.jena.iri.Violation;
|
import org.apache.jena.iri.Violation;
|
||||||
|
|
||||||
import com.hp.hpl.jena.query.QuerySolution;
|
import com.hp.hpl.jena.query.QuerySolution;
|
||||||
import com.hp.hpl.jena.query.ResultSet;
|
|
||||||
import com.hp.hpl.jena.query.Syntax;
|
import com.hp.hpl.jena.query.Syntax;
|
||||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||||
|
|
||||||
|
@ -58,10 +59,6 @@ public class CoAuthorshipQueryRunner implements QueryRunner<CollaborationData> {
|
||||||
|
|
||||||
private Log log;
|
private Log log;
|
||||||
|
|
||||||
private UniqueIDGenerator nodeIDGenerator;
|
|
||||||
|
|
||||||
private UniqueIDGenerator edgeIDGenerator;
|
|
||||||
|
|
||||||
public CoAuthorshipQueryRunner(String egoURI,
|
public CoAuthorshipQueryRunner(String egoURI,
|
||||||
RDFService rdfService, Log log) {
|
RDFService rdfService, Log log) {
|
||||||
|
|
||||||
|
@ -69,18 +66,13 @@ public class CoAuthorshipQueryRunner implements QueryRunner<CollaborationData> {
|
||||||
this.rdfService = rdfService;
|
this.rdfService = rdfService;
|
||||||
this.log = log;
|
this.log = log;
|
||||||
|
|
||||||
this.nodeIDGenerator = new UniqueIDGenerator();
|
|
||||||
this.edgeIDGenerator = new UniqueIDGenerator();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CollaborationData createQueryResult(ResultSet resultSet) {
|
private static class QueryResultConsumer extends ResultSetConsumer {
|
||||||
|
|
||||||
Set<Collaborator> nodes = new HashSet<Collaborator>();
|
Set<Collaborator> nodes = new HashSet<Collaborator>();
|
||||||
|
|
||||||
Map<String, Activity> biboDocumentURLToVO = new HashMap<String, Activity>();
|
Map<String, Activity> biboDocumentURLToVO = new HashMap<String, Activity>();
|
||||||
Map<String, Set<Collaborator>> biboDocumentURLToCoAuthors =
|
Map<String, Set<Collaborator>> biboDocumentURLToCoAuthors = new HashMap<String, Set<Collaborator>>();
|
||||||
new HashMap<String, Set<Collaborator>>();
|
|
||||||
Map<String, Collaborator> nodeURLToVO = new HashMap<String, Collaborator>();
|
Map<String, Collaborator> nodeURLToVO = new HashMap<String, Collaborator>();
|
||||||
Map<String, Collaboration> edgeUniqueIdentifierToVO = new HashMap<String, Collaboration>();
|
Map<String, Collaboration> edgeUniqueIdentifierToVO = new HashMap<String, Collaboration>();
|
||||||
|
|
||||||
|
@ -88,13 +80,15 @@ public class CoAuthorshipQueryRunner implements QueryRunner<CollaborationData> {
|
||||||
|
|
||||||
Set<Collaboration> edges = new HashSet<Collaboration>();
|
Set<Collaboration> edges = new HashSet<Collaboration>();
|
||||||
|
|
||||||
while (resultSet.hasNext()) {
|
private UniqueIDGenerator nodeIDGenerator = new UniqueIDGenerator();
|
||||||
QuerySolution solution = resultSet.nextSolution();
|
private UniqueIDGenerator edgeIDGenerator = new UniqueIDGenerator();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void processQuerySolution(QuerySolution qs) {
|
||||||
/*
|
/*
|
||||||
* We only want to create only ONE ego node.
|
* We only want to create only ONE ego node.
|
||||||
* */
|
* */
|
||||||
RDFNode egoAuthorURLNode = solution.get(QueryFieldLabels.AUTHOR_URL);
|
RDFNode egoAuthorURLNode = qs.get(QueryFieldLabels.AUTHOR_URL);
|
||||||
if (nodeURLToVO.containsKey(egoAuthorURLNode.toString())) {
|
if (nodeURLToVO.containsKey(egoAuthorURLNode.toString())) {
|
||||||
|
|
||||||
egoNode = nodeURLToVO.get(egoAuthorURLNode.toString());
|
egoNode = nodeURLToVO.get(egoAuthorURLNode.toString());
|
||||||
|
@ -105,19 +99,19 @@ public class CoAuthorshipQueryRunner implements QueryRunner<CollaborationData> {
|
||||||
nodes.add(egoNode);
|
nodes.add(egoNode);
|
||||||
nodeURLToVO.put(egoAuthorURLNode.toString(), egoNode);
|
nodeURLToVO.put(egoAuthorURLNode.toString(), egoNode);
|
||||||
|
|
||||||
RDFNode authorLabelNode = solution.get(QueryFieldLabels.AUTHOR_LABEL);
|
RDFNode authorLabelNode = qs.get(QueryFieldLabels.AUTHOR_LABEL);
|
||||||
if (authorLabelNode != null) {
|
if (authorLabelNode != null) {
|
||||||
egoNode.setCollaboratorName(authorLabelNode.toString());
|
egoNode.setCollaboratorName(authorLabelNode.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RDFNode documentNode = solution.get(QueryFieldLabels.DOCUMENT_URL);
|
RDFNode documentNode = qs.get(QueryFieldLabels.DOCUMENT_URL);
|
||||||
Activity biboDocument;
|
Activity biboDocument;
|
||||||
|
|
||||||
if (biboDocumentURLToVO.containsKey(documentNode.toString())) {
|
if (biboDocumentURLToVO.containsKey(documentNode.toString())) {
|
||||||
biboDocument = biboDocumentURLToVO.get(documentNode.toString());
|
biboDocument = biboDocumentURLToVO.get(documentNode.toString());
|
||||||
} else {
|
} else {
|
||||||
biboDocument = createDocumentVO(solution, documentNode.toString());
|
biboDocument = createDocumentVO(qs, documentNode.toString());
|
||||||
biboDocumentURLToVO.put(documentNode.toString(), biboDocument);
|
biboDocumentURLToVO.put(documentNode.toString(), biboDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,14 +122,14 @@ public class CoAuthorshipQueryRunner implements QueryRunner<CollaborationData> {
|
||||||
* we do not want a co-author node or Collaboration if the publication has only one
|
* we do not want a co-author node or Collaboration if the publication has only one
|
||||||
* author and that happens to be the ego.
|
* author and that happens to be the ego.
|
||||||
* */
|
* */
|
||||||
if (solution.get(QueryFieldLabels.AUTHOR_URL).toString().equalsIgnoreCase(
|
if (qs.get(QueryFieldLabels.AUTHOR_URL).toString().equalsIgnoreCase(
|
||||||
solution.get(QueryFieldLabels.CO_AUTHOR_URL).toString())) {
|
qs.get(QueryFieldLabels.CO_AUTHOR_URL).toString())) {
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Collaborator coAuthorNode;
|
Collaborator coAuthorNode;
|
||||||
|
|
||||||
RDFNode coAuthorURLNode = solution.get(QueryFieldLabels.CO_AUTHOR_URL);
|
RDFNode coAuthorURLNode = qs.get(QueryFieldLabels.CO_AUTHOR_URL);
|
||||||
if (nodeURLToVO.containsKey(coAuthorURLNode.toString())) {
|
if (nodeURLToVO.containsKey(coAuthorURLNode.toString())) {
|
||||||
|
|
||||||
coAuthorNode = nodeURLToVO.get(coAuthorURLNode.toString());
|
coAuthorNode = nodeURLToVO.get(coAuthorURLNode.toString());
|
||||||
|
@ -146,7 +140,7 @@ public class CoAuthorshipQueryRunner implements QueryRunner<CollaborationData> {
|
||||||
nodes.add(coAuthorNode);
|
nodes.add(coAuthorNode);
|
||||||
nodeURLToVO.put(coAuthorURLNode.toString(), coAuthorNode);
|
nodeURLToVO.put(coAuthorURLNode.toString(), coAuthorNode);
|
||||||
|
|
||||||
RDFNode coAuthorLabelNode = solution.get(QueryFieldLabels.CO_AUTHOR_LABEL);
|
RDFNode coAuthorLabelNode = qs.get(QueryFieldLabels.CO_AUTHOR_LABEL);
|
||||||
if (coAuthorLabelNode != null) {
|
if (coAuthorLabelNode != null) {
|
||||||
coAuthorNode.setCollaboratorName(coAuthorLabelNode.toString());
|
coAuthorNode.setCollaboratorName(coAuthorLabelNode.toString());
|
||||||
}
|
}
|
||||||
|
@ -186,12 +180,10 @@ public class CoAuthorshipQueryRunner implements QueryRunner<CollaborationData> {
|
||||||
coAuthorNode.getCollaboratorID()),
|
coAuthorNode.getCollaboratorID()),
|
||||||
egoCoAuthorEdge);
|
egoCoAuthorEdge);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void endProcessing() {
|
||||||
/*
|
/*
|
||||||
* This method takes out all the authors & edges between authors that belong to documents
|
* This method takes out all the authors & edges between authors that belong to documents
|
||||||
* that have more than 100 authors. We conjecture that these papers do not provide much
|
* that have more than 100 authors. We conjecture that these papers do not provide much
|
||||||
|
@ -222,51 +214,33 @@ public class CoAuthorshipQueryRunner implements QueryRunner<CollaborationData> {
|
||||||
biboDocumentURLToCoAuthors,
|
biboDocumentURLToCoAuthors,
|
||||||
edges,
|
edges,
|
||||||
edgeUniqueIdentifierToVO);
|
edgeUniqueIdentifierToVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CollaborationData getCollaborationData() {
|
||||||
return new CoAuthorshipData(egoNode, nodes, edges);
|
return new CoAuthorshipData(egoNode, nodes, edges);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeLowQualityNodesAndEdges(
|
private Activity createDocumentVO(QuerySolution solution, String documentURL) {
|
||||||
Set<Collaborator> nodes,
|
|
||||||
Map<String, Activity> biboDocumentURLToVO,
|
|
||||||
Map<String, Set<Collaborator>> biboDocumentURLToCoAuthors,
|
|
||||||
Set<Collaboration> edges) {
|
|
||||||
|
|
||||||
Set<Collaborator> nodesToBeRemoved = new HashSet<Collaborator>();
|
Activity biboDocument = new Activity(documentURL);
|
||||||
for (Map.Entry<String, Set<Collaborator>> currentBiboDocumentEntry
|
|
||||||
: biboDocumentURLToCoAuthors.entrySet()) {
|
|
||||||
|
|
||||||
if (currentBiboDocumentEntry.getValue().size() > MAX_AUTHORS_PER_PAPER_ALLOWED) {
|
RDFNode publicationDateNode = solution.get(QueryFieldLabels.DOCUMENT_PUBLICATION_DATE);
|
||||||
|
if (publicationDateNode != null) {
|
||||||
Activity currentBiboDocument = biboDocumentURLToVO
|
biboDocument.setActivityDate(publicationDateNode.toString());
|
||||||
.get(currentBiboDocumentEntry.getKey());
|
|
||||||
|
|
||||||
Set<Collaboration> edgesToBeRemoved = new HashSet<Collaboration>();
|
|
||||||
|
|
||||||
for (Collaboration currentEdge : edges) {
|
|
||||||
Set<Activity> currentCollaboratorDocuments =
|
|
||||||
currentEdge.getCollaborationActivities();
|
|
||||||
|
|
||||||
if (currentCollaboratorDocuments.contains(currentBiboDocument)) {
|
|
||||||
currentCollaboratorDocuments.remove(currentBiboDocument);
|
|
||||||
if (currentCollaboratorDocuments.isEmpty()) {
|
|
||||||
edgesToBeRemoved.add(currentEdge);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
edges.removeAll(edgesToBeRemoved);
|
return biboDocument;
|
||||||
|
}
|
||||||
|
|
||||||
for (Collaborator currentCoAuthor : currentBiboDocumentEntry.getValue()) {
|
private String getEdgeUniqueIdentifier(int nodeID1, int nodeID2) {
|
||||||
currentCoAuthor.getCollaboratorActivities().remove(currentBiboDocument);
|
String separator = "*";
|
||||||
if (currentCoAuthor.getCollaboratorActivities().isEmpty()) {
|
|
||||||
nodesToBeRemoved.add(currentCoAuthor);
|
if (nodeID1 < nodeID2) {
|
||||||
|
return nodeID1 + separator + nodeID2;
|
||||||
|
} else {
|
||||||
|
return nodeID2 + separator + nodeID1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
nodes.removeAll(nodesToBeRemoved);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createCoAuthorEdges(
|
private void createCoAuthorEdges(
|
||||||
|
@ -334,7 +308,6 @@ public class CoAuthorshipQueryRunner implements QueryRunner<CollaborationData> {
|
||||||
}
|
}
|
||||||
edges.addAll(newlyAddedEdges);
|
edges.addAll(newlyAddedEdges);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,28 +324,49 @@ public class CoAuthorshipQueryRunner implements QueryRunner<CollaborationData> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getEdgeUniqueIdentifier(int nodeID1, int nodeID2) {
|
private void removeLowQualityNodesAndEdges(
|
||||||
|
Set<Collaborator> nodes,
|
||||||
|
Map<String, Activity> biboDocumentURLToVO,
|
||||||
|
Map<String, Set<Collaborator>> biboDocumentURLToCoAuthors,
|
||||||
|
Set<Collaboration> edges) {
|
||||||
|
|
||||||
String separator = "*";
|
Set<Collaborator> nodesToBeRemoved = new HashSet<Collaborator>();
|
||||||
|
for (Map.Entry<String, Set<Collaborator>> currentBiboDocumentEntry
|
||||||
|
: biboDocumentURLToCoAuthors.entrySet()) {
|
||||||
|
|
||||||
if (nodeID1 < nodeID2) {
|
if (currentBiboDocumentEntry.getValue().size() > MAX_AUTHORS_PER_PAPER_ALLOWED) {
|
||||||
return nodeID1 + separator + nodeID2;
|
|
||||||
} else {
|
Activity currentBiboDocument = biboDocumentURLToVO
|
||||||
return nodeID2 + separator + nodeID1;
|
.get(currentBiboDocumentEntry.getKey());
|
||||||
|
|
||||||
|
Set<Collaboration> edgesToBeRemoved = new HashSet<Collaboration>();
|
||||||
|
|
||||||
|
for (Collaboration currentEdge : edges) {
|
||||||
|
Set<Activity> currentCollaboratorDocuments =
|
||||||
|
currentEdge.getCollaborationActivities();
|
||||||
|
|
||||||
|
if (currentCollaboratorDocuments.contains(currentBiboDocument)) {
|
||||||
|
currentCollaboratorDocuments.remove(currentBiboDocument);
|
||||||
|
if (currentCollaboratorDocuments.isEmpty()) {
|
||||||
|
edgesToBeRemoved.add(currentEdge);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
edges.removeAll(edgesToBeRemoved);
|
||||||
|
|
||||||
|
for (Collaborator currentCoAuthor : currentBiboDocumentEntry.getValue()) {
|
||||||
|
currentCoAuthor.getCollaboratorActivities().remove(currentBiboDocument);
|
||||||
|
if (currentCoAuthor.getCollaboratorActivities().isEmpty()) {
|
||||||
|
nodesToBeRemoved.add(currentCoAuthor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nodes.removeAll(nodesToBeRemoved);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Activity createDocumentVO(QuerySolution solution, String documentURL) {
|
/* END QUERY RUNNER */
|
||||||
|
|
||||||
Activity biboDocument = new Activity(documentURL);
|
|
||||||
|
|
||||||
RDFNode publicationDateNode = solution.get(QueryFieldLabels.DOCUMENT_PUBLICATION_DATE);
|
|
||||||
if (publicationDateNode != null) {
|
|
||||||
biboDocument.setActivityDate(publicationDateNode.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return biboDocument;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String generateEgoCoAuthorshipSparqlQuery(String queryURI) {
|
private String generateEgoCoAuthorshipSparqlQuery(String queryURI) {
|
||||||
|
@ -455,19 +449,13 @@ public class CoAuthorshipQueryRunner implements QueryRunner<CollaborationData> {
|
||||||
throw new MalformedQueryParametersException("URI parameter is either null or empty.");
|
throw new MalformedQueryParametersException("URI parameter is either null or empty.");
|
||||||
}
|
}
|
||||||
|
|
||||||
InputStream is = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
try {
|
try {
|
||||||
is = rdfService.sparqlSelectQuery(generateEgoCoAuthorshipSparqlQuery(this.egoURI), RDFService.ResultFormat.JSON);
|
QueryResultConsumer consumer = new QueryResultConsumer();
|
||||||
rs = ResultSetFactory.fromJSON(is);
|
rdfService.sparqlSelectQuery(generateEgoCoAuthorshipSparqlQuery(this.egoURI), consumer);
|
||||||
data = createQueryResult(rs);
|
data = consumer.getCollaborationData();
|
||||||
} catch (RDFServiceException e) {
|
} catch (RDFServiceException e) {
|
||||||
log.error("Unable to execute query", e);
|
log.error("Unable to execute query", e);
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
|
||||||
if (is != null) {
|
|
||||||
try { is.close(); } catch (Throwable t) { }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CollaborationDataCacheEntry newEntry = new CollaborationDataCacheEntry();
|
CollaborationDataCacheEntry newEntry = new CollaborationDataCacheEntry();
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.visualization.coprincipalinvestigator;
|
package edu.cornell.mannlib.vitro.webapp.visualization.coprincipalinvestigator;
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -13,9 +12,9 @@ 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.ResultSetFactory;
|
|
||||||
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 org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
@ -23,14 +22,8 @@ import org.apache.jena.iri.IRI;
|
||||||
import org.apache.jena.iri.IRIFactory;
|
import org.apache.jena.iri.IRIFactory;
|
||||||
import org.apache.jena.iri.Violation;
|
import org.apache.jena.iri.Violation;
|
||||||
|
|
||||||
import com.hp.hpl.jena.query.Query;
|
|
||||||
import com.hp.hpl.jena.query.QueryExecution;
|
|
||||||
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
|
||||||
import com.hp.hpl.jena.query.QueryFactory;
|
|
||||||
import com.hp.hpl.jena.query.QuerySolution;
|
import com.hp.hpl.jena.query.QuerySolution;
|
||||||
import com.hp.hpl.jena.query.ResultSet;
|
|
||||||
import com.hp.hpl.jena.query.Syntax;
|
import com.hp.hpl.jena.query.Syntax;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
|
||||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.visualization.collaborationutils.CoInvestigationData;
|
import edu.cornell.mannlib.vitro.webapp.visualization.collaborationutils.CoInvestigationData;
|
||||||
|
@ -60,10 +53,6 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CollaborationData>
|
||||||
|
|
||||||
private Log log = LogFactory.getLog(CoPIGrantCountQueryRunner.class.getName());
|
private Log log = LogFactory.getLog(CoPIGrantCountQueryRunner.class.getName());
|
||||||
|
|
||||||
private UniqueIDGenerator nodeIDGenerator;
|
|
||||||
|
|
||||||
private UniqueIDGenerator edgeIDGenerator;
|
|
||||||
|
|
||||||
private long before, after;
|
private long before, after;
|
||||||
|
|
||||||
private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME = ""
|
private static final String SPARQL_QUERY_COMMON_OPTIONAL_BLOCK_FOR_ROLE_DATE_TIME = ""
|
||||||
|
@ -95,9 +84,6 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CollaborationData>
|
||||||
this.egoURI = egoURI;
|
this.egoURI = egoURI;
|
||||||
this.rdfService = rdfService;
|
this.rdfService = rdfService;
|
||||||
// this.log = log;
|
// this.log = log;
|
||||||
|
|
||||||
this.nodeIDGenerator = new UniqueIDGenerator();
|
|
||||||
this.edgeIDGenerator = new UniqueIDGenerator();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String generateEgoCoPIquery(String queryURI) {
|
private String generateEgoCoPIquery(String queryURI) {
|
||||||
|
@ -294,19 +280,13 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CollaborationData>
|
||||||
|
|
||||||
before = System.currentTimeMillis();
|
before = System.currentTimeMillis();
|
||||||
|
|
||||||
InputStream is = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
try {
|
try {
|
||||||
is = rdfService.sparqlSelectQuery(generateEgoCoPIquery(this.egoURI), RDFService.ResultFormat.JSON);
|
QueryResultConsumer consumer = new QueryResultConsumer();
|
||||||
rs = ResultSetFactory.fromJSON(is);
|
rdfService.sparqlSelectQuery(generateEgoCoPIquery(this.egoURI), consumer);
|
||||||
data = createQueryResult(rs);
|
data = consumer.getData();
|
||||||
} catch (RDFServiceException e) {
|
} catch (RDFServiceException e) {
|
||||||
log.error("Unable to execute query", e);
|
log.error("Unable to execute query", e);
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
|
||||||
if (is != null) {
|
|
||||||
try { is.close(); } catch (Throwable t) { }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
after = System.currentTimeMillis();
|
after = System.currentTimeMillis();
|
||||||
|
|
||||||
|
@ -356,34 +336,7 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CollaborationData>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class QueryResultConsumer extends ResultSetConsumer {
|
||||||
private Collaboration getExistingEdge(
|
|
||||||
Collaborator collaboratingNode1,
|
|
||||||
Collaborator collaboratingNode2,
|
|
||||||
Map<String, Collaboration> edgeUniqueIdentifierToVO) {
|
|
||||||
|
|
||||||
String edgeUniqueIdentifier = getEdgeUniqueIdentifier(
|
|
||||||
collaboratingNode1.getCollaboratorID(),
|
|
||||||
collaboratingNode2.getCollaboratorID());
|
|
||||||
|
|
||||||
return edgeUniqueIdentifierToVO.get(edgeUniqueIdentifier);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getEdgeUniqueIdentifier(int nodeID1, int nodeID2) {
|
|
||||||
|
|
||||||
String separator = "*";
|
|
||||||
|
|
||||||
if (nodeID1 < nodeID2) {
|
|
||||||
return nodeID1 + separator + nodeID2;
|
|
||||||
} else {
|
|
||||||
return nodeID2 + separator + nodeID1;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private CollaborationData createQueryResult(ResultSet resultSet) {
|
|
||||||
|
|
||||||
Set<Collaborator> nodes = new HashSet<Collaborator>();
|
Set<Collaborator> nodes = new HashSet<Collaborator>();
|
||||||
|
|
||||||
Map<String, Activity> grantURLToVO = new HashMap<String, Activity>();
|
Map<String, Activity> grantURLToVO = new HashMap<String, Activity>();
|
||||||
|
@ -395,15 +348,17 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CollaborationData>
|
||||||
|
|
||||||
Set<Collaboration> edges = new HashSet<Collaboration>();
|
Set<Collaboration> edges = new HashSet<Collaboration>();
|
||||||
|
|
||||||
before = System.currentTimeMillis();
|
private UniqueIDGenerator nodeIDGenerator = new UniqueIDGenerator();
|
||||||
|
private UniqueIDGenerator edgeIDGenerator = new UniqueIDGenerator();
|
||||||
|
|
||||||
while (resultSet.hasNext()) {
|
private Log log = LogFactory.getLog(CoPIGrantCountQueryRunner.class.getName());
|
||||||
QuerySolution solution = resultSet.nextSolution();
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void processQuerySolution(QuerySolution qs) {
|
||||||
/*
|
/*
|
||||||
* We only want to create only ONE ego node.
|
* We only want to create only ONE ego node.
|
||||||
* */
|
* */
|
||||||
RDFNode egoPIURLNode = solution.get(QueryFieldLabels.PI_URL);
|
RDFNode egoPIURLNode = qs.get(QueryFieldLabels.PI_URL);
|
||||||
if (nodeURLToVO.containsKey(egoPIURLNode.toString())) {
|
if (nodeURLToVO.containsKey(egoPIURLNode.toString())) {
|
||||||
|
|
||||||
egoNode = nodeURLToVO.get(egoPIURLNode.toString());
|
egoNode = nodeURLToVO.get(egoPIURLNode.toString());
|
||||||
|
@ -415,20 +370,20 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CollaborationData>
|
||||||
nodeURLToVO.put(egoPIURLNode.toString(), egoNode);
|
nodeURLToVO.put(egoPIURLNode.toString(), egoNode);
|
||||||
|
|
||||||
|
|
||||||
RDFNode authorLabelNode = solution.get(QueryFieldLabels.PI_LABEL);
|
RDFNode authorLabelNode = qs.get(QueryFieldLabels.PI_LABEL);
|
||||||
if (authorLabelNode != null) {
|
if (authorLabelNode != null) {
|
||||||
egoNode.setCollaboratorName(authorLabelNode.toString());
|
egoNode.setCollaboratorName(authorLabelNode.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.debug("PI: " + egoNode.getIndividualLabel());
|
log.debug("PI: " + egoNode.getIndividualLabel());
|
||||||
|
|
||||||
RDFNode grantNode = solution.get(QueryFieldLabels.GRANT_URL);
|
RDFNode grantNode = qs.get(QueryFieldLabels.GRANT_URL);
|
||||||
Activity grant;
|
Activity grant;
|
||||||
|
|
||||||
if (grantURLToVO.containsKey(grantNode.toString())) {
|
if (grantURLToVO.containsKey(grantNode.toString())) {
|
||||||
grant = grantURLToVO.get(grantNode.toString());
|
grant = grantURLToVO.get(grantNode.toString());
|
||||||
} else {
|
} else {
|
||||||
grant = createGrantVO(solution, grantNode.toString());
|
grant = createGrantVO(qs, grantNode.toString());
|
||||||
grantURLToVO.put(grantNode.toString(), grant);
|
grantURLToVO.put(grantNode.toString(), grant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,14 +395,14 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CollaborationData>
|
||||||
* we do not want a co-pi node or edge if the grant has only one
|
* we do not want a co-pi node or edge if the grant has only one
|
||||||
* pi and that happens to be the ego.
|
* pi and that happens to be the ego.
|
||||||
* */
|
* */
|
||||||
if (solution.get(QueryFieldLabels.PI_URL).toString().equalsIgnoreCase(
|
if (qs.get(QueryFieldLabels.PI_URL).toString().equalsIgnoreCase(
|
||||||
solution.get(QueryFieldLabels.CO_PI_URL).toString())) {
|
qs.get(QueryFieldLabels.CO_PI_URL).toString())) {
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Collaborator coPINode;
|
Collaborator coPINode;
|
||||||
|
|
||||||
RDFNode coPIURLNode = solution.get(QueryFieldLabels.CO_PI_URL);
|
RDFNode coPIURLNode = qs.get(QueryFieldLabels.CO_PI_URL);
|
||||||
if (nodeURLToVO.containsKey(coPIURLNode.toString())) {
|
if (nodeURLToVO.containsKey(coPIURLNode.toString())) {
|
||||||
|
|
||||||
coPINode = nodeURLToVO.get(coPIURLNode.toString());
|
coPINode = nodeURLToVO.get(coPIURLNode.toString());
|
||||||
|
@ -458,7 +413,7 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CollaborationData>
|
||||||
nodes.add(coPINode);
|
nodes.add(coPINode);
|
||||||
nodeURLToVO.put(coPIURLNode.toString(), coPINode);
|
nodeURLToVO.put(coPIURLNode.toString(), coPINode);
|
||||||
|
|
||||||
RDFNode coPILabelNode = solution.get(QueryFieldLabels.CO_PI_LABEL);
|
RDFNode coPILabelNode = qs.get(QueryFieldLabels.CO_PI_LABEL);
|
||||||
if (coPILabelNode != null) {
|
if (coPILabelNode != null) {
|
||||||
coPINode.setCollaboratorName(coPILabelNode.toString());
|
coPINode.setCollaboratorName(coPILabelNode.toString());
|
||||||
}
|
}
|
||||||
|
@ -497,9 +452,12 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CollaborationData>
|
||||||
coPINode.getCollaboratorID()),
|
coPINode.getCollaboratorID()),
|
||||||
egoCoPIEdge);
|
egoCoPIEdge);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void endProcessing() {
|
||||||
|
super.endProcessing();
|
||||||
/*
|
/*
|
||||||
* This method takes out all the PIs & edges between PIs that belong to grants
|
* This method takes out all the PIs & edges between PIs that belong to grants
|
||||||
* that have more than 100 PIs. We conjecture that these grants do not provide much
|
* that have more than 100 PIs. We conjecture that these grants do not provide much
|
||||||
|
@ -528,11 +486,10 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CollaborationData>
|
||||||
grantURLToCoPIs,
|
grantURLToCoPIs,
|
||||||
edges,
|
edges,
|
||||||
edgeUniqueIdentifierToVO);
|
edgeUniqueIdentifierToVO);
|
||||||
|
}
|
||||||
|
|
||||||
after = System.currentTimeMillis();
|
|
||||||
log.debug("Time taken to iterate through the ResultSet of SELECT queries is in ms: "
|
|
||||||
+ (after - before));
|
|
||||||
|
|
||||||
|
public CollaborationData getData() {
|
||||||
return new CoInvestigationData(egoNode, nodes, edges);
|
return new CoInvestigationData(egoNode, nodes, edges);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -674,4 +631,31 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CollaborationData>
|
||||||
|
|
||||||
return grant;
|
return grant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Collaboration getExistingEdge(
|
||||||
|
Collaborator collaboratingNode1,
|
||||||
|
Collaborator collaboratingNode2,
|
||||||
|
Map<String, Collaboration> edgeUniqueIdentifierToVO) {
|
||||||
|
|
||||||
|
String edgeUniqueIdentifier = getEdgeUniqueIdentifier(
|
||||||
|
collaboratingNode1.getCollaboratorID(),
|
||||||
|
collaboratingNode2.getCollaboratorID());
|
||||||
|
|
||||||
|
return edgeUniqueIdentifierToVO.get(edgeUniqueIdentifier);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getEdgeUniqueIdentifier(int nodeID1, int nodeID2) {
|
||||||
|
|
||||||
|
String separator = "*";
|
||||||
|
|
||||||
|
if (nodeID1 < nodeID2) {
|
||||||
|
return nodeID1 + separator + nodeID2;
|
||||||
|
} else {
|
||||||
|
return nodeID2 + separator + nodeID1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/** END QUERY RESULT CONSUMER **/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue