VIVO-285: visualization updates for ISF

This commit is contained in:
tworrall 2013-09-30 09:30:34 -04:00
parent d71c995e0e
commit 83b3f755d5
27 changed files with 2743 additions and 2524 deletions

View file

@ -25,11 +25,14 @@
?dateTimeEnd
WHERE {
?subject ?property ?advisory
?subject ?property ?advisory .
?advisory core:relates ?advisor .
?advisor <http://purl.obolibrary.org/obo/RO_0000053> ?advisorRole .
LET ( ?localName := afn:localname(?advisory) )
OPTIONAL { ?advisory rdfs:label ?advisoryLabel }
OPTIONAL { ?advisory core:relates ?advisee .
?advisee a foaf:Person .
?advisee <http://purl.obolibrary.org/obo/RO_0000053> ?adviseeRole
OPTIONAL { ?advisee rdfs:label ?adviseeLabel }
}
OPTIONAL { ?advisory core:relates ?degree .
@ -74,7 +77,10 @@
?subject ?property ?advisory .
?advisory a core:AdvisingRelationship .
?advisory ?advisoryProperty ?advisoryValue .
?advisory rdfs:label ?advisoryLabel
?advisory rdfs:label ?advisoryLabel .
?advisory core:relates ?advisor .
?advisor <http://purl.obolibrary.org/obo/RO_0000053> ?advisorRole .
?advisorRole a core:AdvisorRole
} WHERE {
{
?subject ?property ?advisory .
@ -88,10 +94,23 @@
?advisory a core:AdvisingRelationship .
?advisory ?advisoryProperty ?advisoryValue .
?advisory rdfs:label ?advisoryLabel
} UNION {
?subject ?property ?advisory .
?advisory a core:AdvisingRelationship .
?advisory ?advisoryProperty ?advisoryValue .
?advisory core:relates ?advisor .
?advisor <http://purl.obolibrary.org/obo/RO_0000053> ?advisorRole .
?advisorRole a core:AdvisorRole
}
}
</query-construct>
OPTIONAL { ?advisory core:relates ?advisee .
?advisee a foaf:Person .
?advisee &lt;http://purl.obolibrary.org/obo/RO_0000053&gt; ?adviseeRole
<query-construct>
PREFIX bibo: &lt;http://purl.org/ontology/bibo/&gt;
PREFIX core: &lt;http://vivoweb.org/ontology/core#&gt;
@ -104,6 +123,8 @@
?advisory core:relates ?advisee .
?advisee a foaf:Person .
?advisee rdfs:label ?adviseeLabel .
?advisee &lt;http://purl.obolibrary.org/obo/RO_0000053&gt; ?adviseeRole .
?adviseeRole a core:AdviseeRole .
?advisory core:relates ?degree .
?degree a core:AcademicDegree .
?degree rdfs:label ?degreeLabel .
@ -117,11 +138,15 @@
?advisory a core:AdvisingRelationship .
?advisory core:relates ?advisee .
?advisee a foaf:Person .
?advisee &lt;http://purl.obolibrary.org/obo/RO_0000053&gt; ?adviseeRole .
?adviseeRole a core:AdviseeRole
} UNION {
?subject ?property ?advisory .
?advisory a core:AdvisingRelationship .
?advisory core:relates ?advisee .
?advisee a foaf:Person .
?advisee &lt;http://purl.obolibrary.org/obo/RO_0000053&gt; ?adviseeRole .
?adviseeRole a core:AdviseeRole .
?advisee rdfs:label ?adviseeLabel
} UNION {
?subject ?property ?advisory .

View file

@ -3,12 +3,14 @@
<#-- Template for sparkline visualization on individual profile page -->
<#-- Determine whether this person is an author -->
<#assign isAuthor = p.hasStatements(propertyGroups, "${core}authorInAuthorship") />
<#assign isAuthor = p.hasVisualizationStatements(propertyGroups, "${core}relatedBy", "${core}Authorship") />
<#-- Determine whether this person is involved in any grants -->
<#assign isInvestigator = ( p.hasStatements(propertyGroups, "${core}hasInvestigatorRole") ||
p.hasStatements(propertyGroups, "${core}hasPrincipalInvestigatorRole") ||
p.hasStatements(propertyGroups, "${core}hasCo-PrincipalInvestigatorRole") ) >
<#assign obo_RO53 = "http://purl.obolibrary.org/obo/RO_0000053">
<#assign isInvestigator = ( p.hasVisualizationStatements(propertyGroups, "${obo_RO53}", "${core}InvestigatorRole") ||
p.hasVisualizationStatements(propertyGroups, "${obo_RO53}", "${core}PrincipalInvestigatorRole") ||
p.hasVisualizationStatements(propertyGroups, "${obo_RO53}", "${core}CoPrincipalInvestigatorRole") ) >
<#if (isAuthor || isInvestigator)>
@ -70,4 +72,4 @@
<div class="collaboratorship-link"><a href="${coInvestigatorVisUrl}" title="${i18n().co_investigator_network}">${i18n().co_investigator_network_capitalized}</a></div>
</div>
</#if>
</#if>
</#if>

View file

@ -16,7 +16,7 @@
<h1 id="noPubsOrGrants-header">${organizationLabel}</h1>
<h3 id="alternative-vis-info">${textForCurrentEntityComparisonType?capitalize} ${i18n().temporal_graph_capitalized}
<span id="noPubsOrGrants-span">|&nbsp;<a href="${temporalGraphURL}" title="${i18n().view}">${i18n().view} ${textForOtherEntityComparisonType} ${i18n().temporal_graph}</a></span>
<span id="noPubsOrGrants-span">|&nbsp;<a href="${temporalGraphURL}" title="${i18n().view}">${i18n().view}&nbsp${textForOtherEntityComparisonType}&nbsp;${i18n().temporal_graph}</a></span>
</h3>
<div id="error-body">
<p>${i18n().entity_comp_error_text1}

View file

@ -5,7 +5,7 @@
<h2>${i18n().visualization_tools}</h2>
<a href="${refreshCacheURL}">${i18n().refresh_cached_vis_model}</a>
<a href="${refreshCacheURL}">${i18n().refresh_cached_vis_models}</a>
<section class="visualizationTools">
<h3>${i18n().why_needed}</h3>
<p>${i18n().vis_tools_note_one}</p>

View file

@ -453,7 +453,7 @@ local:eventWithinConfig a :ObjectPropertyDisplayConfig ;
local:includesEventContext a :ConfigContext ;
:hasConfiguration local:includesEventConfig ;
:configContextFor <http://purl.obolibrary.org/obo/BFO_0000050> ;
:configContextFor <http://purl.obolibrary.org/obo/BFO_0000051> ;
:qualifiedByDomain <http://purl.org/NET/c4dm/event.owl#Event> ;
:qualifiedBy <http://purl.org/NET/c4dm/event.owl#Event> .
@ -467,11 +467,11 @@ local:includesEventConfig a :ObjectPropertyDisplayConfig ;
local:inEventSeriesContext a :ConfigContext ;
:hasConfiguration local:inEventSeriesConfig ;
:configContextFor <http://purl.obolibrary.org/obo/BFO_0000051> ;
:configContextFor <http://purl.obolibrary.org/obo/BFO_0000050> ;
:qualifiedByDomain <http://purl.org/NET/c4dm/event.owl#Event> ;
:qualifiedBy <http://purl.org/NET/c4dm/event.owl#EventSeries> .
local:includesEventConfig a :ObjectPropertyDisplayConfig ;
local:inEventSeriesConfig a :ObjectPropertyDisplayConfig ;
:listViewConfigFile "listViewConfig-default.xml"^^xsd:string ;
:displayName "in event series" ;
vitro:displayRankAnnot 3;
@ -479,3 +479,16 @@ local:includesEventConfig a :ObjectPropertyDisplayConfig ;
vitro:prohibitedFromUpdateBelowRoleLevelAnnot role:public ;
:propertyGroup <http://vivoweb.org/ontology#vitroPropertyGroupoverview> .
local:awardAssignedByContext a :ConfigContext ;
:hasConfiguration local:awardAssignedByConfig ;
:configContextFor <http://vivoweb.org/ontology/core#assignedBy> ;
:qualifiedByDomain <http://vivoweb.org/ontology/core#Award> ;
:qualifiedBy <http://vivoweb.org/ontology/core#Award> .
local:awardAssignedByConfig a :ObjectPropertyDisplayConfig ;
:listViewConfigFile "listViewConfig-default.xml"^^xsd:string ;
:displayName "award conferred by" ;
vitro:displayRankAnnot 3;
vitro:hiddenFromDisplayBelowRoleLevelAnnot role:public ;
vitro:prohibitedFromUpdateBelowRoleLevelAnnot role:public ;
:propertyGroup <http://vivoweb.org/ontology#vitroPropertyGroupoverview> .

View file

@ -65,12 +65,14 @@ public class ManagePeopleForOrganizationController extends FreemarkerHttpServlet
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
+ "PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> \n"
+ "PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#> \n"
+ "PREFIX foaf: <http://xmlns.com/foaf/0.1/> \n"
+ "SELECT DISTINCT ?subclass ?position (str(?label) as ?name) ?person ?hideThis WHERE { \n"
+ " ?subject core:organizationForPosition ?position . \n"
+ " OPTIONAL { ?position core:positionForPerson ?person . "
+ " ?subject core:relatedBy ?position . \n"
+ " ?position a core:Position . \n"
+ " OPTIONAL { ?position core:relates ?person . "
+ " ?person a foaf:Person . \n"
+ " ?person rdfs:label ?label } \n"
+ " OPTIONAL { ?position vitro:mostSpecificType ?subclass . \n"
+ " ?subclass rdfs:subClassOf core:Position } \n"
+ " OPTIONAL { ?position vitro:mostSpecificType ?subclass } \n"
+ " OPTIONAL { ?position core:hideFromDisplay ?hideThis } \n "
+ "} ORDER BY ?subclass ?name";

View file

@ -209,25 +209,25 @@ public class PersonHasAwardOrHonorGenerator extends VivoBaseGenerator implements
"?awardReceipt <"+ descriptionPred +"> ?description .";
final static String n3ForExistingOrgNewAwardAssertion =
"?award <" + awardConferredByPred +"> ?existingOrg . \n" +
"?existingOrg <" + awardConferredPred + "> ?award . \n" +
"?awardReceipt <" + awardConferredByPred +"> ?existingOrg . \n" +
"?existingOrg <" + awardConferredPred + "> ?awardReceipt . \n" +
"?award <"+ label + "> ?awardLabel .";
final static String n3ForExistingOrgExistingAwardAssertion =
"?existingAward <" + awardConferredByPred +"> ?existingOrg . \n" +
"?existingOrg <" + awardConferredPred + "> ?existingAward . ";
"?awardReceipt <" + awardConferredByPred +"> ?existingOrg . \n" +
"?existingOrg <" + awardConferredPred + "> ?awardReceipt . ";
final static String n3ForNewOrgNewAwardAssertion =
"?newOrg a <" + orgClass + "> . \n" +
"?award <" + awardConferredByPred +"> ?newOrg . \n" +
"?newOrg <" + awardConferredPred + "> ?award . \n" +
"?awardReceipt <" + awardConferredByPred +"> ?newOrg . \n" +
"?newOrg <" + awardConferredPred + "> ?awardReceipt . \n" +
"?award <"+ label + "> ?awardLabel . \n" +
"?newOrg <"+ label + "> ?orgLabel .";
final static String n3ForNewOrgExistingAwardAssertion =
"?newOrg a <" + orgClass + "> . \n" +
"?existingAward <" + awardConferredByPred +"> ?newOrg . \n" +
"?newOrg <" + awardConferredPred + "> ?existingAward . \n" +
"?awardReceipt <" + awardConferredByPred +"> ?newOrg . \n" +
"?newOrg <" + awardConferredPred + "> ?awardReceipt . \n" +
"?newOrg <"+ label + "> ?orgLabel .";
final static String n3ForYearAwarded =

View file

@ -240,6 +240,8 @@ public class PersonHasEducationalTraining extends VivoBaseGenerator implements
"?newOrg <http://vivoweb.org/ontology/core#assigns> ?newAwardedDegree . \n" +
"?newOrg a ?orgType . \n" +
"?newOrg <"+ label +"> ?orgLabel . \n" +
"?edTraining <http://purl.obolibrary.org/obo/RO_0000057> ?newOrg . \n" +
"?newOrg <http://purl.obolibrary.org/obo/RO_0000056> ?edTraining . \n" +
"?newAwardedDegree <http://vivoweb.org/ontology/core#relates> ?degreeType .\n"+
"?degreeType <http://vivoweb.org/ontology/core#relatedBy> ?newAwardedDegree . \n"+
"?newAwardedDegree a core:AwardedDegree .";
@ -254,6 +256,8 @@ public class PersonHasEducationalTraining extends VivoBaseGenerator implements
"?existingOrg <http://vivoweb.org/ontology/core#assigns> ?newAwardedDegree . \n" +
"?newAwardedDegree <http://vivoweb.org/ontology/core#assignedBy> ?existingOrg . \n" +
"?newAwardedDegree <http://vivoweb.org/ontology/core#relates> ?degreeType .\n"+
"?edTraining <http://purl.obolibrary.org/obo/RO_0000057> ?existingOrg . \n" +
"?existingOrg <http://purl.obolibrary.org/obo/RO_0000056> ?edTraining . \n" +
"?degreeType <http://vivoweb.org/ontology/core#relatedBy> ?newAwardedDegree . \n"+
"?newAwardedDegree a core:AwardedDegree .";

View file

@ -1,442 +1,445 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.coauthorship;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import com.hp.hpl.jena.iri.IRI;
import com.hp.hpl.jena.iri.IRIFactory;
import com.hp.hpl.jena.iri.Violation;
import com.hp.hpl.jena.query.Dataset;
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.ResultSet;
import com.hp.hpl.jena.query.Syntax;
import com.hp.hpl.jena.rdf.model.RDFNode;
import edu.cornell.mannlib.vitro.webapp.visualization.collaborationutils.CoAuthorshipData;
import edu.cornell.mannlib.vitro.webapp.visualization.collaborationutils.CollaborationData;
import edu.cornell.mannlib.vitro.webapp.visualization.collaborationutils.CollaboratorComparator;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
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;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.QueryRunner;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.UniqueIDGenerator;
/**
* This query runner is used to execute a sparql query to get all the publications
* for a particular individual. It will also fetch all the authors that worked
* on that particular publication.
*
* @author cdtank
*/
public class CoAuthorshipQueryRunner implements QueryRunner<CollaborationData> {
private static final int MAX_AUTHORS_PER_PAPER_ALLOWED = 100;
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private String egoURI;
private Dataset dataset;
private Log log;
private UniqueIDGenerator nodeIDGenerator;
private UniqueIDGenerator edgeIDGenerator;
public CoAuthorshipQueryRunner(String egoURI,
Dataset dataset, Log log) {
this.egoURI = egoURI;
this.dataset = dataset;
this.log = log;
this.nodeIDGenerator = new UniqueIDGenerator();
this.edgeIDGenerator = new UniqueIDGenerator();
}
private CollaborationData createQueryResult(ResultSet resultSet) {
Set<Collaborator> nodes = new HashSet<Collaborator>();
Map<String, Activity> biboDocumentURLToVO = new HashMap<String, Activity>();
Map<String, Set<Collaborator>> biboDocumentURLToCoAuthors =
new HashMap<String, Set<Collaborator>>();
Map<String, Collaborator> nodeURLToVO = new HashMap<String, Collaborator>();
Map<String, Collaboration> edgeUniqueIdentifierToVO = new HashMap<String, Collaboration>();
Collaborator egoNode = null;
Set<Collaboration> edges = new HashSet<Collaboration>();
while (resultSet.hasNext()) {
QuerySolution solution = resultSet.nextSolution();
/*
* We only want to create only ONE ego node.
* */
RDFNode egoAuthorURLNode = solution.get(QueryFieldLabels.AUTHOR_URL);
if (nodeURLToVO.containsKey(egoAuthorURLNode.toString())) {
egoNode = nodeURLToVO.get(egoAuthorURLNode.toString());
} else {
egoNode = new Collaborator(egoAuthorURLNode.toString(), nodeIDGenerator);
nodes.add(egoNode);
nodeURLToVO.put(egoAuthorURLNode.toString(), egoNode);
RDFNode authorLabelNode = solution.get(QueryFieldLabels.AUTHOR_LABEL);
if (authorLabelNode != null) {
egoNode.setCollaboratorName(authorLabelNode.toString());
}
}
RDFNode documentNode = solution.get(QueryFieldLabels.DOCUMENT_URL);
Activity biboDocument;
if (biboDocumentURLToVO.containsKey(documentNode.toString())) {
biboDocument = biboDocumentURLToVO.get(documentNode.toString());
} else {
biboDocument = createDocumentVO(solution, documentNode.toString());
biboDocumentURLToVO.put(documentNode.toString(), biboDocument);
}
egoNode.addActivity(biboDocument);
/*
* After some discussion we concluded that for the purpose of this visualization
* we do not want a co-author node or Collaboration if the publication has only one
* author and that happens to be the ego.
* */
if (solution.get(QueryFieldLabels.AUTHOR_URL).toString().equalsIgnoreCase(
solution.get(QueryFieldLabels.CO_AUTHOR_URL).toString())) {
continue;
}
Collaborator coAuthorNode;
RDFNode coAuthorURLNode = solution.get(QueryFieldLabels.CO_AUTHOR_URL);
if (nodeURLToVO.containsKey(coAuthorURLNode.toString())) {
coAuthorNode = nodeURLToVO.get(coAuthorURLNode.toString());
} else {
coAuthorNode = new Collaborator(coAuthorURLNode.toString(), nodeIDGenerator);
nodes.add(coAuthorNode);
nodeURLToVO.put(coAuthorURLNode.toString(), coAuthorNode);
RDFNode coAuthorLabelNode = solution.get(QueryFieldLabels.CO_AUTHOR_LABEL);
if (coAuthorLabelNode != null) {
coAuthorNode.setCollaboratorName(coAuthorLabelNode.toString());
}
}
coAuthorNode.addActivity(biboDocument);
Set<Collaborator> coAuthorsForCurrentBiboDocument;
if (biboDocumentURLToCoAuthors.containsKey(biboDocument.getActivityURI())) {
coAuthorsForCurrentBiboDocument = biboDocumentURLToCoAuthors
.get(biboDocument.getActivityURI());
} else {
coAuthorsForCurrentBiboDocument = new HashSet<Collaborator>();
biboDocumentURLToCoAuthors.put(biboDocument.getActivityURI(),
coAuthorsForCurrentBiboDocument);
}
coAuthorsForCurrentBiboDocument.add(coAuthorNode);
Collaboration egoCoAuthorEdge =
getExistingEdge(egoNode, coAuthorNode, edgeUniqueIdentifierToVO);
/*
* If "egoCoAuthorEdge" is null it means that no Collaboration exists in between the
* egoNode & current coAuthorNode. Else create a new Collaboration, add it to the edges
* set & add the collaborator document to it.
* */
if (egoCoAuthorEdge != null) {
egoCoAuthorEdge.addActivity(biboDocument);
} else {
egoCoAuthorEdge =
new Collaboration(egoNode, coAuthorNode, biboDocument, edgeIDGenerator);
edges.add(egoCoAuthorEdge);
edgeUniqueIdentifierToVO.put(
getEdgeUniqueIdentifier(egoNode.getCollaboratorID(),
coAuthorNode.getCollaboratorID()),
egoCoAuthorEdge);
}
}
/*
* 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
* insight. However, we have left the documents be.
*
* This method side-effects "nodes" & "edges".
* */
removeLowQualityNodesAndEdges(nodes,
biboDocumentURLToVO,
biboDocumentURLToCoAuthors,
edges);
/*
* We need to create edges between 2 co-authors. E.g. On a paper there were 3 authors
* ego, A & B then we have already created edges like,
* ego - A
* ego - B
* The below sub-routine will take care of,
* A - B
*
* We are side-effecting "edges" here. The only reason to do this is because we are adding
* edges en masse for all the co-authors on all the publications considered so far. The
* other reason being we dont want to compare against 2 sets of edges (edges created before
* & co-author edges created during the course of this method) when we are creating a new
* Collaboration.
* */
createCoAuthorEdges(biboDocumentURLToVO,
biboDocumentURLToCoAuthors,
edges,
edgeUniqueIdentifierToVO);
return new CoAuthorshipData(egoNode, nodes, edges);
}
private void removeLowQualityNodesAndEdges(
Set<Collaborator> nodes,
Map<String, Activity> biboDocumentURLToVO,
Map<String, Set<Collaborator>> biboDocumentURLToCoAuthors,
Set<Collaboration> edges) {
Set<Collaborator> nodesToBeRemoved = new HashSet<Collaborator>();
for (Map.Entry<String, Set<Collaborator>> currentBiboDocumentEntry
: biboDocumentURLToCoAuthors.entrySet()) {
if (currentBiboDocumentEntry.getValue().size() > MAX_AUTHORS_PER_PAPER_ALLOWED) {
Activity currentBiboDocument = biboDocumentURLToVO
.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 void createCoAuthorEdges(
Map<String, Activity> biboDocumentURLToVO,
Map<String, Set<Collaborator>> biboDocumentURLToCoAuthors, Set<Collaboration> edges,
Map<String, Collaboration> edgeUniqueIdentifierToVO) {
for (Map.Entry<String, Set<Collaborator>> currentBiboDocumentEntry
: biboDocumentURLToCoAuthors.entrySet()) {
/*
* If there was only one co-author (other than ego) then we dont have to create any
* edges. so the below condition will take care of that.
*
* We are restricting edges between co-author if a particular document has more than
* 100 co-authors. Our conjecture is that such edges do not provide any good insight
* & causes unnecessary computations causing the server to time-out.
* */
if (currentBiboDocumentEntry.getValue().size() > 1
&& currentBiboDocumentEntry.getValue().size()
<= MAX_AUTHORS_PER_PAPER_ALLOWED) {
Set<Collaboration> newlyAddedEdges = new HashSet<Collaboration>();
/*
* In order to leverage the nested "for loop" for making edges between all the
* co-authors we need to create a list out of the set first.
* */
List<Collaborator> coAuthorNodes =
new ArrayList<Collaborator>(currentBiboDocumentEntry.getValue());
Collections.sort(coAuthorNodes, new CollaboratorComparator());
int numOfCoAuthors = coAuthorNodes.size();
for (int ii = 0; ii < numOfCoAuthors - 1; ii++) {
for (int jj = ii + 1; jj < numOfCoAuthors; jj++) {
Collaborator coAuthor1 = coAuthorNodes.get(ii);
Collaborator coAuthor2 = coAuthorNodes.get(jj);
Collaboration coAuthor1_2Edge = getExistingEdge(coAuthor1,
coAuthor2,
edgeUniqueIdentifierToVO);
Activity currentBiboDocument = biboDocumentURLToVO
.get(currentBiboDocumentEntry
.getKey());
if (coAuthor1_2Edge != null) {
coAuthor1_2Edge.addActivity(currentBiboDocument);
} else {
coAuthor1_2Edge = new Collaboration(coAuthor1,
coAuthor2,
currentBiboDocument,
edgeIDGenerator);
newlyAddedEdges.add(coAuthor1_2Edge);
edgeUniqueIdentifierToVO.put(
getEdgeUniqueIdentifier(coAuthor1.getCollaboratorID(),
coAuthor2.getCollaboratorID()),
coAuthor1_2Edge);
}
}
}
edges.addAll(newlyAddedEdges);
}
}
}
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 Activity createDocumentVO(QuerySolution solution, String documentURL) {
Activity biboDocument = new Activity(documentURL);
RDFNode publicationDateNode = solution.get(QueryFieldLabels.DOCUMENT_PUBLICATION_DATE);
if (publicationDateNode != null) {
biboDocument.setActivityDate(publicationDateNode.toString());
}
return biboDocument;
}
private ResultSet executeQuery(String queryText,
Dataset dataset) {
QueryExecution queryExecution = null;
Query query = QueryFactory.create(queryText, SYNTAX);
queryExecution = QueryExecutionFactory.create(query, dataset);
return queryExecution.execSelect();
}
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:authorInAuthorship ?authorshipNode . \n"
+ "?authorshipNode rdf:type core:Authorship ;"
+ " core:linkedInformationResource ?document . \n"
+ "?document core:informationResourceInAuthorship ?coAuthorshipNode . \n"
+ "?coAuthorshipNode core:linkedAuthor ?coAuthorPerson . \n"
+ "?coAuthorPerson rdfs:label ?coAuthorPersonLabel . \n"
+ "OPTIONAL { ?document core:dateTimeValue ?dateTimeValue . \n"
+ " ?dateTimeValue core:dateTime ?publicationDate } .\n"
+ "} \n"
+ "ORDER BY ?document ?coAuthorPerson\n";
log.debug("COAUTHORSHIP QUERY - " + sparqlQuery);
return sparqlQuery;
}
public CollaborationData getQueryResult()
throws MalformedQueryParametersException {
if (StringUtils.isNotBlank(this.egoURI)) {
/*
* To test for the validity of the URI submitted.
* */
IRIFactory iRIFactory = IRIFactory.jenaImplementation();
IRI iri = iRIFactory.create(this.egoURI);
if (iri.hasViolation(false)) {
String errorMsg = ((Violation) iri.violations(false).next()).getShortMessage();
log.error("Ego Co-Authorship Vis Query " + errorMsg);
throw new MalformedQueryParametersException(
"URI provided for an individual is malformed.");
}
} else {
throw new MalformedQueryParametersException("URI parameter is either null or empty.");
}
ResultSet resultSet = executeQuery(generateEgoCoAuthorshipSparqlQuery(this.egoURI),
this.dataset);
return createQueryResult(resultSet);
}
}
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.coauthorship;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import com.hp.hpl.jena.iri.IRI;
import com.hp.hpl.jena.iri.IRIFactory;
import com.hp.hpl.jena.iri.Violation;
import com.hp.hpl.jena.query.Dataset;
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.ResultSet;
import com.hp.hpl.jena.query.Syntax;
import com.hp.hpl.jena.rdf.model.RDFNode;
import edu.cornell.mannlib.vitro.webapp.visualization.collaborationutils.CoAuthorshipData;
import edu.cornell.mannlib.vitro.webapp.visualization.collaborationutils.CollaborationData;
import edu.cornell.mannlib.vitro.webapp.visualization.collaborationutils.CollaboratorComparator;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
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;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.QueryRunner;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.UniqueIDGenerator;
/**
* This query runner is used to execute a sparql query to get all the publications
* for a particular individual. It will also fetch all the authors that worked
* on that particular publication.
*
* @author cdtank
*/
public class CoAuthorshipQueryRunner implements QueryRunner<CollaborationData> {
private static final int MAX_AUTHORS_PER_PAPER_ALLOWED = 100;
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private String egoURI;
private Dataset dataset;
private Log log;
private UniqueIDGenerator nodeIDGenerator;
private UniqueIDGenerator edgeIDGenerator;
public CoAuthorshipQueryRunner(String egoURI,
Dataset dataset, Log log) {
this.egoURI = egoURI;
this.dataset = dataset;
this.log = log;
this.nodeIDGenerator = new UniqueIDGenerator();
this.edgeIDGenerator = new UniqueIDGenerator();
}
private CollaborationData createQueryResult(ResultSet resultSet) {
Set<Collaborator> nodes = new HashSet<Collaborator>();
Map<String, Activity> biboDocumentURLToVO = new HashMap<String, Activity>();
Map<String, Set<Collaborator>> biboDocumentURLToCoAuthors =
new HashMap<String, Set<Collaborator>>();
Map<String, Collaborator> nodeURLToVO = new HashMap<String, Collaborator>();
Map<String, Collaboration> edgeUniqueIdentifierToVO = new HashMap<String, Collaboration>();
Collaborator egoNode = null;
Set<Collaboration> edges = new HashSet<Collaboration>();
while (resultSet.hasNext()) {
QuerySolution solution = resultSet.nextSolution();
/*
* We only want to create only ONE ego node.
* */
RDFNode egoAuthorURLNode = solution.get(QueryFieldLabels.AUTHOR_URL);
if (nodeURLToVO.containsKey(egoAuthorURLNode.toString())) {
egoNode = nodeURLToVO.get(egoAuthorURLNode.toString());
} else {
egoNode = new Collaborator(egoAuthorURLNode.toString(), nodeIDGenerator);
nodes.add(egoNode);
nodeURLToVO.put(egoAuthorURLNode.toString(), egoNode);
RDFNode authorLabelNode = solution.get(QueryFieldLabels.AUTHOR_LABEL);
if (authorLabelNode != null) {
egoNode.setCollaboratorName(authorLabelNode.toString());
}
}
RDFNode documentNode = solution.get(QueryFieldLabels.DOCUMENT_URL);
Activity biboDocument;
if (biboDocumentURLToVO.containsKey(documentNode.toString())) {
biboDocument = biboDocumentURLToVO.get(documentNode.toString());
} else {
biboDocument = createDocumentVO(solution, documentNode.toString());
biboDocumentURLToVO.put(documentNode.toString(), biboDocument);
}
egoNode.addActivity(biboDocument);
/*
* After some discussion we concluded that for the purpose of this visualization
* we do not want a co-author node or Collaboration if the publication has only one
* author and that happens to be the ego.
* */
if (solution.get(QueryFieldLabels.AUTHOR_URL).toString().equalsIgnoreCase(
solution.get(QueryFieldLabels.CO_AUTHOR_URL).toString())) {
continue;
}
Collaborator coAuthorNode;
RDFNode coAuthorURLNode = solution.get(QueryFieldLabels.CO_AUTHOR_URL);
if (nodeURLToVO.containsKey(coAuthorURLNode.toString())) {
coAuthorNode = nodeURLToVO.get(coAuthorURLNode.toString());
} else {
coAuthorNode = new Collaborator(coAuthorURLNode.toString(), nodeIDGenerator);
nodes.add(coAuthorNode);
nodeURLToVO.put(coAuthorURLNode.toString(), coAuthorNode);
RDFNode coAuthorLabelNode = solution.get(QueryFieldLabels.CO_AUTHOR_LABEL);
if (coAuthorLabelNode != null) {
coAuthorNode.setCollaboratorName(coAuthorLabelNode.toString());
}
}
coAuthorNode.addActivity(biboDocument);
Set<Collaborator> coAuthorsForCurrentBiboDocument;
if (biboDocumentURLToCoAuthors.containsKey(biboDocument.getActivityURI())) {
coAuthorsForCurrentBiboDocument = biboDocumentURLToCoAuthors
.get(biboDocument.getActivityURI());
} else {
coAuthorsForCurrentBiboDocument = new HashSet<Collaborator>();
biboDocumentURLToCoAuthors.put(biboDocument.getActivityURI(),
coAuthorsForCurrentBiboDocument);
}
coAuthorsForCurrentBiboDocument.add(coAuthorNode);
Collaboration egoCoAuthorEdge =
getExistingEdge(egoNode, coAuthorNode, edgeUniqueIdentifierToVO);
/*
* If "egoCoAuthorEdge" is null it means that no Collaboration exists in between the
* egoNode & current coAuthorNode. Else create a new Collaboration, add it to the edges
* set & add the collaborator document to it.
* */
if (egoCoAuthorEdge != null) {
egoCoAuthorEdge.addActivity(biboDocument);
} else {
egoCoAuthorEdge =
new Collaboration(egoNode, coAuthorNode, biboDocument, edgeIDGenerator);
edges.add(egoCoAuthorEdge);
edgeUniqueIdentifierToVO.put(
getEdgeUniqueIdentifier(egoNode.getCollaboratorID(),
coAuthorNode.getCollaboratorID()),
egoCoAuthorEdge);
}
}
/*
* 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
* insight. However, we have left the documents be.
*
* This method side-effects "nodes" & "edges".
* */
removeLowQualityNodesAndEdges(nodes,
biboDocumentURLToVO,
biboDocumentURLToCoAuthors,
edges);
/*
* We need to create edges between 2 co-authors. E.g. On a paper there were 3 authors
* ego, A & B then we have already created edges like,
* ego - A
* ego - B
* The below sub-routine will take care of,
* A - B
*
* We are side-effecting "edges" here. The only reason to do this is because we are adding
* edges en masse for all the co-authors on all the publications considered so far. The
* other reason being we dont want to compare against 2 sets of edges (edges created before
* & co-author edges created during the course of this method) when we are creating a new
* Collaboration.
* */
createCoAuthorEdges(biboDocumentURLToVO,
biboDocumentURLToCoAuthors,
edges,
edgeUniqueIdentifierToVO);
return new CoAuthorshipData(egoNode, nodes, edges);
}
private void removeLowQualityNodesAndEdges(
Set<Collaborator> nodes,
Map<String, Activity> biboDocumentURLToVO,
Map<String, Set<Collaborator>> biboDocumentURLToCoAuthors,
Set<Collaboration> edges) {
Set<Collaborator> nodesToBeRemoved = new HashSet<Collaborator>();
for (Map.Entry<String, Set<Collaborator>> currentBiboDocumentEntry
: biboDocumentURLToCoAuthors.entrySet()) {
if (currentBiboDocumentEntry.getValue().size() > MAX_AUTHORS_PER_PAPER_ALLOWED) {
Activity currentBiboDocument = biboDocumentURLToVO
.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 void createCoAuthorEdges(
Map<String, Activity> biboDocumentURLToVO,
Map<String, Set<Collaborator>> biboDocumentURLToCoAuthors, Set<Collaboration> edges,
Map<String, Collaboration> edgeUniqueIdentifierToVO) {
for (Map.Entry<String, Set<Collaborator>> currentBiboDocumentEntry
: biboDocumentURLToCoAuthors.entrySet()) {
/*
* If there was only one co-author (other than ego) then we dont have to create any
* edges. so the below condition will take care of that.
*
* We are restricting edges between co-author if a particular document has more than
* 100 co-authors. Our conjecture is that such edges do not provide any good insight
* & causes unnecessary computations causing the server to time-out.
* */
if (currentBiboDocumentEntry.getValue().size() > 1
&& currentBiboDocumentEntry.getValue().size()
<= MAX_AUTHORS_PER_PAPER_ALLOWED) {
Set<Collaboration> newlyAddedEdges = new HashSet<Collaboration>();
/*
* In order to leverage the nested "for loop" for making edges between all the
* co-authors we need to create a list out of the set first.
* */
List<Collaborator> coAuthorNodes =
new ArrayList<Collaborator>(currentBiboDocumentEntry.getValue());
Collections.sort(coAuthorNodes, new CollaboratorComparator());
int numOfCoAuthors = coAuthorNodes.size();
for (int ii = 0; ii < numOfCoAuthors - 1; ii++) {
for (int jj = ii + 1; jj < numOfCoAuthors; jj++) {
Collaborator coAuthor1 = coAuthorNodes.get(ii);
Collaborator coAuthor2 = coAuthorNodes.get(jj);
Collaboration coAuthor1_2Edge = getExistingEdge(coAuthor1,
coAuthor2,
edgeUniqueIdentifierToVO);
Activity currentBiboDocument = biboDocumentURLToVO
.get(currentBiboDocumentEntry
.getKey());
if (coAuthor1_2Edge != null) {
coAuthor1_2Edge.addActivity(currentBiboDocument);
} else {
coAuthor1_2Edge = new Collaboration(coAuthor1,
coAuthor2,
currentBiboDocument,
edgeIDGenerator);
newlyAddedEdges.add(coAuthor1_2Edge);
edgeUniqueIdentifierToVO.put(
getEdgeUniqueIdentifier(coAuthor1.getCollaboratorID(),
coAuthor2.getCollaboratorID()),
coAuthor1_2Edge);
}
}
}
edges.addAll(newlyAddedEdges);
}
}
}
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 Activity createDocumentVO(QuerySolution solution, String documentURL) {
Activity biboDocument = new Activity(documentURL);
RDFNode publicationDateNode = solution.get(QueryFieldLabels.DOCUMENT_PUBLICATION_DATE);
if (publicationDateNode != null) {
biboDocument.setActivityDate(publicationDateNode.toString());
}
return biboDocument;
}
private ResultSet executeQuery(String queryText,
Dataset dataset) {
QueryExecution queryExecution = null;
Query query = QueryFactory.create(queryText, SYNTAX);
queryExecution = QueryExecutionFactory.create(query, dataset);
return queryExecution.execSelect();
}
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"
+ "?document core:relatedBy ?coAuthorshipNode . \n"
+ "?coAuthorshipNode rdf:type core:Authorship . \n"
+ "?coAuthorshipNode core:relates ?coAuthorPerson . \n"
+ "?coAuthorPerson rdf:type foaf:Person . \n"
+ "?coAuthorPerson rdfs:label ?coAuthorPersonLabel . \n"
+ "OPTIONAL { ?document core:dateTimeValue ?dateTimeValue . \n"
+ " ?dateTimeValue core:dateTime ?publicationDate } .\n"
+ "} \n"
+ "ORDER BY ?document ?coAuthorPerson\n";
log.debug("COAUTHORSHIP QUERY - " + sparqlQuery);
return sparqlQuery;
}
public CollaborationData getQueryResult()
throws MalformedQueryParametersException {
if (StringUtils.isNotBlank(this.egoURI)) {
/*
* To test for the validity of the URI submitted.
* */
IRIFactory iRIFactory = IRIFactory.jenaImplementation();
IRI iri = iRIFactory.create(this.egoURI);
if (iri.hasViolation(false)) {
String errorMsg = ((Violation) iri.violations(false).next()).getShortMessage();
log.error("Ego Co-Authorship Vis Query " + errorMsg);
throw new MalformedQueryParametersException(
"URI provided for an individual is malformed.");
}
} else {
throw new MalformedQueryParametersException("URI parameter is either null or empty.");
}
ResultSet resultSet = executeQuery(generateEgoCoAuthorshipSparqlQuery(this.egoURI),
this.dataset);
return createQueryResult(resultSet);
}
}

View file

@ -38,9 +38,9 @@ public class CoPIGrantCountConstructQueryRunner implements ModelConstructor {
.getLog(CoPIGrantCountConstructQueryRunner.class.getName());
private static final String SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING =
"?Role core:roleContributesTo ?Grant . "
// + "?Grant rdfs:label ?GrantLabel . "
+ "?Grant core:contributingRole ?RelatedRole . ";
"?Role core:relatedBy ?Grant . "
+ "?Grant rdf:type core:Grant ."
+ "?Grant core:relates ?RelatedRole . ";
public CoPIGrantCountConstructQueryRunner(String egoURI, Dataset dataset,
Log log) {
@ -59,23 +59,31 @@ public class CoPIGrantCountConstructQueryRunner implements ModelConstructor {
}
private String generateConstructQueryForInvestigatorRoleOfProperty(
String queryURI, String preboundProperty) {
String queryURI, String preboundProperty, String preboundRoleType) {
String sparqlQuery = "CONSTRUCT { " + "<" + queryURI + ">"
+ preboundProperty + " ?Role . "
+ "?Role rdf:type " + preboundRoleType + " . "
+ SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
+ "?RelatedRole core:investigatorRoleOf ?coInvestigator ."
+ "?RelatedRole rdf:type core:InvestigatorRole ."
+ "?RelatedRole <http://purl.obolibrary.org/obo/RO_0000052> ?coInvestigator ."
+ "?coInvestigator rdf:type foaf:Person ."
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . " + "}"
+ "WHERE { " + "<" + queryURI + ">" + preboundProperty
+ " ?Role . " + SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
+ "?RelatedRole core:investigatorRoleOf ?coInvestigator ."
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . " + "}";
+ "WHERE { " + "<" + queryURI + ">" + preboundProperty + " ?Role . "
+ "?Role rdf:type " + preboundRoleType + " . "
+ SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
+ "?RelatedRole rdf:type core:InvestigatorRole ."
+ "?RelatedRole vitro:mostSpecificType ?subclass ."
+ "?RelatedRole <http://purl.obolibrary.org/obo/RO_0000052> ?coInvestigator ."
+ "?coInvestigator rdf:type foaf:Person ."
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . "
+ "FILTER (?subclass != core:PrincipalInvestigatorRole && ?subclass != core:CoPrincipalInvestigatorRole)}";
return sparqlQuery;
}
private String generateConstructQueryForPrincipalInvestigatorRoleOfProperty(
String queryURI, String preboundProperty) {
String queryURI, String preboundProperty, String preboundRoleType) {
String sparqlQuery = "CONSTRUCT { "
+ "<"
@ -83,8 +91,11 @@ public class CoPIGrantCountConstructQueryRunner implements ModelConstructor {
+ ">"
+ preboundProperty
+ " ?Role . "
+ "?Role rdf:type " + preboundRoleType + " . "
+ SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
+ "?RelatedRole core:principalInvestigatorRoleOf ?coInvestigator ."
+ "?RelatedRole rdf:type core:PrincipalInvestigatorRole ."
+ "?RelatedRole <http://purl.obolibrary.org/obo/RO_0000052> ?coInvestigator ."
+ "?coInvestigator rdf:type foaf:Person ."
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . "
+ "}"
+ "WHERE { "
@ -93,15 +104,18 @@ public class CoPIGrantCountConstructQueryRunner implements ModelConstructor {
+ ">"
+ preboundProperty
+ " ?Role . "
+ "?Role rdf:type " + preboundRoleType + " . "
+ SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
+ "?RelatedRole core:principalInvestigatorRoleOf ?coInvestigator ."
+ "?RelatedRole rdf:type core:PrincipalInvestigatorRole ."
+ "?RelatedRole <http://purl.obolibrary.org/obo/RO_0000052> ?coInvestigator ."
+ "?coInvestigator rdf:type foaf:Person ."
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . " + "}";
return sparqlQuery;
}
private String generateConstructQueryForCoPrincipalInvestigatorRoleOfProperty(
String queryURI, String preboundProperty) {
String queryURI, String preboundProperty, String preboundRoleType) {
String sparqlQuery = "CONSTRUCT { "
+ "<"
@ -109,8 +123,11 @@ public class CoPIGrantCountConstructQueryRunner implements ModelConstructor {
+ ">"
+ preboundProperty
+ " ?Role . "
+ "?Role rdf:type " + preboundRoleType + " . "
+ SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
+ "?RelatedRole core:co-PrincipalInvestigatorRoleOf ?coInvestigator ."
+ "?RelatedRole rdf:type core:CoPrincipalInvestigatorRole ."
+ "?RelatedRole <http://purl.obolibrary.org/obo/RO_0000052> ?coInvestigator ."
+ "?coInvestigator rdf:type foaf:Person ."
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . "
+ "}"
+ "WHERE { "
@ -119,18 +136,22 @@ public class CoPIGrantCountConstructQueryRunner implements ModelConstructor {
+ ">"
+ preboundProperty
+ " ?Role . "
+ "?Role rdf:type " + preboundRoleType + " . "
+ SPARQL_QUERY_COMMON_CONSTRUCT_AND_WHERE_STRING
+ "?RelatedRole core:co-PrincipalInvestigatorRoleOf ?coInvestigator ."
+ "?RelatedRole rdf:type core:CoPrincipalInvestigatorRole ."
+ "?RelatedRole <http://purl.obolibrary.org/obo/RO_0000052> ?coInvestigator ."
+ "?coInvestigator rdf:type foaf:Person ."
+ "?coInvestigator rdfs:label ?coInvestigatorLabel . " + "}";
return sparqlQuery;
}
private String generateConstructQueryForDateTimeValueofRole(
String queryURI, String preboundProperty) {
String queryURI, String preboundProperty, String preboundRoleType) {
String sparqlQuery = "CONSTRUCT { " + "<" + queryURI + ">"
+ preboundProperty + " ?Role . "
+ "?Role rdf:type " + preboundRoleType + " . "
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
+ "?dateTimeIntervalValue core:start ?startDate . "
+ "?startDate core:dateTime ?startDateTimeValue . "
@ -139,6 +160,7 @@ public class CoPIGrantCountConstructQueryRunner implements ModelConstructor {
+ "}"
+ "WHERE { " + "{" + "<" + queryURI + ">" + preboundProperty
+ " ?Role . "
+ "?Role rdf:type " + preboundRoleType + " . "
+ "?Role core:dateTimeInterval ?dateTimeIntervalValue . "
+ "?dateTimeIntervalValue core:start ?startDate . "
+ "?startDate core:dateTime ?startDateTimeValue . "
@ -153,14 +175,16 @@ public class CoPIGrantCountConstructQueryRunner implements ModelConstructor {
}
private String generateConstructQueryForDateTimeValueofGrant(
String queryURI, String preboundProperty) {
String queryURI, String preboundProperty, String preboundRoleType) {
String sparqlQuery = "CONSTRUCT { " + "<"
+ queryURI
+ ">"
+ preboundProperty
+ " ?Role . "
+ "?Role core:roleContributesTo ?Grant ."
+ "?Role rdf:type " + preboundRoleType + " . "
+ "?Role core:relatedBy ?Grant ."
+ "?Grant rdf:type core:Grant ."
+ "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
+ "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
+ "?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
@ -174,7 +198,9 @@ public class CoPIGrantCountConstructQueryRunner implements ModelConstructor {
+ ">"
+ preboundProperty
+ " ?Role . "
+ "?Role core:roleContributesTo ?Grant ."
+ "?Role rdf:type " + preboundRoleType + " . "
+ "?Role core:relatedBy ?Grant ."
+ "?Grant rdf:type core:Grant ."
+ "?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
+ "?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
+ "?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
@ -268,45 +294,45 @@ public class CoPIGrantCountConstructQueryRunner implements ModelConstructor {
.add(generateConstructQueryForInvestigatorLabel(this.egoURI));
constructQueries
.add(generateConstructQueryForInvestigatorRoleOfProperty(
this.egoURI, "core:hasInvestigatorRole"));
this.egoURI, "<http://purl.obolibrary.org/obo/RO_0000053>", "core:InvestigatorRole"));
constructQueries
.add(generateConstructQueryForCoPrincipalInvestigatorRoleOfProperty(
this.egoURI, "core:hasInvestigatorRole"));
this.egoURI, "<http://purl.obolibrary.org/obo/RO_0000053>", "core:InvestigatorRole"));
constructQueries
.add(generateConstructQueryForPrincipalInvestigatorRoleOfProperty(
this.egoURI, "core:hasInvestigatorRole"));
this.egoURI, "<http://purl.obolibrary.org/obo/RO_0000053>", "core:InvestigatorRole"));
constructQueries.add(generateConstructQueryForDateTimeValueofRole(
this.egoURI, "core:hasInvestigatorRole"));
this.egoURI, "<http://purl.obolibrary.org/obo/RO_0000053>", "core:InvestigatorRole"));
constructQueries.add(generateConstructQueryForDateTimeValueofGrant(
this.egoURI, "core:hasInvestigatorRole"));
this.egoURI, "<http://purl.obolibrary.org/obo/RO_0000053>", "core:InvestigatorRole"));
constructQueries
.add(generateConstructQueryForInvestigatorRoleOfProperty(
this.egoURI, "core:hasPrincipalInvestigatorRole"));
this.egoURI, "<http://purl.obolibrary.org/obo/RO_0000053>", "core:PrincipalInvestigatorRole"));
constructQueries
.add(generateConstructQueryForCoPrincipalInvestigatorRoleOfProperty(
this.egoURI, "core:hasPrincipalInvestigatorRole"));
this.egoURI, "<http://purl.obolibrary.org/obo/RO_0000053>", "core:PrincipalInvestigatorRole"));
constructQueries
.add(generateConstructQueryForPrincipalInvestigatorRoleOfProperty(
this.egoURI, "core:hasPrincipalInvestigatorRole"));
this.egoURI, "<http://purl.obolibrary.org/obo/RO_0000053>", "core:PrincipalInvestigatorRole"));
constructQueries.add(generateConstructQueryForDateTimeValueofRole(
this.egoURI, "core:hasPrincipalInvestigatorRole"));
this.egoURI, "<http://purl.obolibrary.org/obo/RO_0000053>", "core:PrincipalInvestigatorRole"));
constructQueries.add(generateConstructQueryForDateTimeValueofGrant(
this.egoURI, "core:hasPrincipalInvestigatorRole"));
this.egoURI, "<http://purl.obolibrary.org/obo/RO_0000053>", "core:PrincipalInvestigatorRole"));
constructQueries
.add(generateConstructQueryForInvestigatorRoleOfProperty(
this.egoURI, "core:hasCo-PrincipalInvestigatorRole"));
this.egoURI, "<http://purl.obolibrary.org/obo/RO_0000053>", "core:CoPrincipalInvestigatorRole"));
constructQueries
.add(generateConstructQueryForCoPrincipalInvestigatorRoleOfProperty(
this.egoURI, "core:hasCo-PrincipalInvestigatorRole"));
this.egoURI, "<http://purl.obolibrary.org/obo/RO_0000053>", "core:CoPrincipalInvestigatorRole"));
constructQueries
.add(generateConstructQueryForPrincipalInvestigatorRoleOfProperty(
this.egoURI, "core:hasCo-PrincipalInvestigatorRole"));
this.egoURI, "<http://purl.obolibrary.org/obo/RO_0000053>", "core:CoPrincipalInvestigatorRole"));
constructQueries.add(generateConstructQueryForDateTimeValueofRole(
this.egoURI, "core:hasCo-PrincipalInvestigatorRole"));
this.egoURI, "<http://purl.obolibrary.org/obo/RO_0000053>", "core:CoPrincipalInvestigatorRole"));
constructQueries.add(generateConstructQueryForDateTimeValueofGrant(
this.egoURI, "core:hasCo-PrincipalInvestigatorRole"));
this.egoURI, "<http://purl.obolibrary.org/obo/RO_0000053>", "core:CoPrincipalInvestigatorRole"));
}
}

View file

@ -113,13 +113,21 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CollaborationData>
+ "<" + queryURI + "> rdfs:label ?PILabel . "
+ "{ "
+ "<" + queryURI + "> core:hasCo-PrincipalInvestigatorRole ?Role . "
+ "<" + queryURI + "> <http://purl.obolibrary.org/obo/RO_0000053> ?Role . "
+ "?Role core:roleContributesTo ?Grant . "
+ "?Role rdf:type core:CoPrincipalInvestigatorRole . "
+ "?Grant core:contributingRole ?RelatedRole . "
+ "?Role core:relatedBy ?Grant . "
+ "?RelatedRole core:principalInvestigatorRoleOf ?CoPI . "
+ "?Grant rdf:type core:Grant . "
+ "?Grant core:relates ?RelatedRole . "
+ "?RelatedRole rdf:type core:PrincipalInvestigatorRole . "
+ "?RelatedRole <http://purl.obolibrary.org/obo/RO_0000052> ?CoPI . "
+ "?CoPI rdf:type foaf:Person . "
+ "?CoPI rdfs:label ?CoPILabel . "
@ -133,13 +141,21 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CollaborationData>
+ "{ "
+ "<" + queryURI + "> core:hasCo-PrincipalInvestigatorRole ?Role . "
+ "<" + queryURI + "> <http://purl.obolibrary.org/obo/RO_0000053> ?Role . "
+ "?Role core:roleContributesTo ?Grant . "
+ "?Role rdf:type core:CoPrincipalInvestigatorRole . "
+ "?Grant core:contributingRole ?RelatedRole . "
+ "?Role core:relatedBy ?Grant . "
+ "?RelatedRole core:investigatorRoleOf ?CoPI . "
+ "?Grant rdf:type core:Grant . "
+ "?Grant core:relates ?RelatedRole . "
+ "?RelatedRole rdf:type core:InvestigatorRole . "
+ "?RelatedRole <http://purl.obolibrary.org/obo/RO_0000052> ?CoPI . "
+ "?CoPI rdf:type foaf:Person . "
+ "?CoPI rdfs:label ?CoPILabel . "
@ -154,13 +170,21 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CollaborationData>
+ "{ "
+ "<" + queryURI + "> core:hasCo-PrincipalInvestigatorRole ?Role . "
+ "<" + queryURI + "> <http://purl.obolibrary.org/obo/RO_0000053> ?Role . "
+ "?Role core:roleContributesTo ?Grant . "
+ "?Role rdf:type core:CoPrincipalInvestigatorRole . "
+ "?Grant core:contributingRole ?RelatedRole . "
+ "?Role core:relatedBy ?Grant . "
+ "?RelatedRole core:co-PrincipalInvestigatorRoleOf ?CoPI . "
+ "?Grant rdf:type core:Grant . "
+ "?Grant core:relates ?RelatedRole . "
+ "?RelatedRole rdf:type core:CoPrincipalInvestigatorRole . "
+ "?RelatedRole <http://purl.obolibrary.org/obo/RO_0000052> ?CoPI . "
+ "?CoPI rdf:type foaf:Person . "
+ "?CoPI rdfs:label ?CoPILabel . "
@ -176,13 +200,21 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CollaborationData>
+ "{ "
+ "<" + queryURI + "> core:hasPrincipalInvestigatorRole ?Role . "
+ "<" + queryURI + "> <http://purl.obolibrary.org/obo/RO_0000053> ?Role . "
+ "?Role core:roleContributesTo ?Grant . "
+ "?Role rdf:type core:PrincipalInvestigatorRole . "
+ "?Grant core:contributingRole ?RelatedRole . "
+ "?Role core:relatedBy ?Grant . "
+ "?RelatedRole core:principalInvestigatorRoleOf ?CoPI . "
+ "?Grant rdf:type core:Grant . "
+ "?Grant core:relates ?RelatedRole . "
+ "?RelatedRole rdf:type core:PrincipalInvestigatorRole . "
+ "?RelatedRole <http://purl.obolibrary.org/obo/RO_0000052> ?CoPI . "
+ "?CoPI rdf:type foaf:Person . "
+ "?CoPI rdfs:label ?CoPILabel . "
@ -197,13 +229,21 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CollaborationData>
+ "{ "
+ "<" + queryURI + "> core:hasPrincipalInvestigatorRole ?Role . "
+ "<" + queryURI + "> <http://purl.obolibrary.org/obo/RO_0000053> ?Role . "
+ "?Role core:roleContributesTo ?Grant . "
+ "?Role rdf:type core:PrincipalInvestigatorRole . "
+ "?Grant core:contributingRole ?RelatedRole . "
+ "?Role core:relatedBy ?Grant . "
+ "?RelatedRole core:investigatorRoleOf ?CoPI . "
+ "?Grant rdf:type core:Grant . "
+ "?Grant core:relates ?RelatedRole . "
+ "?RelatedRole rdf:type core:InvestigatorRole . "
+ "?RelatedRole <http://purl.obolibrary.org/obo/RO_0000052> ?CoPI . "
+ "?CoPI rdf:type foaf:Person . "
+ "?CoPI rdfs:label ?CoPILabel . "
@ -218,13 +258,21 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CollaborationData>
+ "{ "
+ "<" + queryURI + "> core:hasPrincipalInvestigatorRole ?Role . "
+ "<" + queryURI + "> <http://purl.obolibrary.org/obo/RO_0000053> ?Role . "
+ "?Role core:roleContributesTo ?Grant . "
+ "?Role rdf:type core:PrincipalInvestigatorRole . "
+ "?Grant core:contributingRole ?RelatedRole . "
+ "?Role core:relatedBy ?Grant . "
+ "?RelatedRole core:co-PrincipalInvestigatorRoleOf ?CoPI . "
+ "?Grant rdf:type core:Grant . "
+ "?Grant core:relates ?RelatedRole . "
+ "?RelatedRole rdf:type core:CoPrincipalInvestigatorRole . "
+ "?RelatedRole <http://purl.obolibrary.org/obo/RO_0000052> ?CoPI . "
+ "?CoPI rdf:type foaf:Person . "
+ "?CoPI rdfs:label ?CoPILabel . "
@ -239,13 +287,21 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CollaborationData>
+ "{ "
+ "<" + queryURI + "> core:hasInvestigatorRole ?Role . "
+ "<" + queryURI + "> <http://purl.obolibrary.org/obo/RO_0000053> ?Role . "
+ "?Role core:roleContributesTo ?Grant . "
+ "?Role rdf:type core:InvestigatorRole . "
+ "?Grant core:contributingRole ?RelatedRole . "
+ "?Role core:relatedBy ?Grant . "
+ "?RelatedRole core:investigatorRoleOf ?CoPI . "
+ "?Grant rdf:type core:Grant . "
+ "?Grant core:relates ?RelatedRole . "
+ "?RelatedRole rdf:type core:InvestigatorRole . "
+ "?RelatedRole <http://purl.obolibrary.org/obo/RO_0000052> ?CoPI . "
+ "?CoPI rdf:type foaf:Person . "
+ "?CoPI rdfs:label ?CoPILabel . "
@ -260,13 +316,21 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CollaborationData>
+ "{ "
+ "<" + queryURI + "> core:hasInvestigatorRole ?Role . "
+ "<" + queryURI + "> <http://purl.obolibrary.org/obo/RO_0000053> ?Role . "
+ "?Role core:roleContributesTo ?Grant . "
+ "?Role rdf:type core:InvestigatorRole . "
+ "?Grant core:contributingRole ?RelatedRole . "
+ "?Role core:relatedBy ?Grant . "
+ "?RelatedRole core:co-PrincipalInvestigatorRoleOf ?CoPI . "
+ "?Grant rdf:type core:Grant . "
+ "?Grant core:relates ?RelatedRole . "
+ "?RelatedRole rdf:type core:CoPrincipalInvestigatorRole . "
+ "?RelatedRole <http://purl.obolibrary.org/obo/RO_0000052> ?CoPI . "
+ "?CoPI rdf:type foaf:Person . "
+ "?CoPI rdfs:label ?CoPILabel . "
@ -281,13 +345,21 @@ public class CoPIGrantCountQueryRunner implements QueryRunner<CollaborationData>
+ "{ "
+ "<" + queryURI + "> core:hasInvestigatorRole ?Role . "
+ "<" + queryURI + "> <http://purl.obolibrary.org/obo/RO_0000053> ?Role . "
+ "?Role core:roleContributesTo ?Grant . "
+ "?Role rdf:type core:InvestigatorRole . "
+ "?Grant core:contributingRole ?RelatedRole . "
+ "?Role core:relatedBy ?Grant . "
+ "?RelatedRole core:principalInvestigatorRoleOf ?CoPI . "
+ "?Grant rdf:type core:Grant . "
+ "?Grant core:relates ?RelatedRole . "
+ "?RelatedRole rdf:type core:PrincipalInvestigatorRole . "
+ "?RelatedRole <http://purl.obolibrary.org/obo/RO_0000052> ?CoPI . "
+ "?CoPI rdf:type foaf:Person . "
+ "?CoPI rdfs:label ?CoPILabel . "

View file

@ -53,8 +53,9 @@ public class OrganizationAssociatedPeopleModelWithTypesConstructor implements Mo
+ " <" + organizationURI + "> rdf:type foaf:Organization . "
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
+ " OPTIONAL { "
+ " <" + organizationURI + "> core:organizationForPosition ?Position . "
+ " ?Position core:positionForPerson ?Person . "
+ " <" + organizationURI + "> core:relatedBy ?Position . "
+ " ?Position rdf:type core:Position . "
+ " ?Position core:relates ?Person . "
+ " ?Person rdfs:label ?personLabel. "
+ " ?Person rdf:type ?personType . "
+ " ?personType rdfs:label ?personTypeLabel . "

View file

@ -50,7 +50,8 @@ public class OrganizationModelWithTypesConstructor implements ModelConstructor {
+ " CONSTRUCT { "
+ " ?organization rdf:type foaf:Organization . "
+ " ?organization rdfs:label ?organizationLabel . "
+ " ?organization core:hasSubOrganization ?subOrganization . "
+ " ?organization <http://purl.obolibrary.org/obo/BFO_0000051> ?subOrganization . "
+ " ?subOrganization rdf:type foaf:Organization . "
+ " ?subOrganization rdfs:label ?subOrganizationLabel . "
+ " ?subOrganization rdf:type ?subOrganizationType . "
+ " ?subOrganizationType rdfs:label ?subOrganizationTypeLabel . "
@ -60,7 +61,8 @@ public class OrganizationModelWithTypesConstructor implements ModelConstructor {
+ " ?organization rdfs:label ?organizationLabel . "
+ " "
+ " OPTIONAL { "
+ " ?organization core:hasSubOrganization ?subOrganization . "
+ " ?organization <http://purl.obolibrary.org/obo/BFO_0000051> ?subOrganization . "
+ " ?subOrganization rdf:type foaf:Organization . "
+ " ?subOrganization rdfs:label ?subOrganizationLabel . "
+ " ?subOrganization rdf:type ?subOrganizationType . "
+ " ?subOrganizationType rdfs:label ?subOrganizationTypeLabel . "

View file

@ -1,189 +1,204 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.query.Dataset;
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.Syntax;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.ModelConstructor;
public class OrganizationToGrantsForSubOrganizationsModelConstructor implements ModelConstructor {
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private Dataset dataset;
public static final String MODEL_TYPE = "ORGANIZATION_TO_GRANTS_FOR_SUBORGANIZATIONS";
public static final String MODEL_TYPE_HUMAN_READABLE = "Grants for specific organization via all descendants";
private String organizationURI;
private Log log = LogFactory.getLog(OrganizationToGrantsForSubOrganizationsModelConstructor.class.getName());
private long before, after;
public OrganizationToGrantsForSubOrganizationsModelConstructor(String organizationURI, Dataset dataset) {
this.organizationURI = organizationURI;
this.dataset = dataset;
}
private Set<String> constructOrganizationGrantsQueryTemplate(String constructProperty, String roleTypeProperty) {
Set<String> differentPerspectiveQueries = new HashSet<String>();
String justGrantsQuery = ""
+ " CONSTRUCT { "
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
+ " <" + organizationURI + "> vivosocnet:lastCachedAt ?now . "
+ " <" + organizationURI + "> vivosocnet:" + constructProperty + " ?Grant . "
+ " "
+ " ?Grant rdf:type core:Grant . "
+ " ?Grant rdfs:label ?grantLabel . "
+ " "
+ " } "
+ " WHERE { "
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
+ " <" + organizationURI + "> core:hasSubOrganization* ?subOrganization . "
+ " ?subOrganization core:organizationForPosition ?Position . "
+ " ?Position core:positionForPerson ?Person . "
+ " ?Person core:" + roleTypeProperty + " ?Role . "
+ " ?Role core:roleContributesTo ?Grant . "
+ " ?Grant rdfs:label ?grantLabel . "
+ " "
+ " LET(?now := afn:now()) "
+ " } ";
String justDateTimeOnGrantsQuery = ""
+ " CONSTRUCT { "
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
+ " <" + organizationURI + "> vivosocnet:lastCachedAt ?now . "
+ " "
+ " ?Grant vivosocnet:startDateTimeOnGrant ?startDateTimeValueForGrant . "
// + " ?Grant vivosocnet:endDateTimeOnGrant ?endDateTimeValueForGrant . "
+ " "
+ " } "
+ " WHERE { "
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
+ " <" + organizationURI + "> core:hasSubOrganization* ?subOrganization . "
+ " ?subOrganization core:organizationForPosition ?Position . "
+ " ?Position core:positionForPerson ?Person . "
+ " ?Person core:" + roleTypeProperty + " ?Role . "
+ " ?Role core:roleContributesTo ?Grant . "
+ " "
+ " ?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
// + " OPTIONAL { "
+ " ?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
+ " ?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
// + " } "
// + " OPTIONAL { "
// + " ?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
// + " ?endDateForGrant core:dateTime ?endDateTimeValueForGrant "
// + " } "
+ " "
+ " LET(?now := afn:now()) "
+ " } ";
String justDateTimeOnRolesQuery = ""
+ " CONSTRUCT { "
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
+ " <" + organizationURI + "> vivosocnet:lastCachedAt ?now . "
+ " "
+ " ?Grant vivosocnet:startDateTimeOnRole ?startDateTimeValue . "
// + " ?Grant vivosocnet:endDateTimeOnRole ?endDateTimeValue . "
+ " } "
+ " WHERE { "
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
+ " <" + organizationURI + "> core:hasSubOrganization* ?subOrganization . "
+ " ?subOrganization core:organizationForPosition ?Position . "
+ " ?Position core:positionForPerson ?Person . "
+ " ?Person core:" + roleTypeProperty + " ?Role . "
+ " ?Role core:roleContributesTo ?Grant . "
+ " "
+ " ?Role core:dateTimeInterval ?dateTimeIntervalValue . "
// + " OPTIONAL { "
+ " ?dateTimeIntervalValue core:start ?startDate . "
+ " ?startDate core:dateTime ?startDateTimeValue . "
// + " } "
// + " "
// + " OPTIONAL { "
// + " ?dateTimeIntervalValue core:end ?endDate . "
// + " ?endDate core:dateTime ?endDateTimeValue . "
// + " } "
+ " "
+ " LET(?now := afn:now()) "
+ " } ";
differentPerspectiveQueries.add(justGrantsQuery);
differentPerspectiveQueries.add(justDateTimeOnGrantsQuery);
differentPerspectiveQueries.add(justDateTimeOnRolesQuery);
return differentPerspectiveQueries;
}
private Set<String> constructOrganizationToGrantsQuery() {
Set<String> differentInvestigatorTypeQueries = new HashSet<String>();
Set<String> investigatorRoleQuery = constructOrganizationGrantsQueryTemplate("hasInvestigatorWithGrant", "hasInvestigatorRole");
Set<String> piRoleQuery = constructOrganizationGrantsQueryTemplate("hasPIWithGrant", "hasPrincipalInvestigatorRole");
Set<String> coPIRoleQuery = constructOrganizationGrantsQueryTemplate("hascoPIWithGrant", "hasCo-PrincipalInvestigatorRole");
differentInvestigatorTypeQueries.addAll(investigatorRoleQuery);
differentInvestigatorTypeQueries.addAll(piRoleQuery);
differentInvestigatorTypeQueries.addAll(coPIRoleQuery);
return differentInvestigatorTypeQueries;
}
private Model executeQuery(Set<String> constructQueries) {
Model constructedModel = ModelFactory.createDefaultModel();
before = System.currentTimeMillis();
log.debug("CONSTRUCT query string : " + constructQueries);
for (String currentQuery : constructQueries) {
Query query = null;
try {
query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery() + currentQuery, SYNTAX);
} catch (Throwable th) {
log.error("Could not create CONSTRUCT SPARQL query for query "
+ "string. " + th.getMessage());
log.error(currentQuery);
}
QueryExecution qe = QueryExecutionFactory.create(query, dataset);
try {
qe.execConstruct(constructedModel);
} finally {
qe.close();
}
}
after = System.currentTimeMillis();
log.debug("Time taken to execute the CONSTRUCT queries is in milliseconds: "
+ (after - before));
return constructedModel;
}
public Model getConstructedModel() throws MalformedQueryParametersException {
return executeQuery(constructOrganizationToGrantsQuery());
}
}
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.query.Dataset;
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.Syntax;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.ModelConstructor;
public class OrganizationToGrantsForSubOrganizationsModelConstructor implements ModelConstructor {
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private Dataset dataset;
public static final String MODEL_TYPE = "ORGANIZATION_TO_GRANTS_FOR_SUBORGANIZATIONS";
public static final String MODEL_TYPE_HUMAN_READABLE = "Grants for specific organization via all descendants";
private String organizationURI;
private Log log = LogFactory.getLog(OrganizationToGrantsForSubOrganizationsModelConstructor.class.getName());
private long before, after;
public OrganizationToGrantsForSubOrganizationsModelConstructor(String organizationURI, Dataset dataset) {
this.organizationURI = organizationURI;
this.dataset = dataset;
}
private Set<String> constructOrganizationGrantsQueryTemplate(String constructProperty, String roleType) {
Set<String> differentPerspectiveQueries = new HashSet<String>();
String justGrantsQuery = ""
+ " CONSTRUCT { "
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
+ " <" + organizationURI + "> vivosocnet:lastCachedAt ?now . "
+ " <" + organizationURI + "> vivosocnet:" + constructProperty + " ?Grant . "
+ " "
+ " ?Grant rdf:type core:Grant . "
+ " ?Grant rdfs:label ?grantLabel . "
+ " "
+ " } "
+ " WHERE { "
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
+ " <" + organizationURI + "> <http://purl.obolibrary.org/obo/BFO_0000051>* ?subOrganization . "
+ " ?subOrganization rdf:type foaf:Organization . "
+ " ?subOrganization core:relatedBy ?Position . "
+ " ?Position rdf:type core:Position . "
+ " ?Position core:relates ?Person . "
+ " ?Person rdf:type foaf:Person . "
+ " ?Person <http://purl.obolibrary.org/obo/RO_0000053> ?Role . "
+ " ?Role rdf:type core:" + roleType + " . "
+ " ?Role core:relatedBy ?Grant . "
+ " ?Grant rdf:type core:Grant . "
+ " ?Grant rdfs:label ?grantLabel . "
+ " "
+ " LET(?now := afn:now()) "
+ " } ";
String justDateTimeOnGrantsQuery = ""
+ " CONSTRUCT { "
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
+ " <" + organizationURI + "> vivosocnet:lastCachedAt ?now . "
+ " "
+ " ?Grant vivosocnet:startDateTimeOnGrant ?startDateTimeValueForGrant . "
// + " ?Grant vivosocnet:endDateTimeOnGrant ?endDateTimeValueForGrant . "
+ " "
+ " } "
+ " WHERE { "
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
+ " <" + organizationURI + "> <http://purl.obolibrary.org/obo/BFO_0000051>* ?subOrganization . "
+ " ?subOrganization rdf:type foaf:Organization . "
+ " ?subOrganization core:relatedBy ?Position . "
+ " ?Position rdf:type core:Position . "
+ " ?Position core:relates ?Person . "
+ " ?Person rdf:type foaf:Person . "
+ " ?Person <http://purl.obolibrary.org/obo/RO_0000053> ?Role . "
+ " ?Role rdf:type core:" + roleType + " . "
+ " ?Role core:relatedBy ?Grant . "
+ " ?Grant rdf:type core:Grant . "
+ " "
+ " ?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
// + " OPTIONAL { "
+ " ?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
+ " ?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
// + " } "
// + " OPTIONAL { "
// + " ?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
// + " ?endDateForGrant core:dateTime ?endDateTimeValueForGrant "
// + " } "
+ " "
+ " LET(?now := afn:now()) "
+ " } ";
String justDateTimeOnRolesQuery = ""
+ " CONSTRUCT { "
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
+ " <" + organizationURI + "> vivosocnet:lastCachedAt ?now . "
+ " "
+ " ?Grant vivosocnet:startDateTimeOnRole ?startDateTimeValue . "
// + " ?Grant vivosocnet:endDateTimeOnRole ?endDateTimeValue . "
+ " } "
+ " WHERE { "
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
+ " <" + organizationURI + "> <http://purl.obolibrary.org/obo/BFO_0000051>* ?subOrganization . "
+ " ?subOrganization rdf:type foaf:Organization . "
+ " ?subOrganization core:relatedBy ?Position . "
+ " ?Position rdf:type core:Position . "
+ " ?Position core:relates ?Person . "
+ " ?Person rdf:type foaf:Person . "
+ " ?Person <http://purl.obolibrary.org/obo/RO_0000053> ?Role . "
+ " ?Role rdf:type core:" + roleType + " . "
+ " ?Role core:relatedBy ?Grant . "
+ " ?Grant rdf:type core:Grant . "
+ " "
+ " ?Role core:dateTimeInterval ?dateTimeIntervalValue . "
// + " OPTIONAL { "
+ " ?dateTimeIntervalValue core:start ?startDate . "
+ " ?startDate core:dateTime ?startDateTimeValue . "
// + " } "
// + " "
// + " OPTIONAL { "
// + " ?dateTimeIntervalValue core:end ?endDate . "
// + " ?endDate core:dateTime ?endDateTimeValue . "
// + " } "
+ " "
+ " LET(?now := afn:now()) "
+ " } ";
differentPerspectiveQueries.add(justGrantsQuery);
differentPerspectiveQueries.add(justDateTimeOnGrantsQuery);
differentPerspectiveQueries.add(justDateTimeOnRolesQuery);
return differentPerspectiveQueries;
}
private Set<String> constructOrganizationToGrantsQuery() {
Set<String> differentInvestigatorTypeQueries = new HashSet<String>();
Set<String> investigatorRoleQuery = constructOrganizationGrantsQueryTemplate("hasInvestigatorWithGrant", "InvestigatorRole");
Set<String> piRoleQuery = constructOrganizationGrantsQueryTemplate("hasPIWithGrant", "PrincipalInvestigatorRole");
Set<String> coPIRoleQuery = constructOrganizationGrantsQueryTemplate("hascoPIWithGrant", "CoPrincipalInvestigatorRole");
differentInvestigatorTypeQueries.addAll(investigatorRoleQuery);
differentInvestigatorTypeQueries.addAll(piRoleQuery);
differentInvestigatorTypeQueries.addAll(coPIRoleQuery);
return differentInvestigatorTypeQueries;
}
private Model executeQuery(Set<String> constructQueries) {
Model constructedModel = ModelFactory.createDefaultModel();
before = System.currentTimeMillis();
log.debug("CONSTRUCT query string : " + constructQueries);
for (String currentQuery : constructQueries) {
Query query = null;
try {
query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery() + currentQuery, SYNTAX);
} catch (Throwable th) {
log.error("Could not create CONSTRUCT SPARQL query for query "
+ "string. " + th.getMessage());
log.error(currentQuery);
}
QueryExecution qe = QueryExecutionFactory.create(query, dataset);
try {
qe.execConstruct(constructedModel);
} finally {
qe.close();
}
}
after = System.currentTimeMillis();
log.debug("Time taken to execute the CONSTRUCT queries is in milliseconds: "
+ (after - before));
return constructedModel;
}
public Model getConstructedModel() throws MalformedQueryParametersException {
return executeQuery(constructOrganizationToGrantsQuery());
}
}

View file

@ -53,11 +53,16 @@ public class OrganizationToPublicationsForSubOrganizationsModelConstructor imple
+ " } "
+ " WHERE { "
+ " <" + organizationURI + "> rdfs:label ?organizationLabel . "
+ " <" + organizationURI + "> core:hasSubOrganization* ?subOrganization . "
+ " ?subOrganization core:organizationForPosition ?Position . "
+ " ?Position core:positionForPerson ?Person . "
+ " ?Person core:authorInAuthorship ?Resource . "
+ " ?Resource core:linkedInformationResource ?Document . "
+ " <" + organizationURI + "> <http://purl.obolibrary.org/obo/BFO_0000051>* ?subOrganization . "
+ " ?subOrganization rdf:type foaf:Organization . "
+ " ?subOrganization core:relatedBy ?Position . "
+ " ?Position rdf:type core:Position . "
+ " ?Position core:relates ?Person . "
+ " ?Person rdf:type foaf:Person . "
+ " ?Person core:relatedBy ?Resource . "
+ " ?Resource rdf:type core:Authorship . "
+ " ?Resource core:relates ?Document . "
+ " ?Document rdf:type bibo:Document . "
+ " ?Document rdfs:label ?DocumentLabel . "
+ " "
+ " OPTIONAL { "

View file

@ -1,171 +1,177 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.query.Dataset;
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.Syntax;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.ModelConstructor;
public class PeopleToGrantsModelConstructor implements ModelConstructor {
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private Dataset dataset;
public static final String MODEL_TYPE = "PEOPLE_TO_GRANTS";
public static final String MODEL_TYPE_HUMAN_READABLE = "Grants for all people via all roles";
private Log log = LogFactory.getLog(PeopleToGrantsModelConstructor.class.getName());
private long before, after;
public PeopleToGrantsModelConstructor(Dataset dataset) {
this.dataset = dataset;
}
private Set<String> constructPersonGrantsQueryTemplate(String constructProperty, String roleTypeProperty) {
Set<String> differentPerspectiveQueries = new HashSet<String>();
String justGrantsQuery = ""
+ " CONSTRUCT { "
+ " ?person vivosocnet:lastCachedAt ?now . "
+ " ?person vivosocnet:" + constructProperty + " ?Grant . "
+ " "
+ " ?Grant rdf:type core:Grant . "
+ " ?Grant rdfs:label ?grantLabel . "
+ " "
+ " } "
+ " WHERE { "
+ " ?person core:" + roleTypeProperty + " ?Role . "
+ " ?Role core:roleContributesTo ?Grant . "
+ " ?Grant rdfs:label ?grantLabel . "
+ " "
+ " LET(?now := afn:now()) "
+ " } ";
String justDateTimeOnGrantsQuery = ""
+ " CONSTRUCT { "
+ " ?person vivosocnet:lastCachedAt ?now . "
+ " ?Grant vivosocnet:startDateTimeOnGrant ?startDateTimeValueForGrant . "
// + " ?Grant vivosocnet:endDateTimeOnGrant ?endDateTimeValueForGrant . "
+ " "
+ " } "
+ " WHERE { "
+ " ?person core:" + roleTypeProperty + " ?Role . "
+ " ?Role core:roleContributesTo ?Grant . "
+ " "
+ " ?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
// + " OPTIONAL { "
+ " ?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
+ " ?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
// + " } "
// + " OPTIONAL { "
// + " ?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
// + " ?endDateForGrant core:dateTime ?endDateTimeValueForGrant "
// + " } "
+ " "
+ " LET(?now := afn:now()) "
+ " } ";
String justDateTimeOnRolesQuery = ""
+ " CONSTRUCT { "
+ " ?person vivosocnet:lastCachedAt ?now . "
+ " ?Grant vivosocnet:startDateTimeOnRole ?startDateTimeValue . "
// + " ?Grant vivosocnet:endDateTimeOnRole ?endDateTimeValue . "
+ " } "
+ " WHERE { "
+ " ?person core:" + roleTypeProperty + " ?Role . "
+ " ?Role core:roleContributesTo ?Grant . "
+ " "
+ " ?Role core:dateTimeInterval ?dateTimeIntervalValue . "
// + " OPTIONAL { "
+ " ?dateTimeIntervalValue core:start ?startDate . "
+ " ?startDate core:dateTime ?startDateTimeValue . "
// + " } "
// + " "
// + " OPTIONAL { "
// + " ?dateTimeIntervalValue core:end ?endDate . "
// + " ?endDate core:dateTime ?endDateTimeValue . "
// + " } "
+ " "
+ " LET(?now := afn:now()) "
+ " } ";
differentPerspectiveQueries.add(justGrantsQuery);
differentPerspectiveQueries.add(justDateTimeOnGrantsQuery);
differentPerspectiveQueries.add(justDateTimeOnRolesQuery);
return differentPerspectiveQueries;
}
private Set<String> constructPeopleToGrantsQuery() {
Set<String> differentInvestigatorTypeQueries = new HashSet<String>();
Set<String> investigatorRoleQuery = constructPersonGrantsQueryTemplate("hasGrantAsAnInvestigator", "hasInvestigatorRole");
Set<String> piRoleQuery = constructPersonGrantsQueryTemplate("hasGrantAsPI", "hasPrincipalInvestigatorRole");
Set<String> coPIRoleQuery = constructPersonGrantsQueryTemplate("hasGrantAsCoPI", "hasCo-PrincipalInvestigatorRole");
differentInvestigatorTypeQueries.addAll(investigatorRoleQuery);
differentInvestigatorTypeQueries.addAll(piRoleQuery);
differentInvestigatorTypeQueries.addAll(coPIRoleQuery);
return differentInvestigatorTypeQueries;
}
private Model executeQuery(Set<String> constructQueries) {
Model constructedModel = ModelFactory.createDefaultModel();
before = System.currentTimeMillis();
log.debug("CONSTRUCT query string : " + constructQueries);
for (String currentQuery : constructQueries) {
Query query = null;
try {
query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery() + currentQuery, SYNTAX);
} catch (Throwable th) {
log.error("Could not create CONSTRUCT SPARQL query for query "
+ "string. " + th.getMessage());
log.error(currentQuery);
}
QueryExecution qe = QueryExecutionFactory.create(query, dataset);
try {
qe.execConstruct(constructedModel);
} finally {
qe.close();
}
}
after = System.currentTimeMillis();
log.debug("Time taken to execute the CONSTRUCT queries is in milliseconds: "
+ (after - before));
return constructedModel;
}
public Model getConstructedModel() throws MalformedQueryParametersException {
return executeQuery(constructPeopleToGrantsQuery());
}
}
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.query.Dataset;
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.Syntax;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.ModelConstructor;
public class PeopleToGrantsModelConstructor implements ModelConstructor {
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private Dataset dataset;
public static final String MODEL_TYPE = "PEOPLE_TO_GRANTS";
public static final String MODEL_TYPE_HUMAN_READABLE = "Grants for all people via all roles";
private Log log = LogFactory.getLog(PeopleToGrantsModelConstructor.class.getName());
private long before, after;
public PeopleToGrantsModelConstructor(Dataset dataset) {
this.dataset = dataset;
}
private Set<String> constructPersonGrantsQueryTemplate(String constructProperty, String roleType) {
Set<String> differentPerspectiveQueries = new HashSet<String>();
String justGrantsQuery = ""
+ " CONSTRUCT { "
+ " ?Person vivosocnet:lastCachedAt ?now . "
+ " ?Person vivosocnet:" + constructProperty + " ?Grant . "
+ " "
+ " ?Grant rdf:type core:Grant . "
+ " ?Grant rdfs:label ?grantLabel . "
+ " "
+ " } "
+ " WHERE { "
+ " ?Person <http://purl.obolibrary.org/obo/RO_0000053> ?Role . "
+ " ?Role rdf:type core:" + roleType + " . "
+ " ?Role core:relatedBy ?Grant . "
+ " ?Grant rdf:type core:Grant . "
+ " ?Grant rdfs:label ?grantLabel . "
+ " "
+ " LET(?now := afn:now()) "
+ " } ";
String justDateTimeOnGrantsQuery = ""
+ " CONSTRUCT { "
+ " ?Person vivosocnet:lastCachedAt ?now . "
+ " ?Grant vivosocnet:startDateTimeOnGrant ?startDateTimeValueForGrant . "
// + " ?Grant vivosocnet:endDateTimeOnGrant ?endDateTimeValueForGrant . "
+ " "
+ " } "
+ " WHERE { "
+ " ?Person <http://purl.obolibrary.org/obo/RO_0000053> ?Role . "
+ " ?Role rdf:type core:" + roleType + " . "
+ " ?Role core:relatedBy ?Grant . "
+ " ?Grant rdf:type core:Grant . "
+ " "
+ " ?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
// + " OPTIONAL { "
+ " ?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
+ " ?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
// + " } "
// + " OPTIONAL { "
// + " ?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
// + " ?endDateForGrant core:dateTime ?endDateTimeValueForGrant "
// + " } "
+ " "
+ " LET(?now := afn:now()) "
+ " } ";
String justDateTimeOnRolesQuery = ""
+ " CONSTRUCT { "
+ " ?Person vivosocnet:lastCachedAt ?now . "
+ " ?Grant vivosocnet:startDateTimeOnRole ?startDateTimeValue . "
// + " ?Grant vivosocnet:endDateTimeOnRole ?endDateTimeValue . "
+ " } "
+ " WHERE { "
+ " ?Person <http://purl.obolibrary.org/obo/RO_0000053> ?Role . "
+ " ?Role rdf:type core:" + roleType + " . "
+ " ?Role core:relatedBy ?Grant . "
+ " ?Grant rdf:type core:Grant . "
+ " "
+ " ?Role core:dateTimeInterval ?dateTimeIntervalValue . "
// + " OPTIONAL { "
+ " ?dateTimeIntervalValue core:start ?startDate . "
+ " ?startDate core:dateTime ?startDateTimeValue . "
// + " } "
// + " "
// + " OPTIONAL { "
// + " ?dateTimeIntervalValue core:end ?endDate . "
// + " ?endDate core:dateTime ?endDateTimeValue . "
// + " } "
+ " "
+ " LET(?now := afn:now()) "
+ " } ";
differentPerspectiveQueries.add(justGrantsQuery);
differentPerspectiveQueries.add(justDateTimeOnGrantsQuery);
differentPerspectiveQueries.add(justDateTimeOnRolesQuery);
return differentPerspectiveQueries;
}
private Set<String> constructPeopleToGrantsQuery() {
Set<String> differentInvestigatorTypeQueries = new HashSet<String>();
Set<String> investigatorRoleQuery = constructPersonGrantsQueryTemplate("hasGrantAsAnInvestigator", "InvestigatorRole");
Set<String> piRoleQuery = constructPersonGrantsQueryTemplate("hasGrantAsPI", "PrincipalInvestigatorRole");
Set<String> coPIRoleQuery = constructPersonGrantsQueryTemplate("hasGrantAsCoPI", "CoPrincipalInvestigatorRole");
differentInvestigatorTypeQueries.addAll(investigatorRoleQuery);
differentInvestigatorTypeQueries.addAll(piRoleQuery);
differentInvestigatorTypeQueries.addAll(coPIRoleQuery);
return differentInvestigatorTypeQueries;
}
private Model executeQuery(Set<String> constructQueries) {
Model constructedModel = ModelFactory.createDefaultModel();
before = System.currentTimeMillis();
log.debug("CONSTRUCT query string : " + constructQueries);
for (String currentQuery : constructQueries) {
Query query = null;
try {
query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery() + currentQuery, SYNTAX);
} catch (Throwable th) {
log.error("Could not create CONSTRUCT SPARQL query for query "
+ "string. " + th.getMessage());
log.error(currentQuery);
}
QueryExecution qe = QueryExecutionFactory.create(query, dataset);
try {
qe.execConstruct(constructedModel);
} finally {
qe.close();
}
}
after = System.currentTimeMillis();
log.debug("Time taken to execute the CONSTRUCT queries is in milliseconds: "
+ (after - before));
return constructedModel;
}
public Model getConstructedModel() throws MalformedQueryParametersException {
return executeQuery(constructPeopleToGrantsQuery());
}
}

View file

@ -48,8 +48,11 @@ public class PeopleToPublicationsModelConstructor implements ModelConstructor {
+ " ?journal rdfs:label ?journalLabel . "
+ " } "
+ " WHERE { "
+ " ?person core:authorInAuthorship ?Resource . "
+ " ?Resource core:linkedInformationResource ?Document . "
+ " ?person core:relatedBy ?Resource . "
+ " ?person rdf:type foaf:Person . "
+ " ?Resource rdf:type core:Authorship . "
+ " ?Resource core:relates ?Document . "
+ " ?Document rdf:type bibo:Document . "
+ " ?Document rdfs:label ?DocumentLabel . "
+ " "
+ " OPTIONAL { "

View file

@ -1,174 +1,180 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.query.Dataset;
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.Syntax;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.ModelConstructor;
public class PersonToGrantsModelConstructor implements ModelConstructor {
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private Dataset dataset;
public static final String MODEL_TYPE = "PERSON_TO_GRANTS";
public static final String MODEL_TYPE_HUMAN_READABLE = "Grants for specific person via all roles";
private String personURI;
private Log log = LogFactory.getLog(PersonToGrantsModelConstructor.class.getName());
private long before, after;
public PersonToGrantsModelConstructor(String personURI, Dataset dataset) {
this.personURI = personURI;
this.dataset = dataset;
}
private Set<String> constructPersonGrantsQueryTemplate(String constructProperty, String roleTypeProperty) {
Set<String> differentPerspectiveQueries = new HashSet<String>();
String justGrantsQuery = ""
+ " CONSTRUCT { "
+ " <" + personURI + "> vivosocnet:lastCachedAt ?now . "
+ " <" + personURI + "> vivosocnet:" + constructProperty + " ?Grant . "
+ " "
+ " ?Grant rdf:type core:Grant . "
+ " ?Grant rdfs:label ?grantLabel . "
+ " "
+ " } "
+ " WHERE { "
+ " <" + personURI + "> core:" + roleTypeProperty + " ?Role . "
+ " ?Role core:roleContributesTo ?Grant . "
+ " ?Grant rdfs:label ?grantLabel . "
+ " "
+ " LET(?now := afn:now()) "
+ " } ";
String justDateTimeOnGrantsQuery = ""
+ " CONSTRUCT { "
+ " <" + personURI + "> vivosocnet:lastCachedAt ?now . "
+ " ?Grant vivosocnet:startDateTimeOnGrant ?startDateTimeValueForGrant . "
// + " ?Grant vivosocnet:endDateTimeOnGrant ?endDateTimeValueForGrant . "
+ " "
+ " } "
+ " WHERE { "
+ " <" + personURI + "> core:" + roleTypeProperty + " ?Role . "
+ " ?Role core:roleContributesTo ?Grant . "
+ " "
+ " ?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
// + " OPTIONAL { "
+ " ?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
+ " ?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
// + " } "
// + " OPTIONAL { "
// + " ?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
// + " ?endDateForGrant core:dateTime ?endDateTimeValueForGrant "
// + " } "
+ " "
+ " LET(?now := afn:now()) "
+ " } ";
String justDateTimeOnRolesQuery = ""
+ " CONSTRUCT { "
+ " <" + personURI + "> vivosocnet:lastCachedAt ?now . "
+ " ?Grant vivosocnet:startDateTimeOnRole ?startDateTimeValue . "
// + " ?Grant vivosocnet:endDateTimeOnRole ?endDateTimeValue . "
+ " } "
+ " WHERE { "
+ " <" + personURI + "> core:" + roleTypeProperty + " ?Role . "
+ " ?Role core:roleContributesTo ?Grant . "
+ " "
+ " ?Role core:dateTimeInterval ?dateTimeIntervalValue . "
// + " OPTIONAL { "
+ " ?dateTimeIntervalValue core:start ?startDate . "
+ " ?startDate core:dateTime ?startDateTimeValue . "
// + " } "
// + " "
// + " OPTIONAL { "
// + " ?dateTimeIntervalValue core:end ?endDate . "
// + " ?endDate core:dateTime ?endDateTimeValue . "
// + " } "
+ " "
+ " LET(?now := afn:now()) "
+ " } ";
differentPerspectiveQueries.add(justGrantsQuery);
differentPerspectiveQueries.add(justDateTimeOnGrantsQuery);
differentPerspectiveQueries.add(justDateTimeOnRolesQuery);
return differentPerspectiveQueries;
}
private Set<String> constructPersonToGrantsQuery() {
Set<String> differentInvestigatorTypeQueries = new HashSet<String>();
Set<String> investigatorRoleQuery = constructPersonGrantsQueryTemplate("hasGrantAsAnInvestigator", "hasInvestigatorRole");
Set<String> piRoleQuery = constructPersonGrantsQueryTemplate("hasGrantAsPI", "hasPrincipalInvestigatorRole");
Set<String> coPIRoleQuery = constructPersonGrantsQueryTemplate("hasGrantAsCoPI", "hasCo-PrincipalInvestigatorRole");
differentInvestigatorTypeQueries.addAll(investigatorRoleQuery);
differentInvestigatorTypeQueries.addAll(piRoleQuery);
differentInvestigatorTypeQueries.addAll(coPIRoleQuery);
return differentInvestigatorTypeQueries;
}
private Model executeQuery(Set<String> constructQueries) {
Model constructedModel = ModelFactory.createDefaultModel();
before = System.currentTimeMillis();
log.debug("CONSTRUCT query string : " + constructQueries);
for (String currentQuery : constructQueries) {
Query query = null;
try {
query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery() + currentQuery, SYNTAX);
} catch (Throwable th) {
log.error("Could not create CONSTRUCT SPARQL query for query "
+ "string. " + th.getMessage());
log.error(currentQuery);
}
QueryExecution qe = QueryExecutionFactory.create(query, dataset);
try {
qe.execConstruct(constructedModel);
} finally {
qe.close();
}
}
after = System.currentTimeMillis();
log.debug("Time taken to execute the CONSTRUCT queries is in milliseconds: "
+ (after - before));
return constructedModel;
}
public Model getConstructedModel() throws MalformedQueryParametersException {
return executeQuery(constructPersonToGrantsQuery());
}
}
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.query.Dataset;
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.Syntax;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.ModelConstructor;
public class PersonToGrantsModelConstructor implements ModelConstructor {
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private Dataset dataset;
public static final String MODEL_TYPE = "PERSON_TO_GRANTS";
public static final String MODEL_TYPE_HUMAN_READABLE = "Grants for specific person via all roles";
private String personURI;
private Log log = LogFactory.getLog(PersonToGrantsModelConstructor.class.getName());
private long before, after;
public PersonToGrantsModelConstructor(String personURI, Dataset dataset) {
this.personURI = personURI;
this.dataset = dataset;
}
private Set<String> constructPersonGrantsQueryTemplate(String constructProperty, String roleType) {
Set<String> differentPerspectiveQueries = new HashSet<String>();
String justGrantsQuery = ""
+ " CONSTRUCT { "
+ " <" + personURI + "> vivosocnet:lastCachedAt ?now . "
+ " <" + personURI + "> vivosocnet:" + constructProperty + " ?Grant . "
+ " "
+ " ?Grant rdf:type core:Grant . "
+ " ?Grant rdfs:label ?grantLabel . "
+ " "
+ " } "
+ " WHERE { "
+ " <" + personURI + "> <http://purl.obolibrary.org/obo/RO_0000053> ?Role . "
+ " ?Role rdf:type core:" + roleType + " . "
+ " ?Role core:relatedBy ?Grant . "
+ " ?Grant rdf:type core:Grant . "
+ " ?Grant rdfs:label ?grantLabel . "
+ " "
+ " LET(?now := afn:now()) "
+ " } ";
String justDateTimeOnGrantsQuery = ""
+ " CONSTRUCT { "
+ " <" + personURI + "> vivosocnet:lastCachedAt ?now . "
+ " ?Grant vivosocnet:startDateTimeOnGrant ?startDateTimeValueForGrant . "
// + " ?Grant vivosocnet:endDateTimeOnGrant ?endDateTimeValueForGrant . "
+ " "
+ " } "
+ " WHERE { "
+ " <" + personURI + "> <http://purl.obolibrary.org/obo/RO_0000053> ?Role . "
+ " ?Role rdf:type core:" + roleType + " . "
+ " ?Role core:relatedBy ?Grant . "
+ " ?Grant rdf:type core:Grant . "
+ " "
+ " ?Grant core:dateTimeInterval ?dateTimeIntervalValueForGrant . "
// + " OPTIONAL { "
+ " ?dateTimeIntervalValueForGrant core:start ?startDateForGrant . "
+ " ?startDateForGrant core:dateTime ?startDateTimeValueForGrant . "
// + " } "
// + " OPTIONAL { "
// + " ?dateTimeIntervalValueForGrant core:end ?endDateForGrant . "
// + " ?endDateForGrant core:dateTime ?endDateTimeValueForGrant "
// + " } "
+ " "
+ " LET(?now := afn:now()) "
+ " } ";
String justDateTimeOnRolesQuery = ""
+ " CONSTRUCT { "
+ " <" + personURI + "> vivosocnet:lastCachedAt ?now . "
+ " ?Grant vivosocnet:startDateTimeOnRole ?startDateTimeValue . "
// + " ?Grant vivosocnet:endDateTimeOnRole ?endDateTimeValue . "
+ " } "
+ " WHERE { "
+ " <" + personURI + "> <http://purl.obolibrary.org/obo/RO_0000053> ?Role . "
+ " ?Role rdf:type core:" + roleType + " . "
+ " ?Role core:relatedBy ?Grant . "
+ " ?Grant rdf:type core:Grant . "
+ " "
+ " ?Role core:dateTimeInterval ?dateTimeIntervalValue . "
// + " OPTIONAL { "
+ " ?dateTimeIntervalValue core:start ?startDate . "
+ " ?startDate core:dateTime ?startDateTimeValue . "
// + " } "
// + " "
// + " OPTIONAL { "
// + " ?dateTimeIntervalValue core:end ?endDate . "
// + " ?endDate core:dateTime ?endDateTimeValue . "
// + " } "
+ " "
+ " LET(?now := afn:now()) "
+ " } ";
differentPerspectiveQueries.add(justGrantsQuery);
differentPerspectiveQueries.add(justDateTimeOnGrantsQuery);
differentPerspectiveQueries.add(justDateTimeOnRolesQuery);
return differentPerspectiveQueries;
}
private Set<String> constructPersonToGrantsQuery() {
Set<String> differentInvestigatorTypeQueries = new HashSet<String>();
Set<String> investigatorRoleQuery = constructPersonGrantsQueryTemplate("hasGrantAsAnInvestigator", "InvestigatorRole");
Set<String> piRoleQuery = constructPersonGrantsQueryTemplate("hasGrantAsPI", "PrincipalInvestigatorRole");
Set<String> coPIRoleQuery = constructPersonGrantsQueryTemplate("hasGrantAsCoPI", "CoPrincipalInvestigatorRole");
differentInvestigatorTypeQueries.addAll(investigatorRoleQuery);
differentInvestigatorTypeQueries.addAll(piRoleQuery);
differentInvestigatorTypeQueries.addAll(coPIRoleQuery);
return differentInvestigatorTypeQueries;
}
private Model executeQuery(Set<String> constructQueries) {
Model constructedModel = ModelFactory.createDefaultModel();
before = System.currentTimeMillis();
log.debug("CONSTRUCT query string : " + constructQueries);
for (String currentQuery : constructQueries) {
Query query = null;
try {
query = QueryFactory.create(QueryConstants.getSparqlPrefixQuery() + currentQuery, SYNTAX);
} catch (Throwable th) {
log.error("Could not create CONSTRUCT SPARQL query for query "
+ "string. " + th.getMessage());
log.error(currentQuery);
}
QueryExecution qe = QueryExecutionFactory.create(query, dataset);
try {
qe.execConstruct(constructedModel);
} finally {
qe.close();
}
}
after = System.currentTimeMillis();
log.debug("Time taken to execute the CONSTRUCT queries is in milliseconds: "
+ (after - before));
return constructedModel;
}
public Model getConstructedModel() throws MalformedQueryParametersException {
return executeQuery(constructPersonToGrantsQuery());
}
}

View file

@ -51,8 +51,10 @@ public class PersonToPublicationsModelConstructor implements ModelConstructor {
+ " ?journal rdfs:label ?journalLabel . "
+ " } "
+ " WHERE { "
+ " <" + personURI + "> core:authorInAuthorship ?Resource . "
+ " ?Resource core:linkedInformationResource ?Document . "
+ " <" + personURI + "> core:relatedBy ?Resource . "
+ " ?Resource rdf:type core:Authorship . "
+ " ?Resource core:relates ?Document . "
+ " ?Document rdf:type bibo:Document . "
+ " ?Document rdfs:label ?DocumentLabel . "
+ " "
+ " OPTIONAL { "

View file

@ -50,7 +50,8 @@ public class SubOrganizationWithinModelConstructor implements ModelConstructor {
+ " CONSTRUCT { "
+ " ?organization rdf:type foaf:Organization . "
+ " ?organization rdfs:label ?organizationLabel . "
+ " ?organization core:subOrganizationWithin ?parentOrganization . "
+ " ?organization <http://purl.obolibrary.org/obo/BFO_0000050> ?parentOrganization . "
+ " ?parentOrganization rdf:type foaf:Organization . "
+ " ?parentOrganization rdfs:label ?parentOrganizationLabel . "
+ " } "
+ " WHERE { "
@ -58,7 +59,8 @@ public class SubOrganizationWithinModelConstructor implements ModelConstructor {
+ " ?organization rdfs:label ?organizationLabel . "
+ " "
+ " OPTIONAL { "
+ " ?organization core:subOrganizationWithin ?parentOrganization . "
+ " ?organization <http://purl.obolibrary.org/obo/BFO_0000050> ?parentOrganization . "
+ " ?parentOrganization rdf:type foaf:Organization . "
+ " ?parentOrganization rdfs:label ?parentOrganizationLabel . "
+ " } "
+ " } ";

View file

@ -1,162 +1,163 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.personpubcount;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import com.hp.hpl.jena.iri.IRI;
import com.hp.hpl.jena.iri.IRIFactory;
import com.hp.hpl.jena.iri.Violation;
import com.hp.hpl.jena.query.Dataset;
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.ResultSet;
import com.hp.hpl.jena.query.Syntax;
import com.hp.hpl.jena.rdf.model.RDFNode;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Activity;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Individual;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.QueryRunner;
/**
* This query runner is used to execute a sparql query that will fetch all the publications
* defined by bibo:Document property for a particular individual.
*
* @author cdtank
*/
public class PersonPublicationCountQueryRunner implements QueryRunner<Set<Activity>> {
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private String personURI;
private Dataset dataset;
private Individual author;
public Individual getAuthor() {
return author;
}
private Log log;
private static final String SPARQL_QUERY_COMMON_SELECT_CLAUSE = ""
+ "SELECT (str(?authorLabel) as ?" + QueryFieldLabels.AUTHOR_LABEL + ") \n"
+ " (str(?document) as ?" + QueryFieldLabels.DOCUMENT_URL + ") \n"
+ " (str(?publicationDate) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_DATE + ")\n";
private static final String SPARQL_QUERY_COMMON_WHERE_CLAUSE = ""
+ "?document rdfs:label ?documentLabel .\n"
+ "OPTIONAL { ?document core:dateTimeValue ?dateTimeValue . \n"
+ " ?dateTimeValue core:dateTime ?publicationDate } .\n";
public PersonPublicationCountQueryRunner(String personURI,
Dataset dataset, Log log) {
this.personURI = personURI;
this.dataset = dataset;
this.log = log;
}
private Set<Activity> createJavaValueObjects(ResultSet resultSet) {
Set<Activity> authorDocuments = new HashSet<Activity>();
while (resultSet.hasNext()) {
QuerySolution solution = resultSet.nextSolution();
Activity biboDocument = new Activity(
solution.get(QueryFieldLabels.DOCUMENT_URL)
.toString());
RDFNode publicationDateNode = solution.get(QueryFieldLabels.DOCUMENT_PUBLICATION_DATE);
if (publicationDateNode != null) {
biboDocument.setActivityDate(publicationDateNode.toString());
}
/*
* Since we are getting publication count for just one author at a time we need
* to create only one "Individual" instance. We test against the null for "author" to
* make sure that it has not already been instantiated.
* */
RDFNode authorURLNode = solution.get(QueryFieldLabels.AUTHOR_URL);
if (authorURLNode != null && author == null) {
author = new Individual(authorURLNode.toString());
RDFNode authorLabelNode = solution.get(QueryFieldLabels.AUTHOR_LABEL);
if (authorLabelNode != null) {
author.setIndividualLabel(authorLabelNode.toString());
}
}
authorDocuments.add(biboDocument);
}
return authorDocuments;
}
private ResultSet executeQuery(String queryURI,
Dataset dataset) {
QueryExecution queryExecution = null;
Query query = QueryFactory.create(getSparqlQuery(queryURI), SYNTAX);
queryExecution = QueryExecutionFactory.create(query, dataset);
return queryExecution.execSelect();
}
private String getSparqlQuery(String queryURI) {
String sparqlQuery = QueryConstants.getSparqlPrefixQuery()
+ SPARQL_QUERY_COMMON_SELECT_CLAUSE
+ "(str(<" + queryURI + ">) as ?authPersonLit)\n "
+ "WHERE { \n"
+ "<" + queryURI + "> rdf:type foaf:Person ;\n"
+ " rdfs:label ?authorLabel \n;"
+ " core:authorInAuthorship ?authorshipNode . \n"
+ " ?authorshipNode rdf:type core:Authorship ;"
+ " core:linkedInformationResource ?document . \n"
+ SPARQL_QUERY_COMMON_WHERE_CLAUSE
+ "}\n";
log.debug(sparqlQuery);
return sparqlQuery;
}
public Set<Activity> getQueryResult()
throws MalformedQueryParametersException {
if (StringUtils.isNotBlank(this.personURI)) {
/*
* To test for the validity of the URI submitted.
* */
IRIFactory iRIFactory = IRIFactory.jenaImplementation();
IRI iri = iRIFactory.create(this.personURI);
if (iri.hasViolation(false)) {
String errorMsg = ((Violation) iri.violations(false).next()).getShortMessage();
log.error("Pub Count vis Query " + errorMsg);
throw new MalformedQueryParametersException(
"URI provided for an individual is malformed.");
}
} else {
throw new MalformedQueryParametersException("URL parameter is either null or empty.");
}
ResultSet resultSet = executeQuery(this.personURI,
this.dataset);
return createJavaValueObjects(resultSet);
}
}
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.personpubcount;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import com.hp.hpl.jena.iri.IRI;
import com.hp.hpl.jena.iri.IRIFactory;
import com.hp.hpl.jena.iri.Violation;
import com.hp.hpl.jena.query.Dataset;
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.ResultSet;
import com.hp.hpl.jena.query.Syntax;
import com.hp.hpl.jena.rdf.model.RDFNode;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Activity;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Individual;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.QueryRunner;
/**
* This query runner is used to execute a sparql query that will fetch all the publications
* defined by bibo:Document property for a particular individual.
*
* @author cdtank
*/
public class PersonPublicationCountQueryRunner implements QueryRunner<Set<Activity>> {
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private String personURI;
private Dataset dataset;
private Individual author;
public Individual getAuthor() {
return author;
}
private Log log;
private static final String SPARQL_QUERY_COMMON_SELECT_CLAUSE = ""
+ "SELECT (str(?authorLabel) as ?" + QueryFieldLabels.AUTHOR_LABEL + ") \n"
+ " (str(?document) as ?" + QueryFieldLabels.DOCUMENT_URL + ") \n"
+ " (str(?publicationDate) as ?" + QueryFieldLabels.DOCUMENT_PUBLICATION_DATE + ")\n";
private static final String SPARQL_QUERY_COMMON_WHERE_CLAUSE = ""
+ "?document rdfs:label ?documentLabel .\n"
+ "OPTIONAL { ?document core:dateTimeValue ?dateTimeValue . \n"
+ " ?dateTimeValue core:dateTime ?publicationDate } .\n";
public PersonPublicationCountQueryRunner(String personURI,
Dataset dataset, Log log) {
this.personURI = personURI;
this.dataset = dataset;
this.log = log;
}
private Set<Activity> createJavaValueObjects(ResultSet resultSet) {
Set<Activity> authorDocuments = new HashSet<Activity>();
while (resultSet.hasNext()) {
QuerySolution solution = resultSet.nextSolution();
Activity biboDocument = new Activity(
solution.get(QueryFieldLabels.DOCUMENT_URL)
.toString());
RDFNode publicationDateNode = solution.get(QueryFieldLabels.DOCUMENT_PUBLICATION_DATE);
if (publicationDateNode != null) {
biboDocument.setActivityDate(publicationDateNode.toString());
}
/*
* Since we are getting publication count for just one author at a time we need
* to create only one "Individual" instance. We test against the null for "author" to
* make sure that it has not already been instantiated.
* */
RDFNode authorURLNode = solution.get(QueryFieldLabels.AUTHOR_URL);
if (authorURLNode != null && author == null) {
author = new Individual(authorURLNode.toString());
RDFNode authorLabelNode = solution.get(QueryFieldLabels.AUTHOR_LABEL);
if (authorLabelNode != null) {
author.setIndividualLabel(authorLabelNode.toString());
}
}
authorDocuments.add(biboDocument);
}
return authorDocuments;
}
private ResultSet executeQuery(String queryURI,
Dataset dataset) {
QueryExecution queryExecution = null;
Query query = QueryFactory.create(getSparqlQuery(queryURI), SYNTAX);
queryExecution = QueryExecutionFactory.create(query, dataset);
return queryExecution.execSelect();
}
private String getSparqlQuery(String queryURI) {
String sparqlQuery = QueryConstants.getSparqlPrefixQuery()
+ SPARQL_QUERY_COMMON_SELECT_CLAUSE
+ "(str(<" + queryURI + ">) as ?authPersonLit)\n "
+ "WHERE { \n"
+ "<" + queryURI + "> rdf:type foaf:Person ;\n"
+ " rdfs:label ?authorLabel \n;"
+ " core:relatedBy ?authorshipNode . \n"
+ " ?authorshipNode rdf:type core:Authorship ;"
+ " core:relates ?document . \n"
+ " ?document rdf:type bibo:Document . \n"
+ SPARQL_QUERY_COMMON_WHERE_CLAUSE
+ "}\n";
log.debug(sparqlQuery);
return sparqlQuery;
}
public Set<Activity> getQueryResult()
throws MalformedQueryParametersException {
if (StringUtils.isNotBlank(this.personURI)) {
/*
* To test for the validity of the URI submitted.
* */
IRIFactory iRIFactory = IRIFactory.jenaImplementation();
IRI iri = iRIFactory.create(this.personURI);
if (iri.hasViolation(false)) {
String errorMsg = ((Violation) iri.violations(false).next()).getShortMessage();
log.error("Pub Count vis Query " + errorMsg);
throw new MalformedQueryParametersException(
"URI provided for an individual is malformed.");
}
} else {
throw new MalformedQueryParametersException("URL parameter is either null or empty.");
}
ResultSet resultSet = executeQuery(this.personURI,
this.dataset);
return createJavaValueObjects(resultSet);
}
}

View file

@ -80,8 +80,10 @@ public class OrganizationUtilityFunctions {
String whereClause = "?organization rdf:type foaf:Organization ;"
+ " rdfs:label ?organizationLabel . \n"
+ "OPTIONAL { ?organization core:hasSubOrganization ?subOrg } . \n"
+ "OPTIONAL { ?organization core:subOrganizationWithin ?parent } . \n"
+ "OPTIONAL { ?organization <http://purl.obolibrary.org/obo/BFO_0000051> ?subOrg . \n"
+ " ?subOrg rdf:type foaf:Organization } . \n"
+ "OPTIONAL { ?organization <http://purl.obolibrary.org/obo/BFO_0000050> ?parent . \n"
+ " ?parent rdf:type foaf:Organization } . \n"
+ "FILTER ( !bound(?parent) ). \n";
String groupOrderClause = "GROUP BY ?organization ?organizationLabel \n"

View file

@ -123,9 +123,10 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler {
String whereClause =
"<" + individualURI + "> rdf:type foaf:Person ;"
+ " core:authorInAuthorship ?authorshipNode . \n"
+ " core:relatedBy ?authorshipNode . \n"
+ "?authorshipNode rdf:type core:Authorship ;"
+ " core:linkedInformationResource ?document .";
+ " core:relates ?document . \n"
+ "?document rdf:type bibo:Document .";
String groupOrderClause = "GROUP BY ?" + QueryFieldLabels.AUTHOR_URL + " \n";
@ -152,16 +153,22 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler {
ObjectProperty predicate = ModelUtils.getPropertyForRoleInClass(grantType, vitroRequest.getWebappDaoFactory());
String roleToGrantPredicate = "<" + predicate.getURI() + ">";
String whereClause = "{ <" + individualURI + "> rdf:type foaf:Person ;"
+ " core:hasCo-PrincipalInvestigatorRole ?Role . \n"
+ " <http://purl.obolibrary.org/obo/RO_0000053> ?Role . \n"
+ "?Role rdf:type core:PrincipalInvestigatorRole . \n"
+ "?Role " + roleToGrantPredicate + " ?Grant . }"
+ "UNION \n"
+ "{ <" + individualURI + "> rdf:type foaf:Person ;"
+ " core:hasPrincipalInvestigatorRole ?Role . \n"
+ " <http://purl.obolibrary.org/obo/RO_0000053> ?Role . \n"
+ "?Role rdf:type core:CoPrincipalInvestigatorRole . \n"
+ "?Role " + roleToGrantPredicate + " ?Grant . }"
+ "UNION \n"
+ "{ <" + individualURI + "> rdf:type foaf:Person ;"
+ " core:hasInvestigatorRole ?Role . \n"
+ "?Role " + roleToGrantPredicate + " ?Grant . }";
+ " <http://purl.obolibrary.org/obo/RO_0000053> ?Role . \n"
+ "?Role rdf:type core:InvestigatorRole. \n"
+ "?Role vitro:mostSpecificType ?subclass . \n"
+ "?Role " + roleToGrantPredicate + " ?Grant . \n"
+ "FILTER (?subclass != core:PrincipalInvestigatorRole && "
+ "?subclass != core:CoPrincipalInvestigatorRole)}";
QueryRunner<ResultSet> numberOfGrantsQueryHandler =
new GenericQueryRunner(fieldLabelToOutputFieldLabel,
@ -302,9 +309,11 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler {
String whereClause = "?organization rdf:type foaf:Organization ;"
+ " rdfs:label ?organizationLabel . \n"
+ "OPTIONAL { ?organization core:hasSubOrganization ?subOrg } . \n"
+ "OPTIONAL { ?organization core:subOrganizationWithin ?parent } . \n"
+ "FILTER ( !bound(?parent) ). \n";
+ "OPTIONAL { ?organization core:http://purl.obolibrary.org/obo/BFO_0000051 ?subOrg . \n"
+ " ?subOrg rdf:type foaf:Organization } . \n"
+ "OPTIONAL { ?organization core:http://purl.obolibrary.org/obo/BFO_0000050 ?parent } . \n"
+ " ?parent rdf:type foaf:Organization } . \n"
+ "FILTER ( !bound(?parent) ). \n";
String groupOrderClause = "GROUP BY ?organization ?organizationLabel \n"
+ "ORDER BY DESC(?numOfChildren)\n"

View file

@ -1,134 +1,138 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.visutils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import com.hp.hpl.jena.iri.IRI;
import com.hp.hpl.jena.iri.IRIFactory;
import com.hp.hpl.jena.iri.Violation;
import com.hp.hpl.jena.query.Dataset;
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.ResultSet;
import com.hp.hpl.jena.query.Syntax;
import com.hp.hpl.jena.rdf.model.RDFNode;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.GenericQueryMap;
/**
* This query runner is used to execute a sparql query that will fetch all the
* properties available for the provided individual URI.
*
* @author cdtank
*/
public class AllPropertiesQueryRunner implements QueryRunner<GenericQueryMap> {
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private String filterRule, individualURI;
private Dataset dataset;
private Log log;
public AllPropertiesQueryRunner(String individualURI,
String filterRule,
Dataset dataset,
Log log) {
this.individualURI = individualURI;
this.filterRule = filterRule;
this.dataset = dataset;
this.log = log;
}
private GenericQueryMap createJavaValueObjects(ResultSet resultSet) {
GenericQueryMap queryResult = new GenericQueryMap();
while (resultSet.hasNext()) {
QuerySolution solution = resultSet.nextSolution();
RDFNode predicateNode = solution.get(QueryFieldLabels.PREDICATE);
RDFNode objectNode = solution.get(QueryFieldLabels.OBJECT);
if (predicateNode != null && objectNode != null) {
queryResult.addEntry(predicateNode.toString(),
objectNode.toString());
}
}
return queryResult;
}
private ResultSet executeQuery(String queryText,
Dataset dataset) {
QueryExecution queryExecution = null;
Query query = QueryFactory.create(queryText, SYNTAX);
queryExecution = QueryExecutionFactory.create(query, dataset);
return queryExecution.execSelect();
}
private String generateGenericSparqlQuery(String queryURI, String filterRule) {
// Resource uri1 = ResourceFactory.createResource(queryURI);
String filterClause;
if (StringUtils.isNotBlank(filterRule)) {
filterClause = "FILTER ( " + filterRule + " ) . ";
} else {
filterClause = "";
}
String sparqlQuery = QueryConstants.getSparqlPrefixQuery()
+ "SELECT "
+ " (str(?predicate) as ?" + QueryFieldLabels.PREDICATE + ") "
+ " (str(?object) as ?" + QueryFieldLabels.OBJECT + ") "
+ "WHERE { "
+ "<" + queryURI + "> ?predicate ?object. "
+ filterClause
+ "}";
return sparqlQuery;
}
public GenericQueryMap getQueryResult()
throws MalformedQueryParametersException {
if (StringUtils.isNotBlank(this.individualURI)) {
/*
* To test for the validity of the URI submitted.
* */
IRIFactory iRIFactory = IRIFactory.jenaImplementation();
IRI iri = iRIFactory.create(this.individualURI);
if (iri.hasViolation(false)) {
String errorMsg = ((Violation) iri.violations(false).next()).getShortMessage();
log.error("Generic Query " + errorMsg);
throw new MalformedQueryParametersException(
"URI provided for an individual is malformed.");
}
} else {
throw new MalformedQueryParametersException("URI parameter is either null or empty.");
}
ResultSet resultSet = executeQuery(generateGenericSparqlQuery(
this.individualURI,
this.filterRule),
this.dataset);
return createJavaValueObjects(resultSet);
}
}
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.visutils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.iri.IRI;
import com.hp.hpl.jena.iri.IRIFactory;
import com.hp.hpl.jena.iri.Violation;
import com.hp.hpl.jena.query.Dataset;
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.ResultSet;
import com.hp.hpl.jena.query.Syntax;
import com.hp.hpl.jena.rdf.model.RDFNode;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryFieldLabels;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.GenericQueryMap;
/**
* This query runner is used to execute a sparql query that will fetch all the
* properties available for the provided individual URI.
*
* @author cdtank
*/
public class AllPropertiesQueryRunner implements QueryRunner<GenericQueryMap> {
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private String filterRule, individualURI;
private Dataset dataset;
private Log log = LogFactory.getLog(AllPropertiesQueryRunner.class.getName());
public AllPropertiesQueryRunner(String individualURI,
String filterRule,
Dataset dataset,
Log log) {
this.individualURI = individualURI;
this.filterRule = filterRule;
this.dataset = dataset;
this.log = log;
}
private GenericQueryMap createJavaValueObjects(ResultSet resultSet) {
GenericQueryMap queryResult = new GenericQueryMap();
while (resultSet.hasNext()) {
QuerySolution solution = resultSet.nextSolution();
RDFNode predicateNode = solution.get(QueryFieldLabels.PREDICATE);
RDFNode objectNode = solution.get(QueryFieldLabels.OBJECT);
if (predicateNode != null && objectNode != null) {
queryResult.addEntry(predicateNode.toString(),
objectNode.toString());
}
}
return queryResult;
}
private ResultSet executeQuery(String queryText,
Dataset dataset) {
QueryExecution queryExecution = null;
Query query = QueryFactory.create(queryText, SYNTAX);
queryExecution = QueryExecutionFactory.create(query, dataset);
return queryExecution.execSelect();
}
private String generateGenericSparqlQuery(String queryURI, String filterRule) {
// Resource uri1 = ResourceFactory.createResource(queryURI);
String filterClause;
if (StringUtils.isNotBlank(filterRule)) {
filterClause = "FILTER ( " + filterRule + " ) . ";
} else {
filterClause = "";
}
String sparqlQuery = QueryConstants.getSparqlPrefixQuery()
+ "SELECT "
+ " (str(?predicate) as ?" + QueryFieldLabels.PREDICATE + ") "
+ " (str(?object) as ?" + QueryFieldLabels.OBJECT + ") "
+ "WHERE { "
+ "<" + queryURI + "> ?predicate ?object. "
+ filterClause
+ "}";
log.debug("sparqlQuery = " + sparqlQuery.toString());
return sparqlQuery;
}
public GenericQueryMap getQueryResult()
throws MalformedQueryParametersException {
if (StringUtils.isNotBlank(this.individualURI)) {
/*
* To test for the validity of the URI submitted.
* */
IRIFactory iRIFactory = IRIFactory.jenaImplementation();
IRI iri = iRIFactory.create(this.individualURI);
if (iri.hasViolation(false)) {
String errorMsg = ((Violation) iri.violations(false).next()).getShortMessage();
log.error("Generic Query " + errorMsg);
throw new MalformedQueryParametersException(
"URI provided for an individual is malformed.");
}
} else {
throw new MalformedQueryParametersException("URI parameter is either null or empty.");
}
ResultSet resultSet = executeQuery(generateGenericSparqlQuery(
this.individualURI,
this.filterRule),
this.dataset);
return createJavaValueObjects(resultSet);
}
}

View file

@ -1,98 +1,104 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.visutils;
import java.util.Map;
import com.hp.hpl.jena.query.Dataset;
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.ResultSet;
import com.hp.hpl.jena.query.Syntax;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
/**
* This query runner is used to run a generic sparql query based on the "select",
* "where" & "filter" rules provided to it.
*
* @author cdtank
*/
public class GenericQueryRunner implements QueryRunner<ResultSet> {
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private String whereClause;
private Dataset dataset;
private Map<String, String> fieldLabelToOutputFieldLabel;
private String groupOrderClause;
private String aggregationRules;
public GenericQueryRunner(Map<String, String> fieldLabelToOutputFieldLabel,
String aggregationRules,
String whereClause,
String groupOrderClause,
Dataset dataset) {
this.fieldLabelToOutputFieldLabel = fieldLabelToOutputFieldLabel;
this.aggregationRules = aggregationRules;
this.whereClause = whereClause;
this.groupOrderClause = groupOrderClause;
this.dataset = dataset;
}
private ResultSet executeQuery(String queryText,
Dataset dataset) {
QueryExecution queryExecution = null;
Query query = QueryFactory.create(queryText, SYNTAX);
queryExecution = QueryExecutionFactory.create(query, dataset);
return queryExecution.execSelect();
}
private String generateGenericSparqlQuery() {
StringBuilder sparqlQuery = new StringBuilder();
sparqlQuery.append(QueryConstants.getSparqlPrefixQuery());
sparqlQuery.append("SELECT\n");
for (Map.Entry<String, String> currentfieldLabelToOutputFieldLabel
: this.fieldLabelToOutputFieldLabel.entrySet()) {
sparqlQuery.append("\t(str(?" + currentfieldLabelToOutputFieldLabel.getKey() + ") as ?"
+ currentfieldLabelToOutputFieldLabel.getValue() + ")\n");
}
sparqlQuery.append("\n" + this.aggregationRules + "\n");
sparqlQuery.append("WHERE {\n");
sparqlQuery.append(this.whereClause);
sparqlQuery.append("}\n");
sparqlQuery.append(this.groupOrderClause);
return sparqlQuery.toString();
}
public ResultSet getQueryResult()
throws MalformedQueryParametersException {
ResultSet resultSet = executeQuery(generateGenericSparqlQuery(),
this.dataset);
return resultSet;
}
}
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.visutils;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.query.Dataset;
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.ResultSet;
import com.hp.hpl.jena.query.Syntax;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
/**
* This query runner is used to run a generic sparql query based on the "select",
* "where" & "filter" rules provided to it.
*
* @author cdtank
*/
public class GenericQueryRunner implements QueryRunner<ResultSet> {
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private String whereClause;
private Dataset dataset;
private Map<String, String> fieldLabelToOutputFieldLabel;
private Log log = LogFactory.getLog(GenericQueryRunner.class.getName());
private String groupOrderClause;
private String aggregationRules;
public GenericQueryRunner(Map<String, String> fieldLabelToOutputFieldLabel,
String aggregationRules,
String whereClause,
String groupOrderClause,
Dataset dataset) {
this.fieldLabelToOutputFieldLabel = fieldLabelToOutputFieldLabel;
this.aggregationRules = aggregationRules;
this.whereClause = whereClause;
this.groupOrderClause = groupOrderClause;
this.dataset = dataset;
}
private ResultSet executeQuery(String queryText,
Dataset dataset) {
QueryExecution queryExecution = null;
Query query = QueryFactory.create(queryText, SYNTAX);
queryExecution = QueryExecutionFactory.create(query, dataset);
return queryExecution.execSelect();
}
private String generateGenericSparqlQuery() {
StringBuilder sparqlQuery = new StringBuilder();
sparqlQuery.append(QueryConstants.getSparqlPrefixQuery());
sparqlQuery.append("SELECT\n");
for (Map.Entry<String, String> currentfieldLabelToOutputFieldLabel
: this.fieldLabelToOutputFieldLabel.entrySet()) {
sparqlQuery.append("\t(str(?" + currentfieldLabelToOutputFieldLabel.getKey() + ") as ?"
+ currentfieldLabelToOutputFieldLabel.getValue() + ")\n");
}
sparqlQuery.append("\n" + this.aggregationRules + "\n");
sparqlQuery.append("WHERE {\n");
sparqlQuery.append(this.whereClause);
sparqlQuery.append("}\n");
sparqlQuery.append(this.groupOrderClause);
log.debug("sparqlQuery = " + sparqlQuery.toString());
return sparqlQuery.toString();
}
public ResultSet getQueryResult()
throws MalformedQueryParametersException {
ResultSet resultSet = executeQuery(generateGenericSparqlQuery(),
this.dataset);
return resultSet;
}
}

View file

@ -1,97 +1,103 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.visutils;
import java.util.Map;
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.ResultSet;
import com.hp.hpl.jena.query.Syntax;
import com.hp.hpl.jena.rdf.model.Model;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
/**
* This query runner is used to run a generic sparql query based on the "select",
* "where" & "filter" rules provided to it.
*
* @author cdtank
*/
public class GenericQueryRunnerOnModel implements QueryRunner<ResultSet> {
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private String whereClause;
private Model model;
private Map<String, String> fieldLabelToOutputFieldLabel;
private String groupOrderClause;
private String aggregationRules;
public GenericQueryRunnerOnModel(Map<String, String> fieldLabelToOutputFieldLabel,
String aggregationRules,
String whereClause,
String groupOrderClause,
Model model) {
this.fieldLabelToOutputFieldLabel = fieldLabelToOutputFieldLabel;
this.aggregationRules = aggregationRules;
this.whereClause = whereClause;
this.groupOrderClause = groupOrderClause;
this.model = model;
}
private ResultSet executeQuery(String queryText,
Model dataset) {
QueryExecution queryExecution = null;
Query query = QueryFactory.create(queryText, SYNTAX);
queryExecution = QueryExecutionFactory.create(query, dataset);
return queryExecution.execSelect();
}
private String generateGenericSparqlQuery() {
StringBuilder sparqlQuery = new StringBuilder();
sparqlQuery.append(QueryConstants.getSparqlPrefixQuery());
sparqlQuery.append("SELECT\n");
for (Map.Entry<String, String> currentfieldLabelToOutputFieldLabel
: this.fieldLabelToOutputFieldLabel.entrySet()) {
sparqlQuery.append("\t(str(?" + currentfieldLabelToOutputFieldLabel.getKey() + ") as ?"
+ currentfieldLabelToOutputFieldLabel.getValue() + ")\n");
}
sparqlQuery.append("\n" + this.aggregationRules + "\n");
sparqlQuery.append("WHERE {\n");
sparqlQuery.append(this.whereClause);
sparqlQuery.append("}\n");
sparqlQuery.append(this.groupOrderClause);
return sparqlQuery.toString();
}
public ResultSet getQueryResult()
throws MalformedQueryParametersException {
ResultSet resultSet = executeQuery(generateGenericSparqlQuery(),
this.model);
return resultSet;
}
}
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.visutils;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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.ResultSet;
import com.hp.hpl.jena.query.Syntax;
import com.hp.hpl.jena.rdf.model.Model;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
/**
* This query runner is used to run a generic sparql query based on the "select",
* "where" & "filter" rules provided to it.
*
* @author cdtank
*/
public class GenericQueryRunnerOnModel implements QueryRunner<ResultSet> {
protected static final Syntax SYNTAX = Syntax.syntaxARQ;
private String whereClause;
private Model model;
private Map<String, String> fieldLabelToOutputFieldLabel;
private Log log = LogFactory.getLog(GenericQueryRunnerOnModel.class.getName());
private String groupOrderClause;
private String aggregationRules;
public GenericQueryRunnerOnModel(Map<String, String> fieldLabelToOutputFieldLabel,
String aggregationRules,
String whereClause,
String groupOrderClause,
Model model) {
this.fieldLabelToOutputFieldLabel = fieldLabelToOutputFieldLabel;
this.aggregationRules = aggregationRules;
this.whereClause = whereClause;
this.groupOrderClause = groupOrderClause;
this.model = model;
}
private ResultSet executeQuery(String queryText,
Model dataset) {
QueryExecution queryExecution = null;
Query query = QueryFactory.create(queryText, SYNTAX);
queryExecution = QueryExecutionFactory.create(query, dataset);
return queryExecution.execSelect();
}
private String generateGenericSparqlQuery() {
StringBuilder sparqlQuery = new StringBuilder();
sparqlQuery.append(QueryConstants.getSparqlPrefixQuery());
sparqlQuery.append("SELECT\n");
for (Map.Entry<String, String> currentfieldLabelToOutputFieldLabel
: this.fieldLabelToOutputFieldLabel.entrySet()) {
sparqlQuery.append("\t(str(?" + currentfieldLabelToOutputFieldLabel.getKey() + ") as ?"
+ currentfieldLabelToOutputFieldLabel.getValue() + ")\n");
}
sparqlQuery.append("\n" + this.aggregationRules + "\n");
sparqlQuery.append("WHERE {\n");
sparqlQuery.append(this.whereClause);
sparqlQuery.append("}\n");
sparqlQuery.append(this.groupOrderClause);
log.debug("sparqlQuery = " + sparqlQuery.toString());
return sparqlQuery.toString();
}
public ResultSet getQueryResult()
throws MalformedQueryParametersException {
ResultSet resultSet = executeQuery(generateGenericSparqlQuery(),
this.model);
return resultSet;
}
}