Adding DocumentModifiers to add values from ISF context nodes to Solr Documents.

This commit is contained in:
Brian Caruso 2013-10-03 15:06:12 -04:00
parent 48b8f3797f
commit d58b031132
9 changed files with 7137 additions and 11 deletions

View file

@ -35,29 +35,33 @@ public class VivoAgentContextNodeFields extends ContextNodeFields{
//queries for foaf:Agent
static {
/* Position */
/* Positions for People */
queriesForAgent.add(prefix +
"SELECT " +
"(str(?ContextNodeProperty) as ?contextNodeProperty) WHERE {" +
" ?uri rdf:type foaf:Agent ; ?b ?c . " +
" ?uri rdf:type foaf:Agent . " +
" ?uri ?b ?c . " +
" ?c rdf:type core:Position . " +
" ?c core:hrJobTitle ?ContextNodeProperty . }");
queriesForAgent.add(prefix + "SELECT " +
"(str(?ContextNodeProperty) as ?contextNodeProperty) WHERE {" +
" ?uri rdf:type foaf:Agent ; ?b ?c . " +
" ?uri rdf:type foaf:Agent . " +
" ?uri ?b ?c . " +
" ?c rdf:type core:Position . " +
" ?c core:involvedOrganizationName ?ContextNodeProperty . }");
queriesForAgent.add(prefix + "SELECT " +
"(str(?ContextNodeProperty) as ?contextNodeProperty) WHERE {" +
" ?uri rdf:type foaf:Agent ; ?b ?c . " +
" ?uri rdf:type foaf:Agent . " +
" ?uri ?b ?c . " +
" ?c rdf:type core:Position . " +
" ?c core:positionInOrganization ?i . ?i rdfs:label ?ContextNodeProperty . }");
queriesForAgent.add(prefix + "SELECT " +
"(str(?ContextNodeProperty) as ?contextNodeProperty) WHERE {" +
" ?uri rdf:type foaf:Agent ; ?b ?c . " +
" ?uri rdf:type foaf:Agent . " +
" ?uri ?b ?c . " +
" ?c rdf:type core:Position . " +
" ?c core:titleOrRole ?ContextNodeProperty . }");

View file

@ -15,9 +15,20 @@ 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;
public class VivoDocumentModifiers implements javax.servlet.ServletContextListener{
/**
* Exclude from the search index individuals who's URIs start with these namespaces.
*/
private static final String[] INDIVIDUAL_NS_EXCLUDES={
//bdc34: seems that there are a lot of odd OBO things in the search, exclude them
"http://purl.obolibrary.org/obo/"
};
@SuppressWarnings("unchecked")
@Override
public void contextInitialized(ServletContextEvent sce) {
@ -26,14 +37,35 @@ public class VivoDocumentModifiers implements javax.servlet.ServletContextListen
Dataset dataset = DatasetFactory.create(ModelAccess.on(context).getJenaOntModel());
/* put DocumentModifiers into servlet context for use later in startup by SolrSetup */
/* Put DocumentModifiers into servlet context for use later in startup by SolrSetup
* This adds the code for VIVO specific additions to the building
* of solr Documents. */
List<DocumentModifier> modifiers = (List<DocumentModifier>)context.getAttribute("DocumentModifiers");
if( modifiers == null ){
modifiers = new ArrayList<DocumentModifier>();
context.setAttribute("DocumentModifiers", modifiers);
}
List<DocumentModifier> modifiers = new ArrayList<DocumentModifier>();
modifiers.add(new CalculateParameters(dataset)); //
modifiers.add(new VivoAgentContextNodeFields(rdfServiceFactory));
modifiers.add(new VivoInformationResourceContextNodeFields(rdfServiceFactory));
modifiers.add(new CalculateParameters(dataset));
modifiers.add( new VivoISFBasicFields( rdfServiceFactory ));
modifiers.add( new VivoISFAdvisingFields( rdfServiceFactory ));
modifiers.add( new VivoISFEducationFields( rdfServiceFactory ));
modifiers.add( new VivoISFGrantFields( rdfServiceFactory ));
modifiers.add( new VivoISFMemberFields( rdfServiceFactory ));
modifiers.add(new VivoInformationResourceContextNodeFields(rdfServiceFactory));
context.setAttribute("DocumentModifiers", modifiers);
/*
* Add VIVO specific code that excludes Individuals from the search index.
*/
List<SearchIndexExcluder> excludes =
(List<SearchIndexExcluder>)context.getAttribute("SearchIndexExcludes");
if( excludes == null ){
excludes = new ArrayList<SearchIndexExcluder>();
context.setAttribute("SearchIndexExcludes", excludes);
}
excludes.add(new ExcludeBasedOnNamespace(INDIVIDUAL_NS_EXCLUDES ));
}
@Override

View file

@ -0,0 +1,52 @@
package edu.cornell.mannlib.vitro.webapp.search.solr;
import java.util.ArrayList;
import java.util.List;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ContextNodeFields;
/**
* DocumentModifier for adding rdfs:labels of individuals related via
* a advising relationship.
*
* @author bdc34
*
*/
public class VivoISFAdvisingFields extends ContextNodeFields {
private static String VIVONS = "http://vivoweb.org/ontology/core#";
protected static final String prefix =
" prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n"
+ " prefix core: <" + VIVONS + "> \n"
+ " prefix foaf: <http://xmlns.com/foaf/0.1/> \n"
+ " prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
+ " prefix obo: <http://purl.obolibrary.org/obo/> \n" ;
static List<String> queries = new ArrayList<String>();
static{
queries.add( makeQueryForPeople() );
}
public VivoISFAdvisingFields(RDFServiceFactory rdfServiceFactory){
super(queries,rdfServiceFactory);
}
/**
* This query will get all the labels for the other
* person in the relationship.
*/
private static String makeQueryForPeople(){
return prefix +
"SELECT \n" +
"(str(?result) as ?result) WHERE \n" +
"{\n" +
" ?uri core:relatedBy ?rel . \n" +
" ?rel rdf:type core:AdvisingRelationship . \n" +
" ?rel core:relates ?other . \n" +
" ?other rdfs:label ?result . \n" +
"}";
}
}

View file

@ -0,0 +1,71 @@
package edu.cornell.mannlib.vitro.webapp.search.solr;
import java.util.ArrayList;
import java.util.List;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ContextNodeFields;
/**
* DocumentModifier to populate Solr fields for the basic ISF relationships.
*
* This will add the all rdfs:labels of the related individuals to the solr document.
*
* @author bdc34
*/
public class VivoISFBasicFields extends ContextNodeFields {
private static String VIVONS = "http://vivoweb.org/ontology/core#";
/**
* Subtypes of vivo:Relationship that get handled by this class.
*/
private static String[] RELATIONSHIP_TYPES = {
//VIVONS + "Relationship",
VIVONS + "Postion",
VIVONS + "Authorship",
VIVONS + "Collaboration",
VIVONS + "Affiliation"
};
static List<String> queries = new ArrayList<String>();
public VivoISFBasicFields(RDFServiceFactory rdfServiceFactory){
super(queries,rdfServiceFactory);
}
protected static final String prefix =
" prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n"
+ " prefix core: <" + VIVONS + "> \n"
+ " prefix foaf: <http://xmlns.com/foaf/0.1/> \n"
+ " prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
+ " prefix obo: <http://purl.obolibrary.org/obo/> \n" ;
static {
/* make a string of the RELATIONSHIP_TYPES for use in
* a SPARQL IN clause */
String types = "";
for( int i = 0 ; i < RELATIONSHIP_TYPES.length ; i++ ){
types += RELATIONSHIP_TYPES[i];
if( i != RELATIONSHIP_TYPES.length - 1 ){
types += ", ";
}
}
queries.add(
prefix +
"SELECT \n" +
"(str(?result) as ?result) WHERE \n" +
"{\n" +
" ?uri core:relatedBy ?rel . \n" +
" ?rel rdf:type ?type . \n" +
" ?rel core:relates ?other . \n" +
" ?other rdfs:label ?result . \n" +
" FILTER ( ?type IN ( " + types + " ) )\n" +
"}" );
}
}

View file

@ -0,0 +1,56 @@
package edu.cornell.mannlib.vitro.webapp.search.solr;
import java.util.ArrayList;
import java.util.List;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ContextNodeFields;
public class VivoISFEducationFields extends ContextNodeFields {
private static String VIVONS = "http://vivoweb.org/ontology/core#";
protected static final String prefix =
" prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n"
+ " prefix core: <" + VIVONS + "> \n"
+ " prefix foaf: <http://xmlns.com/foaf/0.1/> \n"
+ " prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
+ " prefix obo: <http://purl.obolibrary.org/obo/> \n" ;
public VivoISFEducationFields(RDFServiceFactory rdfServiceFactory){
super(queries,rdfServiceFactory);
}
/**
* This query will get all the labels for the degree.
*/
private static String queryForDegree =
prefix +
"SELECT \n" +
"(str(?result) as ?result) WHERE \n" +
"{\n" +
" ?uri core:relates ?deg . \n" +
" ?deg rdf:type core:AwardedDegree . \n" +
" ?deg rdfs:label ?result . \n" +
"}";
/**
* This will get all labels for the organization.
*/
private static String queryForOrganization =
prefix +
"SELECT \n" +
"(str(?result) as ?result) WHERE \n" +
"{\n" +
" ?uri core:relates ?deg . \n" +
" ?deg rdf:type core:AwardedDegree . \n" +
" ?deg core:assignedBy ?org . \n" +
" ?org rdfs:label ?result . \n" +
"}";
static List<String> queries = new ArrayList<String>();
static{
queries.add( queryForDegree );
queries.add( queryForOrganization );
}
}

View file

@ -0,0 +1,159 @@
package edu.cornell.mannlib.vitro.webapp.search.solr;
import java.util.ArrayList;
import java.util.List;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ContextNodeFields;
/*
* This DocumentModifier is for the ISF style grants.
* It will
* add people's names to the grant's Solr Document
* add the grant's name to the people's Solr Document
* add the grant's name to the Organization's Solr Document
* add the organization's name to the grant's Solr Document
* add the grant's names to the project's Solr Document
* add the people's names to the project's Solr Document
* add the project's name to the grant's Solr Document
* add the project's name to the people's Solr Document
*/
public class VivoISFGrantFields extends ContextNodeFields {
private static String VIVONS = "http://vivoweb.org/ontology/core#";
protected static final String prefix =
" prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n"
+ " prefix core: <" + VIVONS + "> \n"
+ " prefix foaf: <http://xmlns.com/foaf/0.1/> \n"
+ " prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
+ " prefix obo: <http://purl.obolibrary.org/obo/> \n" ;
public VivoISFGrantFields(RDFServiceFactory rdfServiceFactory){
super(queries,rdfServiceFactory);
}
/**
* Query to add people's names to the grant's Solr Document.
* ?uri is the URI of a grant.
*/
private static String peopleForGrant =
prefix +
"SELECT (str(?result) as ?result) WHERE {\n" +
" ?uri rdf:type core:Grant . \n" +
" ?uri core:relates ?person . \n" +
" ?person rdf:type foaf:Person . \n" +
" ?person rdfs:label ?result . \n" +
"}";
/**
* Query to add the grant's name to the people's Solr Document.
* ?uri is the URI of a person.
*/
private static String grantsForPerson =
prefix +
"SELECT \n" +
"(str(?result) as ?result) WHERE \n" +
"{\n" +
" ?uri rdf:type foaf:Person . \n" +
" ?grant core:relates ?uri . \n" +
" ?grant rdf:type core:Grant . \n" +
" ?grant rdfs:label ?result . \n" +
"}";
/**
* Query to add the grant's name to the Organization's Solr Document.
* ?uri is the URI of an Organization.
*/
private static String grantsForOrganization =
prefix +
"SELECT (str(?result) as ?result) WHERE {\n" +
" ?uri rdf:type foaf:Organization . \n" +
" ?grant core:relates ?uri . \n" +
" ?grant rdf:type core:Grant . \n" +
" ?grant rdfs:label ?result . \n" +
"}";
/**
* Query to add the organization's name to the grant's Solr Document.
* ?uri is the URI of a grant.
*/
private static String organizationsForGrant =
prefix +
"SELECT (str(?result) as ?result) WHERE {\n" +
" ?uri rdf:type core:Grant . \n" +
" ?uri core:relates ?org . \n" +
" ?org rdf:type foaf:Organization . \n" +
" ?org rdfs:label ?result . \n" +
"}";
/**
* Query to add the grant's names to the project's Solr Document.
* ?uir is the URI of a Project.
*/
private static String grantsForProject =
prefix +
"SELECT (str(?result) as ?result) WHERE {\n" +
" ?uri rdf:type core:Project . \n" +
" ?role obo:BFO_0000054 ?uri . \n" +
" ?grant core:relates ?role . \n" +
" ?grant rdf:type core:Grant . \n" +
" ?grant rdfs:label ?result . \n" +
"}";
/**
* Query to add the people's names to the project's Solr Document.
* ?uri is the URI of a Project.
*/
private static String peopleForProject =
prefix +
"SELECT (str(?result) as ?result) WHERE {\n" +
" ?uri rdf:type core:Project . \n" +
" ?role obo:BFO_0000054 ?uri . \n" +
" ?role obo:RO_0000053 ?person . \n" +
" ?person rdf:type foaf:Person . \n" +
" ?person rdfs:label ?result . \n" +
"}";
/**
* Query to add the project's name to the grant's Solr Document.
* ?uri is the URI of a grant.
*/
private static String projectsForGrant =
prefix +
"SELECT \n" +
"(str(?result) as ?result) WHERE \n" +
"{\n" +
" ?uri rdf:type core:Grant. \n" +
" ?uri core:relates ?role . \n" +
" ?role obo:BFO_0000054 ?project . \n" +
" ?project rdf:type core:Project . \n" +
" ?project rdfs:label ?result . \n" +
"}";
/**
* Query to add the project's name to the people's Solr Document.
* ?uri is the URI of a person.
*/
private static String projectsForPerson =
prefix +
"SELECT (str(?result) as ?result) WHERE {\n" +
" ?uri rdf:type foaf:Person . \n" +
" ?uri obo:RO_0000053 ?role . \n" +
" ?role obo:BFO_0000054 ?project . \n" +
" ?project rdf:type core:Project . \n" +
" ?project rdfs:label ?result . \n" +
"}";
static List<String> queries = new ArrayList<String>();
static{
queries.add( peopleForGrant );
queries.add( grantsForPerson );
queries.add( grantsForOrganization );
queries.add( organizationsForGrant );
queries.add( grantsForProject );
queries.add( peopleForProject );
queries.add( projectsForGrant );
queries.add( projectsForPerson );
}
}

View file

@ -0,0 +1,60 @@
package edu.cornell.mannlib.vitro.webapp.search.solr;
import java.util.ArrayList;
import java.util.List;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ContextNodeFields;
/**
* This class will:
* add people's names to organization's Solr Documents.
* add organization names to people's Solr Documents.
*
* @author bdc34
*
*/
public class VivoISFMemberFields extends ContextNodeFields {
private static String VIVONS = "http://vivoweb.org/ontology/core#";
protected static final String prefix =
" prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n"
+ " prefix core: <" + VIVONS + "> \n"
+ " prefix foaf: <http://xmlns.com/foaf/0.1/> \n"
+ " prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
+ " prefix obo: <http://purl.obolibrary.org/obo/> \n" ;
public VivoISFMemberFields(RDFServiceFactory rdfServiceFactory){
super(queries,rdfServiceFactory);
}
/**
* Add people's names to organization's Solr Documents.
*/
private static String peopleForOrganization =
prefix +
"SELECT (str(?result) as ?result) WHERE {\n" +
" ?uri rdf:type foaf:Organization . \n" +
" ?role vivo:roleContrigutesTo ?uri . \n" +
" ?person obo:RO_0000053 ?role . \n" +
" ?person rdfs:label ?result .\n" +
"}";
/**
* add organization names to people's Solr Documents.
*/
private static String organizationForPeople =
prefix +
"SELECT (str(?result) as ?result) WHERE {\n" +
" ?uri rdf:type foaf:Person . \n" +
" ?uri obo:RO_0000053 / vivo:roleContrigutesTo / rdfs:label ?result . \n" +
"}";
static List<String> queries = new ArrayList<String>();
static{
queries.add( peopleForOrganization );
queries.add( organizationForPeople );
}
}