Merge branch 'maint-rel-1.6' into develop

This commit is contained in:
brianjlowe 2013-11-07 12:29:33 -05:00
commit 9fa5dca9d5
189 changed files with 5659 additions and 2433 deletions

View file

@ -0,0 +1,83 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.ajax;
import java.io.IOException;
import java.lang.Integer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONException;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.RDFNode;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.ajax.VitroAjaxController;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
public class GeoFocusResearcherCount extends AbstractAjaxResponder {
private static final Log log = LogFactory.getLog(GeoFocusResearcherCount.class.getName());
private List<Map<String,String>> geoFocusCount;
private static String GEO_FOCUS_COUNT_QUERY = ""
+ "PREFIX core: <http://vivoweb.org/ontology/core#> \n"
+ "PREFIX foaf: <http://xmlns.com/foaf/0.1/> \n"
+ "SELECT DISTINCT (COUNT(DISTINCT ?person) AS ?count) \n"
+ "WHERE { \n"
+ " ?person a foaf:Person . \n"
+ " ?person core:geographicFocus ?focus \n"
+ "}" ;
public GeoFocusResearcherCount(HttpServlet parent, VitroRequest vreq,
HttpServletResponse resp) {
super(parent, vreq, resp);
}
@Override
public String prepareResponse() throws IOException, JSONException {
try {
geoFocusCount = getGeoFocusCount(vreq);
String response = "{ ";
for (Map<String, String> map: geoFocusCount) {
String theCount = map.get("count");
response += "\"count\": \"" + theCount + "\"";
}
response += " }";
log.debug(response);
return response;
} catch (Exception e) {
log.error("Failed geographic focus count", e);
return EMPTY_RESPONSE;
}
}
private List<Map<String,String>> getGeoFocusCount(VitroRequest vreq) {
String queryStr = GEO_FOCUS_COUNT_QUERY;
log.debug("queryStr = " + queryStr);
List<Map<String,String>> count = new ArrayList<Map<String,String>>();
try {
ResultSet results = QueryUtils.getQueryResults(queryStr, vreq);
while (results.hasNext()) {
QuerySolution soln = results.nextSolution();
count.add(QueryUtils.querySolutionToStringValueMap(soln));
}
} catch (Exception e) {
log.error(e, e);
}
return count;
}
}

View file

@ -1,42 +1,46 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.ajax;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.ajax.VitroAjaxController;
/**
* Handle the AJAX functions that are specific to the "new" home page sections, at
* this point just the mapping of geographic locations.
*/
public class HomePageAjaxController extends VitroAjaxController {
private static final Log log = LogFactory
.getLog(HomePageAjaxController.class);
private static final String PARAMETER_ACTION = "action";
@Override
protected void doRequest(VitroRequest vreq, HttpServletResponse resp)
throws ServletException, IOException {
try {
String function = vreq.getParameter(PARAMETER_ACTION);
if ("getGeoFocusLocations".equals(function)) {
new GeoFocusMapLocations(this, vreq, resp).processRequest();
} else {
resp.getWriter().write("[]");
}
} catch (Exception e) {
log.error(e, e);
resp.getWriter().write("[]");
}
}
}
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.ajax;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.ajax.VitroAjaxController;
/**
* Handle the AJAX functions that are specific to the "new" home page sections, at
* this point just the mapping of geographic locations.
*/
public class HomePageAjaxController extends VitroAjaxController {
private static final Log log = LogFactory
.getLog(HomePageAjaxController.class);
private static final String PARAMETER_ACTION = "action";
@Override
protected void doRequest(VitroRequest vreq, HttpServletResponse resp)
throws ServletException, IOException {
try {
String function = vreq.getParameter(PARAMETER_ACTION);
if ("getGeoFocusLocations".equals(function)) {
new GeoFocusMapLocations(this, vreq, resp).processRequest();
}
else if ("getGeoFocusResearcherCount".equals(function)) {
new GeoFocusResearcherCount(this, vreq, resp).processRequest();
}
else {
resp.getWriter().write("[]");
}
} catch (Exception e) {
log.error(e, e);
resp.getWriter().write("[]");
}
}
}

View file

@ -12,6 +12,9 @@ import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.vocabulary.XSD;
@ -31,17 +34,6 @@ Custom form for adding or editing a webpage associated with an individual. The p
ManageWebpagesForIndividual, should forward to this page if: (a) we are adding a new page, or
(b) an edit link in the Manage Webpages view has been clicked. But right now (a) is not implemented.
Object properties:
core:webpage (range: core:URLLink)
core:webpageOf (domain: core:URLLink) (inverse of core:webpage)
Class:
core:URLLink - the link to be added to the individual
Data properties of core:URLLink:
core:linkUrlPredicate
core:linkAnchorText
core:rank
*/
public class AddEditWebpageFormGenerator extends BaseEditConfigurationGenerator implements EditConfigurationGenerator {
@ -55,7 +47,7 @@ public class AddEditWebpageFormGenerator extends BaseEditConfigurationGenerator
prepare(vreq, config);
return config;
}
//Have broken this method down into two portions to allow for overriding of edit configuration
//without having to copy the entire method and before prepare is called
@ -69,6 +61,9 @@ public class AddEditWebpageFormGenerator extends BaseEditConfigurationGenerator
initPropertyParameters(vreq, session, config);
initObjectPropForm(config, vreq);
String linkUri = getLinkUri(vreq);
String domainUri = vreq.getParameter("domainUri");
String vcardIndividualType = "http://www.w3.org/2006/vcard/ns#Kind";
config.setVarNameForSubject("subject");
config.setVarNameForObject("vcard");
@ -84,11 +79,22 @@ public class AddEditWebpageFormGenerator extends BaseEditConfigurationGenerator
config.addUrisInScope("linkUrlPredicate", list( "http://www.w3.org/2006/vcard/ns#url" ));
config.addUrisInScope("linkLabelPredicate", list( "http://www.w3.org/2000/01/rdf-schema#label" ));
config.addUrisInScope("rankPredicate", list( core + "rank"));
config.addSparqlForAdditionalUrisInScope("vcard", individualVcardQuery);
config.addUrisInScope("vcardType", list( vcardIndividualType ));
if ( config.isUpdate() ) {
config.addUrisInScope("link", list( linkUri ));
}
else {
if ( domainUri.equals("http://xmlns.com/foaf/0.1/Person") ) {
vcardIndividualType = "http://www.w3.org/2006/vcard/ns#Individual";
}
else if ( domainUri.equals("http://xmlns.com/foaf/0.1/Organization") ) {
vcardIndividualType = "http://www.w3.org/2006/vcard/ns#Organization";
}
}
config.addSparqlForAdditionalUrisInScope("vcard", individualVcardQuery);
config.setUrisOnForm("urlType");
config.setLiteralsOnForm(list("url","label","rank"));
@ -140,6 +146,7 @@ public class AddEditWebpageFormGenerator extends BaseEditConfigurationGenerator
static String N3_FOR_WEBPAGE =
"?subject ?webpageProperty ?vcard . \n"+
"?vcard ?inverseProperty ?subject . \n"+
"?vcard a ?vcardType . \n" +
"?vcard <http://www.w3.org/2006/vcard/ns#hasURL> ?link ."+
"?link a <http://www.w3.org/2006/vcard/ns#URL> . \n" +
"?link ?linkUrlPredicate ?url .";

View file

@ -39,12 +39,6 @@ import edu.cornell.mannlib.vitro.webapp.utils.generators.EditModeUtils;
* Custom form for adding a grant to an person for the predicates hasCo-PrincipalInvestigatorRole
and hasPrincipalInvestigatorRole.
This is intended to create a set of statements like:
?person core:hasPrincipalInvestigatorRole ?newRole.
?newRole rdf:type core:PrincipalInvestigatorRole ;
core:relatedRole ?someGrant .
*
*/
public class AddGrantRoleToPersonGenerator implements EditConfigurationGenerator {
@ -277,8 +271,7 @@ public class AddGrantRoleToPersonGenerator implements EditConfigurationGenerator
urisInScope.put("roleType",
Arrays.asList(new String[]{getRoleType(vreq)}));
//Setting inverse role predicate
urisInScope.put("inverseRolePredicate", getInversePredicate(vreq));
urisInScope.put("inverseRolePredicate", getInversePredicate(vreq));
editConfiguration.setUrisInScope(urisInScope);
//Uris in scope include subject, predicate, and object var
//literals in scope empty initially, usually populated by code in prepare for update
@ -664,12 +657,12 @@ public class AddGrantRoleToPersonGenerator implements EditConfigurationGenerator
//Some values will have a default value
//grantToRolePredicate
public String getDefaultgrantToRolePredicate() {
return "http://vivoweb.org/ontology/core#relatedRole";
return "http://vivoweb.org/ontology/core#relates";
}
//roleToGrantPredicate
public String getDefaultroleToGrantPredicate() {
return "http://vivoweb.org/ontology/core#roleIn";
return "http://purl.obolibrary.org/obo/BFO_0000054";
}

View file

@ -351,28 +351,28 @@ public class AddPublicationToPersonGenerator extends VivoBaseGenerator implement
return "@prefix vivo: <" + vivoCore + "> . \n" +
"?pubUri <" + presentedAtPred + "> ?newConference . \n" +
"?newConference a <" + conferenceClass + "> . \n" +
"?newConference vivo:includesEvent ?pubUri . \n" +
"?newConference <http://purl.obolibrary.org/obo/BFO_0000051> ?pubUri . \n" +
"?newConference <" + label + "> ?conference .";
}
private String getN3ForConference() {
return "@prefix vivo: <" + vivoCore + "> . \n" +
"?pubUri <" + presentedAtPred + "> ?conferenceUri . \n" +
"?conferenceUri vivo:includesEvent ?pubUri . ";
"?conferenceUri <http://purl.obolibrary.org/obo/BFO_0000051> ?pubUri . ";
}
private String getN3ForNewConferenceNewPub() {
return "@prefix vivo: <" + vivoCore + "> . \n" +
"?newPublication <" + presentedAtPred + "> ?newConference . \n" +
"?newConference a <" + conferenceClass + "> . \n" +
"?newConference vivo:includesEvent ?newPublication . \n" +
"?newConference <http://purl.obolibrary.org/obo/BFO_0000051> ?newPublication . \n" +
"?newConference <" + label + "> ?conference .";
}
private String getN3ForConferenceNewPub() {
return "@prefix vivo: <" + vivoCore + "> . \n" +
"?newPublication <" + presentedAtPred + "> ?conferenceUri . \n" +
"?conferenceUri vivo:includesEvent ?newPublication . ";
"?conferenceUri <http://purl.obolibrary.org/obo/BFO_0000051> ?newPublication . ";
}
private String getN3ForNewEvent() {
@ -911,7 +911,7 @@ public class AddPublicationToPersonGenerator extends VivoBaseGenerator implement
literalOptions.add(list("http://purl.org/ontology/bibo/Report", "Report"));
literalOptions.add(list("http://vivoweb.org/ontology/core#ResearchProposal", "Research Proposal"));
literalOptions.add(list("http://vivoweb.org/ontology/core#Review", "Review"));
literalOptions.add(list("http://vivoweb.org/ontology/core#Software", "Software"));
literalOptions.add(list("http://purl.obolibrary.org/obo/ERO_0000071 ", "Software"));
literalOptions.add(list("http://vivoweb.org/ontology/core#Speech", "Speech"));
literalOptions.add(list("http://purl.org/ontology/bibo/Thesis", "Thesis"));
literalOptions.add(list("http://vivoweb.org/ontology/core#Video", "Video"));
@ -941,7 +941,7 @@ public class AddPublicationToPersonGenerator extends VivoBaseGenerator implement
}
public EditMode getEditMode(VitroRequest vreq) {
return EditModeUtils.getEditMode(vreq, list("http://vivoweb.org/ontology/core#linkedInformationResource"));
return EditModeUtils.getEditMode(vreq, list("http://vivoweb.org/ontology/core#relates"));
}
}

View file

@ -0,0 +1,388 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpSession;
import com.hp.hpl.jena.vocabulary.XSD;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeIntervalValidationVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeWithPrecisionVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.ChildVClassesOptions;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.ChildVClassesWithParent;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.IndividualsViaVClassOptions;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation;
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils.EditMode;
import edu.cornell.mannlib.vitro.webapp.utils.generators.EditModeUtils;
public class OrganizationForTrainingGenerator extends VivoBaseGenerator implements EditConfigurationGenerator{
//TODO: can we get rid of the session and get it form the vreq?
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, HttpSession session) throws Exception {
EditConfigurationVTwo conf = new EditConfigurationVTwo();
initBasics(conf, vreq);
initPropertyParameters(vreq, session, conf);
initObjectPropForm(conf, vreq);
conf.setTemplate("organizationForTraining.ftl");
conf.setVarNameForSubject("organization");
conf.setVarNameForPredicate("predicate");
conf.setVarNameForObject("edTraining");
conf.setN3Required( Arrays.asList( n3ForNewEdTraining, trainingTypeAssertion ) );
conf.setN3Optional(Arrays.asList( majorFieldAssertion, n3ForAwardedDegree, n3ForNewPerson, n3ForExistingPerson,
n3ForNewPersonAwardedDegree, n3ForExistingPersonAwardedDegree, deptAssertion, infoAssertion, n3ForStart,
n3ForEnd, firstNameAssertion, lastNameAssertion ));
conf.addNewResource("edTraining", DEFAULT_NS_FOR_NEW_RESOURCE);
conf.addNewResource("awardedDegree",DEFAULT_NS_FOR_NEW_RESOURCE);
conf.addNewResource("newPerson",DEFAULT_NS_FOR_NEW_RESOURCE);
conf.addNewResource("intervalNode",DEFAULT_NS_FOR_NEW_RESOURCE);
conf.addNewResource("startNode",DEFAULT_NS_FOR_NEW_RESOURCE);
conf.addNewResource("endNode",DEFAULT_NS_FOR_NEW_RESOURCE);
conf.addNewResource("vcardPerson", DEFAULT_NS_FOR_NEW_RESOURCE);
conf.addNewResource("vcardName", DEFAULT_NS_FOR_NEW_RESOURCE);
//uris in scope: none
//literals in scope: none
conf.setUrisOnform( Arrays.asList( "existingPerson", "degreeType", "trainingType"));
conf.setLiteralsOnForm( Arrays.asList("personLabel", "personLabelDisplay", "awardedDegreeLabel",
"majorField", "dept", "info", "firstName", "lastName"));
conf.addSparqlForExistingLiteral("personLabel", personLabelQuery);
conf.addSparqlForExistingLiteral("majorField", majorFieldQuery);
conf.addSparqlForExistingLiteral("dept", deptQuery);
conf.addSparqlForExistingLiteral("info", infoQuery);
conf.addSparqlForExistingLiteral("startField-value", existingStartDateQuery);
conf.addSparqlForExistingLiteral("endField-value", existingEndDateQuery);
conf.addSparqlForExistingUris("awardedDegree", existingAwardedDegreeQuery);
conf.addSparqlForExistingUris("existingPerson", existingPersonQuery);
conf.addSparqlForExistingUris("trainingType", trainingTypeQuery);
conf.addSparqlForExistingUris("degreeType", degreeTypeQuery);
conf.addSparqlForExistingUris("intervalNode",existingIntervalNodeQuery);
conf.addSparqlForExistingUris("startNode", existingStartNodeQuery);
conf.addSparqlForExistingUris("endNode", existingEndNodeQuery);
conf.addSparqlForExistingUris("startField-precision", existingStartPrecisionQuery);
conf.addSparqlForExistingUris("endField-precision", existingEndPrecisionQuery);
//Add sparql to include inverse property as well
conf.addSparqlForAdditionalUrisInScope("inverseTrainingAtPerson", inverseTrainingAtPersonQuery);
conf.addField( new FieldVTwo().
setName("degreeType").
setOptions( new IndividualsViaVClassOptions(
degreeTypeClass)));
conf.addField( new FieldVTwo().
setName("majorField").
setRangeDatatypeUri( XSD.xstring.toString() ).
setValidators(list("datatype:" + XSD.xstring.toString())));
conf.addField( new FieldVTwo().
setName("existingPerson")
//options will be added in browser by auto complete JS
);
conf.addField( new FieldVTwo().
setName("awardedDegree")
//options will be added in browser by auto complete JS
);
conf.addField( new FieldVTwo().
setName("personLabel").
setRangeDatatypeUri(XSD.xstring.toString() ).
setValidators( list("datatype:" + XSD.xstring.toString())));
conf.addField( new FieldVTwo().
setName("awardedDegreeLabel").
setRangeDatatypeUri(XSD.xstring.toString() ).
setValidators( list("datatype:" + XSD.xstring.toString())));
conf.addField( new FieldVTwo().
setName("existingAwardedDegreeLabel").
setRangeDatatypeUri(XSD.xstring.toString() ).
setValidators( list("datatype:" + XSD.xstring.toString())));
conf.addField( new FieldVTwo().
setName("personLabelDisplay").
setRangeDatatypeUri(XSD.xstring.toString() ));
conf.addField( new FieldVTwo().
setName("firstName").
setRangeDatatypeUri(XSD.xstring.toString() ).
setValidators( list("datatype:" + XSD.xstring.toString()) )
);
conf.addField( new FieldVTwo().
setName("lastName").
setRangeDatatypeUri(XSD.xstring.toString() ).
setValidators( list("datatype:" + XSD.xstring.toString()) )
);
conf.addField( new FieldVTwo().
setName("trainingType").
setValidators( list("nonempty") ).
setOptions(
new ChildVClassesWithParent(edProcessClass)));
conf.addField( new FieldVTwo().
setName("dept").
setRangeDatatypeUri( XSD.xstring.toString() ).
setValidators(list("datatype:" + XSD.xstring.toString())));
conf.addField( new FieldVTwo().
setName("info").
setRangeDatatypeUri( XSD.xstring.toString() ).
setValidators(list("datatype:" + XSD.xstring.toString())));
FieldVTwo startField = new FieldVTwo().
setName("startField");
conf.addField(startField.
setEditElement(
new DateTimeWithPrecisionVTwo(startField,
VitroVocabulary.Precision.YEAR.uri(),
VitroVocabulary.Precision.NONE.uri())));
FieldVTwo endField = new FieldVTwo().
setName("endField");
conf.addField( endField.
setEditElement(
new DateTimeWithPrecisionVTwo(endField,
VitroVocabulary.Precision.YEAR.uri(),
VitroVocabulary.Precision.NONE.uri())));
//Add validator
conf.addValidator(new DateTimeIntervalValidationVTwo("startField","endField"));
conf.addValidator(new AntiXssValidation());
//Adding additional data, specifically edit mode
addFormSpecificData(conf, vreq);
prepare(vreq, conf);
return conf;
}
/* N3 assertions for working with educational training */
final static String n3ForNewEdTraining =
"@prefix core: <"+ vivoCore +"> .\n"+
"?organization <http://purl.obolibrary.org/obo/RO_0000056> ?edTraining .\n" +
"?edTraining a core:EducationalProcess .\n" +
"?edTraining <http://purl.obolibrary.org/obo/RO_0000057> ?organization .";
final static String trainingTypeAssertion =
"?edTraining a ?trainingType .";
final static String n3ForAwardedDegree =
"@prefix core: <"+ vivoCore +"> .\n"+
"?edTraining <http://purl.obolibrary.org/obo/RO_0002234> ?awardedDegree . \n" +
"?awardedDegree <http://purl.obolibrary.org/obo/RO_0002353> ?edTraining . \n" +
"?awardedDegree <http://vivoweb.org/ontology/core#assignedBy> ?organization . \n" +
"?organization <http://vivoweb.org/ontology/core#assigns> ?awardedDegree . \n" +
"?awardedDegree <"+ label +"> ?awardedDegreeLabel . \n" +
"?awardedDegree <http://vivoweb.org/ontology/core#relates> ?degreeType .\n"+
"?degreeType <http://vivoweb.org/ontology/core#relatedBy> ?awardedDegree . \n"+
"?awardedDegree a core:AwardedDegree .";
final static String n3ForNewPerson =
"?edTraining <http://purl.obolibrary.org/obo/RO_0000057> ?newPerson . \n" +
"?newPerson <http://purl.obolibrary.org/obo/RO_0000056> ?edTraining . \n" +
"?newPerson a <http://xmlns.com/foaf/0.1/Person> . \n" +
"?newPerson <"+ label +"> ?personLabel . ";
final static String n3ForExistingPerson =
"?edTraining <http://purl.obolibrary.org/obo/RO_0000057> ?existingPerson . \n" +
"?existingPerson <http://purl.obolibrary.org/obo/RO_0000056> ?edTraining . \n" +
" ";
final static String n3ForNewPersonAwardedDegree =
"?awardedDegree <http://vivoweb.org/ontology/core#relates> ?newPerson . \n" +
"?newPerson <http://vivoweb.org/ontology/core#releatedBy> ?awardedDegree . \n" +
"?newPerson a <http://xmlns.com/foaf/0.1/Person> . \n" +
"?awardedDegree <"+ label +"> ?awardedDegreeLabel . \n" +
"?newPerson <"+ label +"> ?personLabel . ";
final static String firstNameAssertion =
"@prefix vcard: <http://www.w3.org/2006/vcard/ns#> . \n" +
"?newPerson <http://purl.obolibrary.org/obo/ARG_2000028> ?vcardPerson . \n" +
"?vcardPerson <http://purl.obolibrary.org/obo/ARG_2000029> ?newPerson . \n" +
"?vcardPerson a <http://www.w3.org/2006/vcard/ns#Individual> . \n" +
"?vcardPerson vcard:hasName ?vcardName . \n" +
"?vcardName a <http://www.w3.org/2006/vcard/ns#Name> . \n" +
"?vcardName vcard:givenName ?firstName .";
final static String lastNameAssertion =
"@prefix vcard: <http://www.w3.org/2006/vcard/ns#> . \n" +
"?newPerson <http://purl.obolibrary.org/obo/ARG_2000028> ?vcardPerson . \n" +
"?vcardPerson <http://purl.obolibrary.org/obo/ARG_2000029> ?newPerson . \n" +
"?vcardPerson a <http://www.w3.org/2006/vcard/ns#Individual> . \n" +
"?vcardPerson vcard:hasName ?vcardName . \n" +
"?vcardName a <http://www.w3.org/2006/vcard/ns#Name> . \n" +
"?vcardName vcard:familyName ?lastName .";
final static String n3ForExistingPersonAwardedDegree =
"?awardedDegree <http://vivoweb.org/ontology/core#relates> ?existingPerson . \n" +
"?existingPerson <http://vivoweb.org/ontology/core#relatedBy> ?awardedDegree . \n" +
"?awardedDegree <"+ label +"> ?awardedDegreeLabel . \n" +
"?existingPerson a <http://xmlns.com/foaf/0.1/Person> . ";
final static String majorFieldAssertion =
"?edTraining <"+ majorFieldPred +"> ?majorField .";
final static String n3ForStart =
"?edTraining <"+ toInterval +"> ?intervalNode .\n"+
"?intervalNode <"+ type +"> <"+ intervalType +"> .\n"+
"?intervalNode <"+ intervalToStart +"> ?startNode .\n"+
"?startNode <"+ type +"> <"+ dateTimeValueType +"> .\n"+
"?startNode <"+ dateTimeValue +"> ?startField-value .\n"+
"?startNode <"+ dateTimePrecision +"> ?startField-precision .";
final static String n3ForEnd =
"?edTraining <"+ toInterval +"> ?intervalNode . \n"+
"?intervalNode <"+ type +"> <"+ intervalType +"> .\n"+
"?intervalNode <"+ intervalToEnd +"> ?endNode .\n"+
"?endNode <"+ type +"> <"+ dateTimeValueType +"> .\n"+
"?endNode <"+ dateTimeValue +"> ?endField-value .\n"+
"?endNode <"+ dateTimePrecision +"> ?endField-precision .";
final static String deptAssertion =
"?edTraining <"+ deptPred +"> ?dept .";
final static String infoAssertion =
"?edTraining <"+ infoPred +"> ?info .";
/* Queries for editing an existing educational training entry */
final static String existingAwardedDegreeQuery =
"SELECT ?existingAwardedDegree WHERE {\n"+
"?edTraining <http://purl.obolibrary.org/obo/RO_0002234> ?existingAwardedDegree . }\n";
final static String existingAwardedDegreeLabelQuery =
"SELECT ?existingAwardedDegreeLabel WHERE {\n"+
"?edTraining <http://purl.obolibrary.org/obo/RO_0002234> ?existingAwardedDegree . \n" +
"?existingAwardedDegree <"+ label +"> ?existingAwardedDegreeLabel }\n";
final static String existingPersonQuery =
"PREFIX rdfs: <"+ rdfs +"> \n"+
"SELECT ?existingPerson WHERE {\n"+
"?edTraining <http://purl.obolibrary.org/obo/RO_0000057> ?existingPerson . \n" +
"?existingPerson <http://purl.obolibrary.org/obo/RO_0000056> ?edTraining . \n" +
"?existingPerson a <http://xmlns.com/foaf/0.1/Person> . \n " +
" }";
final static String personLabelQuery =
"PREFIX rdfs: <"+ rdfs +"> \n"+
"SELECT ?existingPersonLabel WHERE {\n"+
"?edTraining <http://purl.obolibrary.org/obo/RO_0000057> ?existingPerson . \n" +
"?existingPerson <http://purl.obolibrary.org/obo/RO_0000056> ?edTraining .\n"+
"?existingPerson <"+ label +"> ?existingPersonLabel .\n"+
"?existingPerson a <http://xmlns.com/foaf/0.1/Person> . \n " +
" }";
final static String trainingTypeQuery =
"PREFIX vitro: <" + VitroVocabulary.vitroURI + "> \n" +
"SELECT ?existingTrainingType WHERE { \n" +
" ?edTraining vitro:mostSpecificType ?existingTrainingType . }";
final static String degreeTypeQuery =
"PREFIX core: <"+ vivoCore +"> \n"+
"SELECT ?existingDegreeType WHERE {\n"+
"?edTraining <http://purl.obolibrary.org/obo/RO_0002234> ?existingAwardedDegree . \n"+
"?existingAwardedDegree a core:AwardedDegree . \n"+
"?existingAwardedDegree core:relates ?existingDegreeType . \n" +
"?existingDegreeType a core:AcademicDegree }";
final static String majorFieldQuery =
"SELECT ?existingMajorField WHERE {\n"+
"?edTraining <"+ majorFieldPred +"> ?existingMajorField . }";
final static String deptQuery =
"SELECT ?existingDept WHERE {\n"+
"?edTraining <"+ deptPred +"> ?existingDept . }";
final static String infoQuery =
"SELECT ?existingInfo WHERE {\n"+
"?edTraining <"+ infoPred +"> ?existingInfo . }";
final static String existingIntervalNodeQuery =
"SELECT ?existingIntervalNode WHERE {\n"+
"?edTraining <"+ toInterval +"> ?existingIntervalNode .\n"+
"?existingIntervalNode <"+ type +"> <"+ intervalType +"> . }";
final static String existingStartNodeQuery =
"SELECT ?existingStartNode WHERE {\n"+
"?edTraining <"+ toInterval +"> ?intervalNode .\n"+
"?intervalNode <"+ type +"> <"+ intervalType +"> .\n"+
"?intervalNode <"+ intervalToStart +"> ?existingStartNode . \n"+
"?existingStartNode <"+ type +"> <"+ dateTimeValueType +"> .}";
final static String existingStartDateQuery =
"SELECT ?existingDateStart WHERE {\n"+
"?edTraining <"+ toInterval +"> ?intervalNode .\n"+
"?intervalNode <"+ type +"> <"+ intervalType +"> .\n"+
"?intervalNode <"+ intervalToStart +"> ?startNode .\n"+
"?startNode <"+ type +"> <"+ dateTimeValueType +"> .\n"+
"?startNode <"+ dateTimeValue +"> ?existingDateStart . }";
final static String existingStartPrecisionQuery =
"SELECT ?existingStartPrecision WHERE {\n"+
"?edTraining <"+ toInterval +"> ?intervalNode .\n"+
"?intervalNode <"+ type +"> <"+ intervalType +"> .\n"+
"?intervalNode <"+ intervalToStart +"> ?startNode .\n"+
"?startNode <"+ type +"> <"+ dateTimeValueType +"> . \n"+
"?startNode <"+ dateTimePrecision +"> ?existingStartPrecision . }";
final static String existingEndNodeQuery =
"SELECT ?existingEndNode WHERE { \n"+
"?edTraining <"+ toInterval +"> ?intervalNode .\n"+
"?intervalNode <"+ type +"> <"+ intervalType +"> .\n"+
"?intervalNode <"+ intervalToEnd +"> ?existingEndNode . \n"+
"?existingEndNode <"+ type +"> <"+ dateTimeValueType +"> .}";
final static String existingEndDateQuery =
"SELECT ?existingEndDate WHERE {\n"+
"?edTraining <"+ toInterval +"> ?intervalNode .\n"+
"?intervalNode <"+ type +"> <"+ intervalType +"> .\n"+
"?intervalNode <"+ intervalToEnd +"> ?endNode .\n"+
"?endNode <"+ type +"> <"+ dateTimeValueType +"> .\n"+
"?endNode <"+ dateTimeValue +"> ?existingEndDate . }";
final static String existingEndPrecisionQuery =
"SELECT ?existingEndPrecision WHERE {\n"+
"?edTraining <"+ toInterval +"> ?intervalNode .\n"+
"?intervalNode <"+ type +"> <"+ intervalType +"> .\n"+
"?intervalNode <"+ intervalToEnd +"> ?endNode .\n"+
"?endNode <"+ type +"> <"+ dateTimeValueType +"> .\n"+
"?endNode <"+ dateTimePrecision +"> ?existingEndPrecision . }";
//Query for inverse property
final static String inverseTrainingAtPersonQuery =
"PREFIX owl: <http://www.w3.person/2002/07/owl#>"
+ " SELECT ?inverseTrainingAtPerson "
+ " WHERE { ?inverseTrainingAtPerson owl:inverseOf <http://vivoweb.org/ontology/core#relates> . } ";
//Adding form specific data such as edit mode
public void addFormSpecificData(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
HashMap<String, Object> formSpecificData = new HashMap<String, Object>();
formSpecificData.put("editMode", getEditMode(vreq).name().toLowerCase());
editConfiguration.setFormSpecificData(formSpecificData);
}
public EditMode getEditMode(VitroRequest vreq) {
List<String> predicates = new ArrayList<String>();
predicates.add("http://vivoweb.org/ontology/core#relates");
return EditModeUtils.getEditMode(vreq, predicates);
}
}

View file

@ -129,12 +129,22 @@ public class OrganizationHasPositionHistoryGenerator extends VivoBaseGenerator
+ "?person rdfs:label ?personLabel . ";
private static final String N3_NEW_FIRST_NAME = ""
+ "@prefix foaf: <http://xmlns.com/foaf/0.1/> . \n"
+ "?person foaf:firstName ?firstName .";
+ "@prefix vcard: <http://www.w3.org/2006/vcard/ns#> . \n"
+ "?person <http://purl.obolibrary.org/obo/ARG_2000028> ?vcardPerson . \n"
+ "?vcardPerson <http://purl.obolibrary.org/obo/ARG_2000029> ?person . \n"
+ "?vcardPerson a <http://www.w3.org/2006/vcard/ns#Individual> . \n"
+ "?vcardPerson vcard:hasName ?vcardName . \n"
+ "?vcardName a <http://www.w3.org/2006/vcard/ns#Name> . \n"
+ "?vcardName vcard:givenName ?firstName .";
private static final String N3_NEW_LAST_NAME = ""
+ "@prefix foaf: <http://xmlns.com/foaf/0.1/> . \n"
+ "?person foaf:lastName ?lastName .";
+ "@prefix vcard: <http://www.w3.org/2006/vcard/ns#> . \n"
+ "?person <http://purl.obolibrary.org/obo/ARG_2000028> ?vcardPerson . \n"
+ "?vcardPerson <http://purl.obolibrary.org/obo/ARG_2000029> ?person . \n"
+ "?vcardPerson a <http://www.w3.org/2006/vcard/ns#Individual> . \n"
+ "?vcardPerson vcard:hasName ?vcardName . \n"
+ "?vcardName a <http://www.w3.org/2006/vcard/ns#Name> . \n"
+ "?vcardName vcard:familyName ?lastName .";
private static final String N3_EXISTING_PERSON = ""
+ "@prefix core: <http://vivoweb.org/ontology/core#> . \n"
@ -179,6 +189,8 @@ public class OrganizationHasPositionHistoryGenerator extends VivoBaseGenerator
conf.addNewResource("position", DEFAULT_NS_FOR_NEW_RESOURCE);
conf.addNewResource("person", DEFAULT_NS_FOR_NEW_RESOURCE);
conf.addNewResource("vcardName", DEFAULT_NS_FOR_NEW_RESOURCE);
conf.addNewResource("vcardPerson", DEFAULT_NS_FOR_NEW_RESOURCE);
conf.addNewResource("intervalNode", DEFAULT_NS_FOR_NEW_RESOURCE);
conf.addNewResource("startNode", DEFAULT_NS_FOR_NEW_RESOURCE);
conf.addNewResource("endNode", DEFAULT_NS_FOR_NEW_RESOURCE);

View file

@ -27,46 +27,24 @@ import edu.cornell.mannlib.vitro.webapp.utils.generators.EditModeUtils;
Form for adding an educational attainment to an individual
Classes:
core:EducationalTraining - primary new individual being created
core:EducationalProcess - primary new individual being created
foaf:Person - existing individual
foaf:Organization - new or existing individual
core:AcademicdegreeType - existing individual
core:AcademicDegree - existing individual
core:AwardedDegree - new or existing individual
Data properties of EducationalTraining:
core:majorField
core:departmentOrSchool
core:supplementalInformation
Object properties (domain : range)
core:educationalTraining (Person : EducationalTraining) - inverse of core:educationalTrainingOf
core:educationalTrainingOf (EducationalTraining : Person) - inverse of core:educationalTraining
core:degreeTypeEarned (EducationalTraining : AcademicdegreeType) - inverse of core:degreeTypeOutcomeOf
core:degreeTypeOutcomeOf (AcademicdegreeType : EducationalTraining) - inverse of core:degreeTypeEarned
core:organizationGrantingdegreeType (EducationalTraining : Organization) - no inverse
Future version
--------------
Classes:
core:DateTimeValue
core:DateTimeValuePrecision
Object properties:
core:dateTimeValue (EducationalTraining : DateTimeValue)
core:dateTimePrecision (DateTimeValue : DateTimeValuePrecision)
There are 4 modes that this form can be in:
1. Add, there is a subject and a predicate but no position and nothing else.
2. normal edit where everything should already be filled out. There is a subject, a object and an individual on
the other end of the object's core:trainingAtOrganization stmt.
the other end of the object's relationship.
3. Repair a bad role node. There is a subject, prediate and object but there is no individual on the
other end of the object's core:trainingAtOrganization stmt. This should be similar to an add but the form should be expanded.
other end of the object's relationship. This should be similar to an add but the form should be expanded.
4. Really bad node. multiple core:trainingAtOrganization statements.
4. Really bad node. multiple statements on the other end of the object's relationship.
* @author bdc34
*

View file

@ -0,0 +1,789 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.search.indexing;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.ontology.OntModel;
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.QuerySolutionMap;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.Syntax;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.shared.Lock;
import edu.cornell.mannlib.vitro.webapp.search.beans.StatementToURIsToUpdate;
public class AdditionalURIsForContextNodes implements StatementToURIsToUpdate {
private OntModel model;
private Set<String> alreadyChecked;
private long accumulatedTime = 0;
private static final List<String> multiValuedQueriesForAgent = new ArrayList<String>();
private static final String multiValuedQueryForInformationContentEntity;
private static final List<String> multiValuedQueriesForRole = new ArrayList<String>();
private static final List<String>queryList;
private Log log = LogFactory.getLog(AdditionalURIsForContextNodes.class);
public AdditionalURIsForContextNodes( OntModel jenaOntModel){
this.model = jenaOntModel;
}
@Override
public List<String> findAdditionalURIsToIndex(Statement stmt) {
if( stmt != null ){
long start = System.currentTimeMillis();
List<String>urisToIndex = new ArrayList<String>();
if(stmt.getSubject() != null && stmt.getSubject().isURIResource() ){
String subjUri = stmt.getSubject().getURI();
if( subjUri != null && ! alreadyChecked.contains( subjUri )){
urisToIndex.addAll( findAdditionalURIsToIndex(subjUri));
alreadyChecked.add(subjUri);
}
}
if( stmt.getObject() != null && stmt.getObject().isURIResource() ){
String objUri = stmt.getSubject().getURI();
if( objUri != null && ! alreadyChecked.contains(objUri)){
urisToIndex.addAll( findAdditionalURIsToIndex(objUri));
alreadyChecked.add(objUri);
}
}
accumulatedTime += (System.currentTimeMillis() - start ) ;
return urisToIndex;
}else{
return Collections.emptyList();
}
}
@Override
public void startIndexing() {
alreadyChecked = new HashSet<String>();
accumulatedTime = 0L;
}
@Override
public void endIndxing() {
log.debug( "Accumulated time for this run of the index: " + accumulatedTime + " msec");
alreadyChecked = null;
}
protected List<String> findAdditionalURIsToIndex(String uri) {
List<String> uriList = new ArrayList<String>();
for(String query : queryList){
//log.info("Executing query: "+ query);
QuerySolutionMap initialBinding = new QuerySolutionMap();
Resource uriResource = ResourceFactory.createResource(uri);
initialBinding.add("uri", uriResource);
Query sparqlQuery = QueryFactory.create( query, Syntax.syntaxARQ);
model.getLock().enterCriticalSection(Lock.READ);
try{
QueryExecution qExec = QueryExecutionFactory.create(sparqlQuery, model, initialBinding);
try{
ResultSet results = qExec.execSelect();
while(results.hasNext()){
QuerySolution soln = results.nextSolution();
Iterator<String> iter = soln.varNames() ;
while( iter.hasNext()){
String name = iter.next();
RDFNode node = soln.get( name );
if( node != null ){
uriList.add("" + node.toString());
}else{
log.debug(name + " is null");
}
}
}
}catch(Throwable t){
log.error(t,t);
} finally{
qExec.close();
}
}finally{
model.getLock().leaveCriticalSection();
}
}
if( log.isDebugEnabled() )
log.debug( "additional uris for " + uri + " are " + uriList);
return uriList;
}
private static final String prefix = "prefix owl: <http://www.w3.org/2002/07/owl#> \n"
+ " prefix vitroDisplay: <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#> \n"
+ " prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n"
+ " prefix core: <http://vivoweb.org/ontology/core#> \n"
+ " prefix foaf: <http://xmlns.com/foaf/0.1/> \n"
+ " prefix obo: <http://purl.obolibrary.org/obo/> \n"
+ " prefix vcard: <http://www.w3.org/2006/vcard/ns#> \n"
+ " prefix event: <http://purl.org/NET/c4dm/event.owl#> \n"
+ " prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
+ " prefix localNav: <http://vitro.mannlib.cornell.edu/ns/localnav#> \n"
+ " prefix bibo: <http://purl.org/ontology/bibo/> \n";
static{
// If a person changes then update
// organizations for positions
multiValuedQueriesForAgent.add(prefix +
"SELECT DISTINCT \n" +
" (str(?i) as ?positionInOrganization) \n" +
" WHERE {\n"
+ "?uri rdf:type foaf:Agent ; core:relatedBy ?c . \n"
+ " ?c rdf:type core:Position . \n"
+ " OPTIONAL { ?c core:relates ?i . ?i rdf:type foaf:Organization } . \n"
+ " }");
// If a person changes then update
// advisee, linkedAuthor and informationResource
multiValuedQueriesForAgent.add(prefix +
"SELECT (str(?d) as ?advisee) \n" +
" (str(?f) as ?linkedAuthor) (str(?h) as ?linkedInformationResource) WHERE { {\n"
+ "?uri rdf:type foaf:Agent . \n"
+ "?uri core:relatedBy ?c . \n"
+ "?c rdf:type core:AdvisingRelationship . \n"
+ "?c core:relates ?d . \n"
+ "?d rdf:type core:AdviseeRole . \n"
+ "?d obo:RO_0000052 ?e . \n"
+ "?e rdf:type foaf:Person . \n"
+ "} \n"
+ "UNION { \n"
+ " ?uri rdf:type foaf:Agent . \n"
+ " ?uri core:relatedBy ?c . \n"
+ " ?c rdf:type core:Authorship . \n"
+ " OPTIONAL {?c core:relates ?f . \n"
+ " ?f rdf:type foaf:Person . } \n"
+ " OPTIONAL { ?c core:relates ?h . \n"
+ " ?h rdf:type obo:IAO_0000030 . } \n"
+ " } } ");
// If a person changes then update
// award giver
multiValuedQueriesForAgent.add(prefix +
"SELECT (str(?d) as ?awardConferredBy) \n" +
"WHERE {\n"
+ "?uri rdf:type foaf:Agent ; ?b ?c . \n"
+ " ?c rdf:type core:AwardReceipt . \n"
+ " OPTIONAL { ?c core:assignedBy ?d . } . \n"
+ " }");
// If a person changes then update
// organization for role
multiValuedQueriesForAgent.add(prefix +
"SELECT (str(?Organization) as ?organization) \n" +
"WHERE {\n"
+ "?uri rdf:type foaf:Agent ; ?b ?c . \n"
+ " ?c rdf:type obo:BFO_0000023 ; obo:BFO_0000054 ?Organization .\n"
+ " }");
// If a person changes then update
// organization in educational training
multiValuedQueriesForAgent.add(prefix +
"SELECT \n" +
"(str(?e) as ?trainingAtOrganization) WHERE {\n"
+ " ?uri rdf:type foaf:Agent ; ?b ?c . \n"
+ " ?c rdf:type core:EducationalProcess . \n"
+ " OPTIONAL { ?c obo:RO_0000057 ?e . \n"
+ " ?e rdf:type foaf:Organization . } . "
+"}");
// If an organization changes then update
// people in head of relations
multiValuedQueriesForAgent.add(
" # for organization, get leader \n" +
prefix +
"SELECT \n" +
"(str(?e) as ?LeaderPerson ) WHERE {\n"
+ " ?uri rdf:type foaf:Agent . \n"
+ " ?uri core:contributingRole ?c . \n"
+ " ?c rdf:type core:LeaderRole . \n"
+ " OPTIONAL { ?c obo:RO_0000052 ?e . \n"
+ " ?e rdf:type foaf:Person . } . "
+"}");
}
//multivalued query for obo:IAO_0000030 (Information Content Entity)
static {
multiValuedQueryForInformationContentEntity = prefix +
"SELECT (str(?b) as ?linkedAuthor) (str(?d) as ?linkedInformationResource) \n"
+ "(str(?f) as ?editor) \n" +
"(str(?i) as ?features) WHERE {\n"
+ " ?uri rdf:type obo:IAO_0000030 . \n"
+ " OPTIONAL { ?uri core:relatedBy ?a . \n"
+ " ?a rdf:type core:Authorship . \n"
+ " ?a core:relates ?b . ?b rdf:type foaf:Person .\n"
+ " ?a core:relates ?d . ?d rdf:type obo:IAO_0000030 .\n"
+ "} . "
+ " OPTIONAL { ?uri core:relatedBy ?e . \n"
+ " ?e rdf:type core:Editorship . \n"
+ " ?e core:relates ?f . ?f rdf:type foaf:Person .\n"
+ "} . "
+ " OPTIONAL { ?uri core:features ?i . } . \n"
+"}" ;
}
protected static List<String> queriesForAuthorship(){
List<String> queries = new ArrayList<String>();
//get additional URIs of information resources from author side
queries.add(
prefix
+ "SELECT (str(?a) as ?infoResource) WHERE {\n"
+ " ?uri rdf:type foaf:Person . \n"
+ " ?uri core:relatedBy ?aship .\n"
+ " ?aship rdf:type core:Authorship .\n"
+ "OPTIONAL { ?aship core:relates ?a . ?a rdf:type obo:IAO_0000030 } .\n"
+"}" );
//get additional URIs of authors from information resource side
queries.add(
prefix
+ "SELECT (str(?a) as ?author ) WHERE {\n"
+ " ?uri rdf:type obo:IAO_0000030 . \n"
+ " ?uri core:relatedBy ?aship . ?aship rdf:type core:Authorship . \n"
+ "OPTIONAL { ?aship core:relates ?a . ?a rdf:type foaf:Person } .\n"
+"}" );
return queries;
}
protected static List<String> queriesForURLLink(){
List<String> queries = new ArrayList<String>();
//get additional URIs when URLLink is changed
queries.add(
prefix
+ "SELECT (str(?x) as ?individual) WHERE {\n"
+ " ?i rdf:type vcard:Individual . \n"
+ " ?i vcard:hasURL ?uri . \n"
+ " ?i obo:ARG_2000029 ?x . \n"
+"}" );
return queries;
}
protected static List<String> queriesForEducationalTraining(){
List<String> queries = new ArrayList<String>();
//if person changes, no additional URIs need to be
//changed because the person is not displayed on the
//degree individual or on the degree granting organization
//if the degree changes, the person needs to be updated
//since the degree name is shown on the person page.
queries.add(
prefix
+ " SELECT (str(?person) as ?personUri) WHERE {\n"
+ " ?uri rdf:type core:AcademicDegree . \n"
+ " ?uri core:relatedBy ?awardedDegree .\n"
+ " ?awardedDegree rdf:type core:AwardedDegree .\n"
+ " ?awardedDegree core:relates ?person .\n"
+ " ?person rdf:type foaf:Person .\n"
+"}" );
//if the organization changes the person needs to be updated
//since the organization name is shown on the person page.
queries.add(
prefix
+ " SELECT (str(?person) as ?personUri) WHERE {\n"
+ " ?uri rdf:type foaf:Organization . \n"
+ " ?uri obo:RO_0000056 ?edTrainingNode .\n"
+ " ?edTrainingNode rdf:type core:EducationalProcess . \n"
+ " ?edTrainingNode obo:RO_0000057 ?person . \n"
+ " ?person rdf:type foaf:Person ."
+"}" );
return queries;
}
protected static List<String> queriesForPosition(){
List<String> queries = new ArrayList<String>();
//If an organization changes, update people
queries.add(
prefix
+ " SELECT (str(?person) as ?personUri) WHERE {\n"
+ " ?uri rdf:type foaf:Organization . \n"
+ " ?uri core:relatedBy ?positionNode .\n"
+ " ?positionNode rdf:type core:Position .\n"
+ " ?positionNode core:relates ?person . \n"
+ " ?person rdf:type foaf:Person .\n"
+"}" );
//if people change, update organizations
queries.add(
prefix
+ " SELECT (str(?org) as ?orgUri) WHERE {\n"
+ " ?uri rdf:type foaf:Person . \n"
+ " ?uri core:relatedBy ?positionNode .\n"
+ " ?positionNode rdf:type core:Position .\n"
+ " ?positionNode core:relates ?org . \n"
+ " ?org rdf:type foaf:Organization .\n"
+"}" );
return queries;
}
static{
// core:AttendeeRole
// If the person changes, update the attendee role in organization
// core:AttendeeRole applies to events, not organizations; updating accordingly - tlw72
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?event) \n " +
"WHERE {\n"
+ "?uri rdf:type foaf:Person . \n"
+ "?uri obo:RO_0000053 ?c . \n"
+ "?c rdf:type core:AttendeeRole . \n"
+ "?c obo:BFO_0000054 ?d . \n"
+ "?d rdf:type event:Event .\n"
+ " }");
// If the organization changes, update the attendee role of person
// core:AttendeeRole applies to events, not organizations; updating accordingly - tlw72
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?person) \n" +
"WHERE {\n"
+ "?uri rdf:type event:Event . \n"
+ "?uri obo:BFO_0000055 ?c . \n"
+ "?c rdf:type core:AttendeeRole . \n"
+ "?c obo:RO_0000052 ?d . \n"
+ "?d rdf:type foaf:Person .\n"
+ " }");
// core:ClinicalRole -- core:clinicalRoleOf
// If the person changes, update the clinical role in project
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?project) \n" +
"WHERE {\n"
+ "?uri rdf:type foaf:Person . \n"
+ "?uri obo:RO_0000053 ?c . \n"
+ "?c rdf:type core:ClinicalRole . \n"
+ "?c obo:BFO_0000054 ?d .\n"
+ "?d rdf:type core:Project .\n"
+ " }");
// If the person changes, update the clinical role in service
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?service) \n" +
"WHERE {\n"
+ "?uri rdf:type foaf:Person . \n"
+ "?uri obo:RO_0000053 ?c . \n"
+ "?c rdf:type core:ClinicalRole . \n"
+ "?c core:roleContributesTo ?d .\n"
+ "?d rdf:type obo:ERO_0000005 .\n"
+ " }");
// If the project changes, update the clinical role of person
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?person) \n" +
"WHERE {\n"
+ "?uri rdf:type core:Project . \n"
+ "?uri obo:BFO_0000055 ?c . \n"
+ "?c rdf:type core:ClinicalRole . \n"
+ "?c obo:RO_0000052 ?d .\n "
+ "?d rdf:type foaf:Person .\n "
+ " }");
// If the service changes, update the clinical role of person
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?person) \n" +
"WHERE {\n"
+ "?uri rdf:type obo:ERO_0000005 . \n"
+ "?uri core:contributingRole ?c . \n"
+ "?c rdf:type core:ClinicalRole . \n"
+ "?c obo:RO_0000052 ?d .\n "
+ "?d rdf:type foaf:Person .\n "
+ " }");
// If the person changes, update the leader role in organization
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?organization) \n" +
"WHERE {\n"
+ "?uri rdf:type foaf:Person . \n"
+ "?uri obo:RO_0000053 ?c . \n"
+ "?c rdf:type core:LeaderRole . \n"
+ "?c core:roleContributesTo ?d .\n"
+ "?d rdf:type foaf:Organization .\n "
+ " }");
// If the organization changes, update the leader role of person
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?person) \n" +
"WHERE {\n"
+ "?uri rdf:type foaf:Organization . \n"
+ "?uri core:contributingRole ?c . \n"
+ "?c rdf:type core:LeaderRole . \n"
+ "?c obo:RO_0000052 ?d .\n "
+ "?d rdf:type foaf:Person .\n "
+ " }");
// core:MemberRole -- core:memberRoleOf
// If the person changes, update the member role in organization
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?organization) \n" +
"WHERE \n{"
+ "?uri rdf:type foaf:Person . \n"
+ "?uri obo:RO_0000053 ?c . \n"
+ "?c rdf:type core:MemberRole . \n"
+ "?c core:roleContributesTo ?d .\n"
+ "?d rdf:type foaf:Organization .\n "
+ " }");
// If the organization changes, update the member role of person
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?person) \n" +
"WHERE {"
+ "?uri rdf:type foaf:Organization . \n"
+ "?uri core:contributingRole ?c . \n"
+ "?c rdf:type core:MemberRole . \n"
+ "?c obo:RO_0000052 ?d .\n "
+ "?d rdf:type foaf:Person .\n "
+ " }");
// core:OrganizerRole -- core:organizerRoleOf
// If the person changes, update the organizer role in organization
// organizerRole appplies to events not organizations; updating accordingly - tlw72
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?event) \n" +
"WHERE {"
+ "?uri rdf:type foaf:Person . \n"
+ "?uri obo:RO_0000053 ?c . \n"
+ "?c rdf:type core:OrganizerRole .\n"
+ "?c obo:BFO_0000054 ?d .\n"
+ "?d rdf:type event:Event .\n "
+ " }");
// If the organization changes, update the organizer role of person
// organizerRole appplies to events not organizations; updating accordingly - tlw72
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?person) \n" +
"WHERE {\n"
+ "?uri rdf:type event:Event . \n"
+ "?uri obo:BFO_0000055 ?c . \n"
+ "?c rdf:type core:OrganizerRole . \n"
+ "?c obo:RO_0000052 ?d .\n "
+ "?d rdf:type foaf:Person .\n "
+ " }");
// core:OutreachProviderRole -- core:outreachProviderRoleOf
// If the person changes, update the outreach provider role in organization
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?organization) \n" +
"WHERE {\n"
+ "?uri rdf:type foaf:Person . \n"
+ "?uri obo:RO_0000053 ?c . \n"
+ "?c rdf:type core:OutreachProviderRole .\n"
+ "?c core:roleContributesTo ?d .\n"
+ "?d rdf:type foaf:Organization .\n "
+ " }");
// If the organization changes, update the outreach provider role of person
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?person) \n" +
"WHERE {\n"
+ "?uri rdf:type foaf:Organization . \n"
+ "?uri core:contributingRole ?c . \n"
+ "?c rdf:type core:OutreachProviderRole . \n"
+ "?c obo:RO_0000052 ?d .\n "
+ "?d rdf:type foaf:Person .\n "
+ " }");
// core:PresenterRole -- core:presenterRoleOf
// If the person changes, update the presentation
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?presentation) \n" +
"WHERE {\n"
+ "?uri rdf:type foaf:Person . \n"
+ "?uri obo:RO_0000053 ?c . \n"
+ " ?c rdf:type core:PresenterRole . \n"
+ " ?c obo:BFO_0000054 ?d .\n"
+ " ?d rdf:type core:Presentation . \n"
+ " }");
// If the presentation changes, update the person
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?person) \n" +
"WHERE {\n"
+ "?uri rdf:type core:Presentation . \n"
+ "?uri obo:BFO_0000055 ?c . \n"
+ " ?c rdf:type core:PresenterRole . \n "
+ "?c obo:RO_0000052 ?d .\n "
+ "?d rdf:type foaf:Person .\n "
+ " }");
// core:ResearcherRole -- core:researcherRoleOf
// If the person changes, update the grant
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?grant) \n" +
"WHERE {\n"
+ "?uri rdf:type foaf:Person . \n"
+ "?uri obo:RO_0000053 ?c . \n"
+ " ?c rdf:type core:ResearcherRole . \n "
+ " ?c core:relatedBy ?d .\n"
+ " ?d rdf:type core:Grant . \n"
+ " }");
// If the grant changes, update the researcher
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?person) \n" +
"WHERE {\n"
+ "?uri rdf:type core:Grant . \n"
+ "?uri core:relates ?c . \n"
+ " ?c rdf:type core:ResearcherRole . \n "
+ " ?c obo:RO_0000052 ?d .\n"
+ "?d rdf:type foaf:Person .\n "
+ " }");
// If the grant changes, update the principal investigator
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?person) \n" +
"WHERE {\n"
+ "?uri rdf:type core:Grant . \n"
+ " ?uri core:relates ?c . \n"
+ " ?c rdf:type core:PrincipalInvestigatorRole . \n "
+ " ?c obo:RO_0000052 ?d .\n"
+ "?d rdf:type foaf:Person .\n "
+ " }");
// If the grant changes, update the co-principal investigator
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?person) \n" +
"WHERE {\n"
+ "?uri rdf:type core:Grant . \n"
+ " ?uri core:relates ?c . \n"
+ " ?c rdf:type core:CoPrincipalInvestigatorRole . \n "
+ " ?c obo:RO_0000052 ?d .\n"
+ "?d rdf:type foaf:Person .\n "
+ " }");
// If the grant changes, update the investigator
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?person) \n" +
"WHERE {\n"
+ "?uri rdf:type core:Grant . \n"
+ " ?uri core:relates ?c . \n"
+ " ?c rdf:type core:InvestigatorRole . \n "
+ " ?c obo:RO_0000052 ?d .\n"
+ "?d rdf:type foaf:Person .\n "
+ " }");
// If the person changes, update the project
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?project) \n" +
"WHERE {\n"
+ "?uri rdf:type foaf:Person . \n"
+ "?uri obo:RO_0000053 ?c . \n"
+ " ?c rdf:type core:ResearcherRole . \n "
+ " ?c obo:BFO_0000054 ?d .\n"
+ " ?d rdf:type core:Project . \n"
+ " }");
// If the project changes, update the researcher
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?person) \n" +
"WHERE {\n"
+ "?uri rdf:type core:Project . \n"
+ " ?uri obo:BFO_0000055 ?c .\n"
+ " ?c rdf:type core:ResearcherRole . \n "
+ " ?c obo:RO_0000052 ?d .\n"
+ "?d rdf:type foaf:Person .\n "
+ " }");
// core:EditorRole -- core:editorRoleOf, core:forInformationResource (person, informationresource)
// If the person changes, update the editor role of the info resource
// changing foaf:Organization to info content entity. Org no longer applies here - tlw72
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?informationResource) \n" +
"WHERE {\n"
+ "?uri rdf:type foaf:Person . \n"
+ "?uri obo:RO_0000053 ?c . \n"
+ " ?c rdf:type core:EditorRole . \n "
+ " ?c core:roleContributesTo ?d .\n"
+ "?d rdf:type obo:IAO_0000030 .\n "
+ " }");
// If the info respource changes, update the editor role of person
// changing foaf:Organization to info content entity. Org no longer applies here - tlw72
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?person) \n" +
"WHERE {\n"
+ "?uri rdf:type obo:IAO_0000030 . \n"
+ "?uri core:contributingRole ?c . \n"
+ " ?c rdf:type core:EditorRole . \n "
+ " ?c obo:RO_0000052 ?d .\n"
+ "?d rdf:type foaf:Person .\n "
+ " }");
// Next two queries are covered by the previous two. Commenting them out - tlw72
// If the person changes, update the information resource associated with editor role
/* multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?informationResource) \n" +
"WHERE {\n"
+ "?uri rdf:type foaf:Person ; ?b ?c . \n"
+ " ?c rdf:type core:EditorRole ; core:forInformationResource ?d .\n"
+ " }");
// If the organization changes, update the information resource associated with editor role
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?informationResource) \n" +
"WHERE {\n"
+ "?uri rdf:type foaf:Organization ; ?b ?c . \n"
+ " ?c rdf:type core:EditorRole ; core:forInformationResource ?d .\n"
+ " }");
*/
// core:ServiceProviderRole -- core:serviceProviderRoleOf
// If the person changes, update the service provider role in organization
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?organization) \n" +
"WHERE {\n"
+ "?uri rdf:type foaf:Person . \n"
+ "?uri obo:RO_0000053 ?c . \n"
+ " ?c rdf:type obo:ERO_0000012 . \n"
+ " ?c core:roleContributesTo ?d .\n"
+ " ?d rdf:type foaf:Organization .\n "
+ " }");
// If the organization changes, update the service provider role of person
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?person) \n" +
"WHERE {\n"
+ "?uri rdf:type foaf:Organization . \n"
+ "?uri core:contributingRole ?c . \n"
+ " ?c rdf:type obo:ERO_0000012 . \n "
+ " ?c obo:RO_0000052 ?d .\n"
+ "?d rdf:type foaf:Person .\n "
+ " }");
// core:TeacherRole -- core:teacherRoleOf
// If the person changes, update the teacher role in organization
// updated to make this an Event (e.g., a course) not an organization - tlw72
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?event) \n" +
"WHERE {\n"
+ "?uri rdf:type foaf:Person . \n"
+ "?uri obo:RO_0000053 ?c . \n"
+ " ?c rdf:type core:TeacherRole . \n"
+ " ?c obo:BFO_0000054 ?d .\n"
+ " ?d rdf:type event:Event .\n "
+ " }");
// If the organization changes, update the teacher role of person
// updated to make this an Event (e.g., a course) not an organization - tlw72
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?person) \n" +
"WHERE {\n"
+ "?uri rdf:type event:Event . \n"
+ "?uri obo:BFO_0000055 ?c . \n"
+ " ?c rdf:type core:TeacherRole . \n "
+ " ?c obo:RO_0000052 ?d .\n"
+ "?d rdf:type foaf:Person .\n "
+ " }");
// core:ReviewerRole -- core:forInformationResource, core:reviewerRoleOf
// core:PeerReviewerRole -- core:forInformationResource, core:reviewerRoleOf
// If the person changes, update the information resource associated with reviewer role
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?informationResource) \n " +
"WHERE {\n"
+ "?uri rdf:type foaf:Person . \n"
+ "?uri obo:RO_0000053 ?c . \n"
+ " ?c rdf:type core:ReviewerRole . \n"
+ " ?c core:roleContributesTo ?d .\n"
+ " ?d rdf:type obo:IAO_0000030 .\n "
+ " }");
// If the organization changes, update the information resource associated with reviewer role
multiValuedQueriesForRole.add(prefix +
"SELECT (str(?d) as ?informationResource) \n" +
"WHERE {\n"
+ "?uri rdf:type obo:IAO_0000030 . \n"
+ "?uri core:contributingRole ?c . \n"
+ " ?c rdf:type core:ReviewerRole. \n "
+ " ?c obo:RO_0000052 ?d .\n"
+ "?d rdf:type foaf:Person .\n "
+ " }");
}
static{
List<String> tmpList = new ArrayList<String>();
tmpList.add(multiValuedQueryForInformationContentEntity);
tmpList.addAll(multiValuedQueriesForAgent);
tmpList.addAll(multiValuedQueriesForRole);
tmpList.addAll( queriesForAuthorship());
tmpList.addAll(queriesForURLLink());
tmpList.addAll(queriesForEducationalTraining());
tmpList.addAll(queriesForPosition());
queryList = Collections.unmodifiableList(tmpList);
}
}

View file

@ -0,0 +1,30 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.search.indexing;
import java.util.ArrayList;
import java.util.List;
import com.hp.hpl.jena.ontology.OntModel;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.search.beans.StatementToURIsToUpdate;
/**
* Make a list of StatementToURIsToUpdate objects for use by the
* IndexBuidler.
*/
public class AdditionalUriFinders {
public static List<StatementToURIsToUpdate> getList(OntModel jenaOntModel,
IndividualDao indDao) {
List<StatementToURIsToUpdate> uriFinders = new ArrayList<>();
uriFinders.add(new AdditionalURIsForDataProperties());
uriFinders.add(new AdditionalURIsForObjectProperties(jenaOntModel));
uriFinders.add(new AdditionalURIsForContextNodes(jenaOntModel));
uriFinders.add(new AdditionalURIsForTypeStatements());
uriFinders.add(new URIsForClassGroupChange(indDao));
return uriFinders;
}
}

View file

@ -0,0 +1,298 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.search.solr;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.solr.common.SolrInputDocument;
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.QuerySolutionMap;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.Syntax;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.shared.Lock;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames;
import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.DocumentModifier;
public class CalculateParameters implements DocumentModifier {
private boolean shutdown = false;
private Dataset dataset;
// public static int totalInd=1;
private static final String prefix = "prefix owl: <http://www.w3.org/2002/07/owl#> "
+ " prefix vitroDisplay: <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#> "
+ " prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
+ " prefix core: <http://vivoweb.org/ontology/core#> "
+ " prefix foaf: <http://xmlns.com/foaf/0.1/> "
+ " prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> "
+ " prefix localNav: <http://vitro.mannlib.cornell.edu/ns/localnav#> "
+ " prefix obo: <http://purl.obolibrary.org/obo/> "
+ " prefix bibo: <http://purl.org/ontology/bibo/> ";
private static final String betaQuery = prefix + " SELECT count(distinct ?inLinks) " +
" WHERE { " +
" ?uri rdf:type owl:Thing . " +
" ?inLinks ?prop ?uri . " +
" } ";
private static final String totalCountQuery = prefix + " SELECT count(distinct ?ind) " +
" WHERE { " +
" ?ind rdf:type owl:Thing . " +
" } ";
private static Log log = LogFactory.getLog(CalculateParameters.class);
public CalculateParameters(Dataset dataset){
this.dataset =dataset;
// new Thread(new TotalInd(this.dataset,totalCountQuery)).start();
}
public CalculateParameters(){
super();
}
public float calculateBeta(String uri){
float beta=0;
int Conn=0;
Query query;
QuerySolutionMap initialBinding = new QuerySolutionMap();
QuerySolution soln = null;
Resource uriResource = ResourceFactory.createResource(uri);
initialBinding.add("uri", uriResource);
dataset.getLock().enterCriticalSection(Lock.READ);
QueryExecution qexec=null;
try{
query = QueryFactory.create(betaQuery,Syntax.syntaxARQ);
qexec = QueryExecutionFactory.create(query,dataset,initialBinding);
ResultSet results = qexec.execSelect();
List<String> resultVars = results.getResultVars();
if(resultVars!=null && resultVars.size()!=0){
soln = results.next();
Conn = Integer.parseInt(soln.getLiteral(resultVars.get(0)).getLexicalForm());
}
}catch(Throwable t){
if( ! shutdown )
log.error(t,t);
}finally{
if( qexec != null )
qexec.close();
dataset.getLock().leaveCriticalSection();
}
beta = (float)Conn;
//beta *= 100;
beta += 1;
// sigmoid function to keep beta between 0 to 1;
beta = (float) (1 / ( 1 + Math.pow(Math.E,(-beta))));
if(beta > 1)
log.info("Beta higher than 1 : " + beta);
else if(beta <= 0)
log.info("Beta lower < = 0 : " + beta);
return beta;
}
public String[] getAdjacentNodes(String uri){
List<String> queryList = new ArrayList<String>();
Set<String> adjacentNodes = new HashSet<String>();
Set<String> coauthorNames = new HashSet<String>();
String[] info = new String[]{"",""};
StringBuffer adjacentNodesConcat = new StringBuffer();
StringBuffer coauthorBuff = new StringBuffer();
adjacentNodesConcat.append("");
coauthorBuff.append("");
queryList.add(prefix +
" SELECT ?adjobj (str(?adjobjLabel) as ?coauthor) " +
" WHERE { " +
" ?uri rdf:type <http://xmlns.com/foaf/0.1/Person> . " +
" ?uri ?prop ?obj . " +
" ?obj rdf:type <http://vivoweb.org/ontology/core#Relationship> . " +
" ?obj ?prop2 ?obj2 . " +
" ?obj2 rdf:type obo:IAO_0000030 . " +
" ?obj2 ?prop3 ?obj3 . " +
" ?obj3 rdf:type <http://vivoweb.org/ontology/core#Relationship> . " +
" ?obj3 ?prop4 ?adjobj . " +
" ?adjobj rdfs:label ?adjobjLabel . " +
" ?adjobj rdf:type <http://xmlns.com/foaf/0.1/Person> . " +
" FILTER (?prop !=rdf:type) . " +
" FILTER (?prop2!=rdf:type) . " +
" FILTER (?prop3!=rdf:type) . " +
" FILTER (?prop4!=rdf:type) . " +
" FILTER (?adjobj != ?uri) . " +
"}");
queryList.add(prefix +
" SELECT ?adjobj " +
" WHERE{ " +
" ?uri rdf:type foaf:Agent . " +
" ?uri ?prop ?obj . " +
" ?obj ?prop2 ?adjobj . " +
" FILTER (?prop !=rdf:type) . " +
" FILTER isURI(?obj) . " +
" FILTER (?prop2!=rdf:type) . " +
" FILTER (?adjobj != ?uri) . " +
" FILTER isURI(?adjobj) . " +
" { ?adjobj rdf:type <http://xmlns.com/foaf/0.1/Organization> . } " +
" UNION " +
" { ?adjobj rdf:type <http://xmlns.com/foaf/0.1/Person> . } " +
" UNION " +
" { ?adjobj rdf:type obo:IAO_0000030 . } " +
" UNION " +
" { ?adjobj rdf:type <http://vivoweb.org/ontology/core#Location> . } ." +
"}");
Query query;
QuerySolution soln;
QuerySolutionMap initialBinding = new QuerySolutionMap();
Resource uriResource = ResourceFactory.createResource(uri);
initialBinding.add("uri", uriResource);
Iterator<String> queryItr = queryList.iterator();
dataset.getLock().enterCriticalSection(Lock.READ);
Resource adjacentIndividual = null;
RDFNode coauthor = null;
try{
while(queryItr.hasNext()){
/*if(!isPerson){
queryItr.next(); // we don't want first query to execute if the ind is not a person.
}*/
query = QueryFactory.create(queryItr.next(),Syntax.syntaxARQ);
QueryExecution qexec = QueryExecutionFactory.create(query,dataset,initialBinding);
try{
ResultSet results = qexec.execSelect();
while(results.hasNext()){
soln = results.nextSolution();
adjacentIndividual = (Resource)soln.get("adjobj");
if(adjacentIndividual!=null){
adjacentNodes.add(adjacentIndividual.getURI());
}
coauthor = soln.get("coauthor");
if(coauthor!=null){
coauthorNames.add(" co-authors " + coauthor.toString() + " co-authors ");
}
}
}catch(Exception e){
if( ! shutdown )
log.error("Error found in getAdjacentNodes method of SearchQueryHandler");
}finally{
qexec.close();
}
}
queryList = null;
Iterator<String> itr = adjacentNodes.iterator();
while(itr.hasNext()){
adjacentNodesConcat.append(itr.next() + " ");
}
info[0] = adjacentNodesConcat.toString();
itr = coauthorNames.iterator();
while(itr.hasNext()){
coauthorBuff.append(itr.next());
}
info[1] = coauthorBuff.toString();
}
catch(Throwable t){
if( ! shutdown )
log.error(t,t);
}finally{
dataset.getLock().leaveCriticalSection();
adjacentNodes = null;
adjacentNodesConcat = null;
coauthorBuff = null;
}
return info;
}
@Override
public void modifyDocument(Individual individual, SolrInputDocument doc, StringBuffer addUri) {
// TODO Auto-generated method stub
// calculate beta value.
log.debug("Parameter calculation starts..");
float beta = calculateBeta(individual.getURI());
doc.addField(VitroSearchTermNames.BETA, beta);
doc.setDocumentBoost(beta + doc.getDocumentBoost() );
log.debug("Parameter calculation is done");
}
public void shutdown(){
shutdown=true;
}
}
class TotalInd implements Runnable{
private Dataset dataset;
private String totalCountQuery;
private static Log log = LogFactory.getLog(TotalInd.class);
public TotalInd(Dataset dataset,String totalCountQuery){
this.dataset = dataset;
this.totalCountQuery = totalCountQuery;
}
public void run(){
int totalInd=0;
Query query;
QuerySolution soln = null;
dataset.getLock().enterCriticalSection(Lock.READ);
QueryExecution qexec = null;
try{
query = QueryFactory.create(totalCountQuery,Syntax.syntaxARQ);
qexec = QueryExecutionFactory.create(query,dataset);
ResultSet results = qexec.execSelect();
List<String> resultVars = results.getResultVars();
if(resultVars!=null && resultVars.size()!=0){
soln = results.next();
totalInd = Integer.parseInt(soln.getLiteral(resultVars.get(0)).getLexicalForm());
}
//CalculateParameters.totalInd = totalInd;
//log.info("Total number of individuals in the system are : " + CalculateParameters.totalInd);
}catch(Throwable t){
log.error(t,t);
}finally{
if( qexec != null )
qexec.close();
dataset.getLock().leaveCriticalSection();
}
}
}

View file

@ -13,7 +13,6 @@ import com.hp.hpl.jena.query.DatasetFactory;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.CalculateParameters;
import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.DocumentModifier;
import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ExcludeBasedOnNamespace;
import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.SearchIndexExcluder;

View file

@ -48,7 +48,7 @@ public class VivoInformationResourceContextNodeFields extends ContextNodeFields{
+ "?uri core:relatedBy ?a . "
+ "?a rdf:type core:Authorship ."
+ "?a core:relates ?b ."
+ "?b rdf:type foaf:Person ."
+ "?b rdf:type foaf:Agent ."
+ "?b rdfs:label ?ContextNodeProperty .}");
/* features */
@ -69,7 +69,7 @@ public class VivoInformationResourceContextNodeFields extends ContextNodeFields{
+ "?uri core:relatedBy ?e . "
+ "?e rdf:type core:Editorship ."
+ "?e core:relates ?i ."
+ "?i rdf:type foaf:Person ."
+ "?i rdf:type foaf:Agent ."
+ "?i rdfs:label ?ContextNodeProperty ."
+ "}");

View file

@ -68,7 +68,7 @@ public class UtilitiesRequestHandler implements VisualizationRequestHandler {
String filterRule = "?predicate = j.2:mainImage "
+ "|| ?predicate = core:preferredTitle "
// + "|| ?predicate = core:preferredTitle "
+ "|| ?predicate = rdfs:label";
QueryRunner<GenericQueryMap> profileQueryHandler =