diff --git a/rdf/display/everytime/searchIndexerConfigurationVivo.n3 b/rdf/display/everytime/searchIndexerConfigurationVivo.n3 index 07c81b21..54595cdb 100644 --- a/rdf/display/everytime/searchIndexerConfigurationVivo.n3 +++ b/rdf/display/everytime/searchIndexerConfigurationVivo.n3 @@ -29,25 +29,140 @@ a , . -:vivodocumentModifier_valuesFromVcards - a , - . +:vivodocumentModifier_PreferredTitle + a , + ; + rdfs:label "Preferred title" ; + :hasTargetField "ALLTEXT" ; + :hasTargetField "ALLTEXTUNSTEMMED" ; + :hasTargetField "PREFERRED_TITLE" ; + :hasSparqlQuery """ + PREFIX vcard: + PREFIX obo: + SELECT ?title + WHERE { + ?uri obo:ARG_2000028 ?card . + ?card a vcard:Individual . + ?card vcard:hasTitle ?titleHolder . + ?titleHolder vcard:title ?title . + } + """ . + +:vivodocumentModifier_EmailAddress + a , + ; + rdfs:label "Email address" ; + :hasTargetField "ALLTEXT" ; + :hasTargetField "ALLTEXTUNSTEMMED" ; + :hasSparqlQuery """ + PREFIX vcard: + PREFIX obo: + SELECT ?email + WHERE { + ?uri obo:ARG_2000028 ?card . + ?card a vcard:Individual . + ?card vcard:hasEmail ?emailHolder . + ?emailHolder vcard:email ?email . + } + """ . +:vivodocumentModifier_NamesAcrossContextNodes + a , + ; + rdfs:label "Names of objects across context nodes" ; + :hasSparqlQuery """ + PREFIX rdf: + PREFIX core: + PREFIX foaf: + PREFIX rdfs: + PREFIX obo: + SELECT (str(?rawresult) as ?result) + WHERE { + ?uri core:relatedBy ?rel . + ?rel rdf:type ?type . + ?rel core:relates ?other . + ?other rdfs:label ?rawresult . + FILTER ( ?type IN ( core:Position, core:Authorship, core:Collaboration, core:Affiliation ) ) + } + """ . -:vivodocumentModifier_ISFBasicFields - a , - . +:vivodocumentModifier_MembershipFields + a , + ; + rdfs:label "Add people to organization and vice versa." ; + :hasSparqlQuery """ + PREFIX rdf: + PREFIX core: + PREFIX foaf: + PREFIX rdfs: + PREFIX obo: + SELECT (str(?rawresult) as ?result) + WHERE { + ?uri rdf:type foaf:Organization . + ?role core:roleContributesTo ?uri . + ?person obo:RO_0000053 ?role . + ?person rdfs:label ?rawresult . + } + """ ; + :hasSparqlQuery """ + PREFIX rdf: + PREFIX core: + PREFIX foaf: + PREFIX rdfs: + PREFIX obo: + SELECT (str(?rawresult) as ?result) + WHERE { + ?uri rdf:type foaf:Person . + ?uri obo:RO_0000053 / core:roleContributesTo / rdfs:label ?rawresult . + } + """ . -:vivodocumentModifier_ISFAdvisingFields - a , - . - -:vivodocumentModifier_ISFEducationFields - a , - . - -:vivodocumentModifier_ISFMemberFields - a , - . +:vivodocumentModifier_EducationFields + a , + ; + rdfs:label "Labels for a degree and the granting organization." ; + :hasSparqlQuery """ + PREFIX rdf: + PREFIX core: + PREFIX rdfs: + SELECT (str(?rawresult) as ?result) + WHERE { + ?uri core:relates ?deg . + ?deg rdf:type core:AwardedDegree . + ?deg rdfs:label ?rawresult . + } + """ ; + :hasSparqlQuery """ + PREFIX rdf: + PREFIX core: + PREFIX rdfs: + SELECT (str(?rawresult) as ?result) + WHERE { + ?uri core:relates ?deg . + ?deg rdf:type core:AwardedDegree . + ?deg core:assignedBy ?org . + ?org rdfs:label ?rawresult . + } + """ . + +:vivodocumentModifier_AdvisingFields + a , + ; + rdfs:label "Labels for people in an advising relationship." ; + :hasSparqlQuery """ + PREFIX rdf: + PREFIX core: + PREFIX foaf: + PREFIX rdfs: + PREFIX obo: + SELECT (str(?rawresult) as ?result) + WHERE { + ?uri core:relatedBy ?rel . + ?rel rdf:type core:AdvisingRelationship . + ?rel core:relates ?other . + ?other rdfs:label ?rawresult . + FILTER( ?other != ?uri ) + } + """ . :vivodocumentModifier_Grants_Projects_ForPerson a , diff --git a/src/edu/cornell/mannlib/vitro/webapp/searchindex/documentBuilding/VIVOValuesFromVcards.java b/src/edu/cornell/mannlib/vitro/webapp/searchindex/documentBuilding/VIVOValuesFromVcards.java deleted file mode 100644 index 551da06d..00000000 --- a/src/edu/cornell/mannlib/vitro/webapp/searchindex/documentBuilding/VIVOValuesFromVcards.java +++ /dev/null @@ -1,145 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.searchindex.documentBuilding; - -import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.ALLTEXT; -import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.ALLTEXTUNSTEMMED; -import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.PREFERRED_TITLE; - -import org.apache.commons.lang.StringUtils; -import org.apache.commons.logging.Log; -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.RDFNode; - -import edu.cornell.mannlib.vitro.webapp.beans.Individual; -import edu.cornell.mannlib.vitro.webapp.modelaccess.ContextModelAccess; -import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; -import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; -import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils; -import edu.cornell.mannlib.vitro.webapp.utils.configuration.ContextModelsUser; - -/** - * If there are any VCards on this Individual with Title objects, store the text - * in the Preferred Title search field, and the ALL_TEXT field. - * - * If there are any VCards on this Individual with EMail objects, store the text - * in the ALL_TEXT field. - */ -public class VIVOValuesFromVcards implements DocumentModifier, ContextModelsUser { - private static final Log log = LogFactory - .getLog(VIVOValuesFromVcards.class); - - private static final String PREFERRED_TITLE_QUERY = "" - + "prefix vcard: \n" - + "prefix obo: \n\n" - + "SELECT ?title WHERE { \n" // - + " ?uri obo:ARG_2000028 ?card . \n" - + " ?card a vcard:Individual . \n" - + " ?card vcard:hasTitle ?titleHolder . \n" - + " ?titleHolder vcard:title ?title . \n" // - + "}"; - - private static final ResultParser PREFERRED_TITLE_PARSER = new ResultParser() { - @Override - public void parse(String uri, QuerySolution solution, SearchInputDocument doc) { - String title = getLiteralValue(solution, "title"); - if (StringUtils.isNotBlank(title)) { - doc.addField(PREFERRED_TITLE, title); - doc.addField(ALLTEXT, title); - doc.addField(ALLTEXTUNSTEMMED, title); - log.debug("Preferred Title for " + uri + ": '" + title + "'"); - } - } - }; - - private static final String EMAIL_QUERY = "" - + "prefix vcard: \n" - + "prefix obo: \n\n" - + "SELECT ?email WHERE { \n" // - + " ?uri obo:ARG_2000028 ?card . \n" - + " ?card a vcard:Individual . \n" - + " ?card vcard:hasEmail ?emailHolder . \n" - + " ?emailHolder vcard:email ?email . \n" // - + "}"; - - private static final ResultParser EMAIL_PARSER = new ResultParser() { - @Override - public void parse(String uri, QuerySolution solution, - SearchInputDocument doc) { - String email = getLiteralValue(solution, "email"); - if (StringUtils.isNotBlank(email)) { - doc.addField(ALLTEXT, email); - doc.addField(ALLTEXTUNSTEMMED, email); - log.debug("Email for " + uri + ": '" + email + "'"); - } - }}; - - private RDFService rdfService; - private boolean shutdown = false; - - @Override - public void setContextModels(ContextModelAccess models) { - this.rdfService = models.getRDFService(); - } - - @Override - public void modifyDocument(Individual individual, SearchInputDocument doc) { - if (individual == null) - return; - - processQuery(individual, PREFERRED_TITLE_QUERY, PREFERRED_TITLE_PARSER, - doc); - processQuery(individual, EMAIL_QUERY, EMAIL_PARSER, doc); - } - - private void processQuery(Individual individual, String queryTemplate, - ResultParser resultParser, SearchInputDocument doc) { - String uri = "<" + individual.getURI() + "> "; - String query = queryTemplate.replaceAll("\\?uri", uri); - - try { - ResultSet results = RDFServiceUtils.sparqlSelectQuery(query, - rdfService); - if (results != null) { - while (results.hasNext()) { - log.debug("Next solution"); - QuerySolution solution = results.nextSolution(); - resultParser.parse(uri, solution, doc); - } - } - } catch (Exception e) { - if (!shutdown) { - log.error("problem while running query '" + query + "'", e); - } - } - } - - @Override - public void shutdown() { - shutdown = true; - } - - - @Override - public String toString() { - return this.getClass().getSimpleName() + "[]"; - } - - private abstract static class ResultParser { - public abstract void parse(String uri, QuerySolution solution, SearchInputDocument doc); - - String getLiteralValue(QuerySolution solution, String name) { - RDFNode node = solution.get(name); - if ((node != null) && (node.isLiteral())) { - String value = node.asLiteral().getString(); - if (StringUtils.isNotBlank(value)) { - return value; - } - } - return ""; - } - } -} diff --git a/src/edu/cornell/mannlib/vitro/webapp/searchindex/documentBuilding/VivoISFAdvisingFields.java b/src/edu/cornell/mannlib/vitro/webapp/searchindex/documentBuilding/VivoISFAdvisingFields.java deleted file mode 100644 index 0b761511..00000000 --- a/src/edu/cornell/mannlib/vitro/webapp/searchindex/documentBuilding/VivoISFAdvisingFields.java +++ /dev/null @@ -1,52 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.searchindex.documentBuilding; - -import java.util.ArrayList; -import java.util.List; - -/** - * 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: \n" - + " prefix core: <" + VIVONS + "> \n" - + " prefix foaf: \n" - + " prefix rdfs: \n" - + " prefix obo: \n" ; - - static List queries = new ArrayList(); - static{ - queries.add( makeQueryForPeople() ); - } - - public VivoISFAdvisingFields(){ - super(queries); - } - - /** - * This query will get all the labels for the other - * person in the relationship. - */ - private static String makeQueryForPeople(){ - return prefix + - "SELECT \n" + - "(str(?rawresult) as ?result) WHERE \n" + - "{\n" + - " ?uri core:relatedBy ?rel . \n" + - " ?rel rdf:type core:AdvisingRelationship . \n" + - " ?rel core:relates ?other . \n" + - " ?other rdfs:label ?rawresult . \n" + - " FILTER( ?other != ?uri ) \n" + - "}"; - } - -} diff --git a/src/edu/cornell/mannlib/vitro/webapp/searchindex/documentBuilding/VivoISFBasicFields.java b/src/edu/cornell/mannlib/vitro/webapp/searchindex/documentBuilding/VivoISFBasicFields.java deleted file mode 100644 index 956fab99..00000000 --- a/src/edu/cornell/mannlib/vitro/webapp/searchindex/documentBuilding/VivoISFBasicFields.java +++ /dev/null @@ -1,69 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.searchindex.documentBuilding; - -import java.util.ArrayList; -import java.util.List; - -/** - * DocumentModifier to populate Search index fields for the basic ISF relationships. - * - * This will add the all rdfs:labels of the related individuals to the search 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 + "Position", - VIVONS + "Authorship", - VIVONS + "Collaboration", - VIVONS + "Affiliation" - }; - - static List queries = new ArrayList(); - - public VivoISFBasicFields(){ - super(queries); - } - - protected static final String prefix = - " prefix rdf: \n" - + " prefix core: <" + VIVONS + "> \n" - + " prefix foaf: \n" - + " prefix rdfs: \n" - + " prefix 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(?rawresult) as ?result) WHERE \n" + - "{\n" + - " ?uri core:relatedBy ?rel . \n" + - " ?rel rdf:type ?type . \n" + - " ?rel core:relates ?other . \n" + - " ?other rdfs:label ?rawresult . \n" + - " FILTER ( ?type IN ( " + types + " ) )\n" + - "}" ); - } - -} diff --git a/src/edu/cornell/mannlib/vitro/webapp/searchindex/documentBuilding/VivoISFEducationFields.java b/src/edu/cornell/mannlib/vitro/webapp/searchindex/documentBuilding/VivoISFEducationFields.java deleted file mode 100644 index b3208795..00000000 --- a/src/edu/cornell/mannlib/vitro/webapp/searchindex/documentBuilding/VivoISFEducationFields.java +++ /dev/null @@ -1,55 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.searchindex.documentBuilding; - -import java.util.ArrayList; -import java.util.List; - -public class VivoISFEducationFields extends ContextNodeFields { - private static String VIVONS = "http://vivoweb.org/ontology/core#"; - - protected static final String prefix = - " prefix rdf: \n" - + " prefix core: <" + VIVONS + "> \n" - + " prefix foaf: \n" - + " prefix rdfs: \n" - + " prefix obo: \n" ; - - public VivoISFEducationFields(){ - super(queries); - } - - /** - * This query will get all the labels for the degree. - */ - private static String queryForDegree = - prefix + - "SELECT \n" + - "(str(?rawresult) as ?result) WHERE \n" + - "{\n" + - " ?uri core:relates ?deg . \n" + - " ?deg rdf:type core:AwardedDegree . \n" + - " ?deg rdfs:label ?rawresult . \n" + - "}"; - - /** - * This will get all labels for the organization. - */ - private static String queryForOrganization = - prefix + - "SELECT \n" + - "(str(?rawresult) as ?result) WHERE \n" + - "{\n" + - " ?uri core:relates ?deg . \n" + - " ?deg rdf:type core:AwardedDegree . \n" + - " ?deg core:assignedBy ?org . \n" + - " ?org rdfs:label ?rawresult . \n" + - "}"; - - static List queries = new ArrayList(); - - static{ - queries.add( queryForDegree ); - queries.add( queryForOrganization ); - } -} diff --git a/src/edu/cornell/mannlib/vitro/webapp/searchindex/documentBuilding/VivoISFMemberFields.java b/src/edu/cornell/mannlib/vitro/webapp/searchindex/documentBuilding/VivoISFMemberFields.java deleted file mode 100644 index 458378cc..00000000 --- a/src/edu/cornell/mannlib/vitro/webapp/searchindex/documentBuilding/VivoISFMemberFields.java +++ /dev/null @@ -1,59 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.searchindex.documentBuilding; - -import java.util.ArrayList; -import java.util.List; - -/** - * This class will: - * add people's names to organization's search Documents. - * add organization names to people's search Documents. - * - * @author bdc34 - * - */ -public class VivoISFMemberFields extends ContextNodeFields { - private static String VIVONS = "http://vivoweb.org/ontology/core#"; - - protected static final String prefix = - " prefix rdf: \n" - + " prefix core: <" + VIVONS + "> \n" - + " prefix foaf: \n" - + " prefix rdfs: \n" - + " prefix obo: \n" ; - - public VivoISFMemberFields(){ - super(queries); - } - - /** - * Add people's names to organization's search Documents. - */ - private static String peopleForOrganization = - prefix + - "SELECT (str(?rawresult) as ?result) WHERE {\n" + - " ?uri rdf:type foaf:Organization . \n" + - " ?role core:roleContributesTo ?uri . \n" + - " ?person obo:RO_0000053 ?role . \n" + - " ?person rdfs:label ?rawresult .\n" + - "}"; - - /** - * add organization names to people's search Documents. - */ - private static String organizationForPeople = - prefix + - "SELECT (str(?rawresult) as ?result) WHERE {\n" + - " ?uri rdf:type foaf:Person . \n" + - " ?uri obo:RO_0000053 / core:roleContributesTo / rdfs:label ?rawresult . \n" + - "}"; - - - static List queries = new ArrayList(); - - static{ - queries.add( peopleForOrganization ); - queries.add( organizationForPeople ); - } -}