This commit is contained in:
anupsawant 2011-05-31 23:23:59 +00:00
parent adac7e86a0
commit cbf8627376
9 changed files with 39 additions and 779 deletions

View file

@ -1,732 +0,0 @@
package edu.cornell.mannlib.vitro.webapp.search.beans;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletContext;
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.Literal;
import com.hp.hpl.jena.rdf.model.Property;
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.StmtIterator;
import com.hp.hpl.jena.shared.Lock;
import com.hp.hpl.jena.vocabulary.RDF;
import java.util.HashSet;
import java.util.Set;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
public class SearchQueryHandler {
private OntModel fullModel;
private String contextNodeURI;
private int totalInd;
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 bibo: <http://purl.org/ontology/bibo/> ";
//private String query = "";
// private static final String queryForEducationalTraining = "SELECT ?query WHERE {" +
// "?searchConfig <"+ DisplayVocabulary.QUERY_FOR_EDUCATIONAL_TRAINING + "> ?query . }";
private static Log log = LogFactory.getLog(SearchQueryHandler.class);
public SearchQueryHandler(String contextNodeURI,
OntModel displayOntModel, ServletContext context) {
this.fullModel = ModelContext.getJenaOntModel(context);
this.contextNodeURI = contextNodeURI;
this.totalInd = fullModel.listIndividuals().toList().size();
//query = getQueryFromModel(contextNodeURI, displayOntModel);
}
/*
* bk392 : The original idea behind writing up this method was to check
* if I can read the queries from search.n3, write them to the displayOntModel(during startup) and
* read them in this class.
*
* Eventually, its going to be like that. All these hardcoded queries
* will go into search.n3 and will be written into the display model.
* ContextNodesInclusionFactors gets the queries out from the display Model
* and fires them, gets the values, concatenates them and passes them back to
* IndividualToSolrDoc.
*/
// private String getQueryFromModel(String uri, OntModel displayOntModel) {
//
// String resultQuery = "";
// QuerySolutionMap initialBinding = new QuerySolutionMap();
// Resource searchConfig = ResourceFactory.createResource(uri);
//
// initialBinding.add("searchConfig", searchConfig);
//
// Query query = QueryFactory.create(queryForEducationalTraining);
// displayOntModel.enterCriticalSection(Lock.READ);
// try{
// QueryExecution qExec = QueryExecutionFactory.create(query, displayOntModel, initialBinding);
// try{
// ResultSet results = qExec.execSelect();
// while(results.hasNext()){
// QuerySolution soln = results.nextSolution();
// Literal node = soln.getLiteral("query");
// if(node.isLiteral()){
// resultQuery = node.toString();
// }else{
// log.warn("unexpected literal in the object position for context node queries " + node.toString());
// }
// }
// }catch(Throwable t){
// log.error(t,t);
// } finally{
// qExec.close();
// }
// }finally{
// displayOntModel.leaveCriticalSection();
// }
//
// return resultQuery.substring(0, resultQuery.length() - 3);
// }
// public List<Field> getFieldValues(String uri, Model modelToQuery, List<String> queries){
//what do the queries need to be like?
// SELECT ?field ?value WHERE ....
// what to do with multiple values for a field?
// }
//in different object:
/*
* get queries from somewhere
* get model to run queries on
* get list of individuals
* for each individual:
* fields = getFieldValues(uri, model, queiries)
* index(fields)?
*
*
*/
public String getPropertiesAssociatedWithPosition(String uri){
StringBuffer propertyValues = new StringBuffer();
QuerySolutionMap initialBinding = new QuerySolutionMap();
Resource uriResource = ResourceFactory.createResource(uri);
initialBinding.add("uri", uriResource);
String thisQuery = prefix +
"SELECT " +
"(str(?HRJobTitle) as ?hrJobTitle) (str(?InvolvedOrganizationName) as ?involvedOrganizationName) " +
" (str(?PositionForPerson) as ?positionForPerson) (str(?PositionInOrganization) as ?positionInOrganization) " +
" (str(?TitleOrRole) as ?titleOrRole) WHERE {" //(str(?PositionLabel) as ?positionLabel)
+ "?uri rdf:type foaf:Agent ; ?b ?c . "
+ " ?c rdf:type core:Position . "
+ " OPTIONAL { ?c core:hrJobTitle ?HRJobTitle . } . "
+ " OPTIONAL { ?c core:involvedOrganizationName ?InvolvedOrganizationName . } ."
+ " OPTIONAL { ?c core:positionForPerson ?f . ?f rdfs:label ?PositionForPerson . } . "
+ " OPTIONAL { ?c core:positionInOrganization ?i . ?i rdfs:label ?PositionInOrganization . } . "
+ " OPTIONAL { ?c core:titleOrRole ?TitleOrRole . } . "
//+ " OPTIONAL { ?c rdfs:label ?PositionLabel . } "
+ " } ORDER BY ?PositionLabel ";
Query sparqlQuery = QueryFactory.create(thisQuery, Syntax.syntaxARQ);
fullModel.enterCriticalSection(Lock.READ);
try{
QueryExecution qExec = QueryExecutionFactory.create(sparqlQuery, fullModel, initialBinding);
try{
ResultSet results = qExec.execSelect();
while(results.hasNext()){
QuerySolution soln = results.nextSolution();
RDFNode hrJobTitle = soln.get("hrJobTitle");
if(hrJobTitle != null){
propertyValues.append(" " + hrJobTitle.toString());
}else{
log.debug("hrJobTitle is null ");
}
RDFNode involvedOrganizationName = soln.get("involvedOrganizationName");
if(involvedOrganizationName != null){
propertyValues.append(" " + involvedOrganizationName.toString());
}else{
log.debug("involvedOrganizationName is null ");
}
RDFNode positionForPerson = soln.get("positionForPerson");
if(positionForPerson != null){
propertyValues.append(" " + positionForPerson.toString());
}else{
log.debug("positionForPerson is null ");
}
RDFNode positionInOrganization = soln.get("positionInOrganization");
if(positionInOrganization != null){
propertyValues.append(" " + positionInOrganization.toString());
}else{
log.debug("positionInOrganization is null ");
}
RDFNode titleOrRole = soln.get("titleOrRole");
if(titleOrRole != null){
propertyValues.append(" " + titleOrRole.toString());
}else{
log.debug("titleOrRole is null ");
}
/*RDFNode positionLabel = soln.get("positionLabel");
if(positionLabel != null){
propertyValues.append(" " + positionLabel.toString());
}else{
log.debug("positionLabel is null ");
}*/
}
}catch(Throwable t){
log.error(t,t);
} finally{
qExec.close();
}
}finally{
fullModel.leaveCriticalSection();
}
return propertyValues.toString();
}
public String getPropertiesAssociatedWithRelationship(String uri){
StringBuffer propertyValues = new StringBuffer();
QuerySolutionMap initialBinding = new QuerySolutionMap();
Resource uriResource = ResourceFactory.createResource(uri);
initialBinding.add("uri", uriResource);
String thisQuery = prefix +
"SELECT (str(?Advisee) as ?advisee) (str(?DegreeCandidacy) as ?degreeCandidacy) " +
" (str(?LinkedAuthor) as ?linkedAuthor) (str(?LinkedInformationResource) as ?linkedInformationResource) WHERE {"
+ "?uri rdf:type foaf:Agent ; ?b ?c . "
+ " ?c rdf:type core:Relationship . "
+ " OPTIONAL { ?c core:advisee ?d . ?d rdfs:label ?Advisee . } . "
+ " OPTIONAL { ?c core:degreeCandidacy ?e . ?e rdfs:label ?DegreeCandidacy . } ."
+ " OPTIONAL { ?c core:linkedAuthor ?f . ?f rdfs:label ?LinkedAuthor . } . "
+ " OPTIONAL { ?c core:linkedInformationResource ?h . ?h rdfs:label ?LinkedInformationResource . } . "
+ " } ";
Query sparqlQuery = QueryFactory.create(thisQuery, Syntax.syntaxARQ);
fullModel.enterCriticalSection(Lock.READ);
try{
QueryExecution qExec = QueryExecutionFactory.create(sparqlQuery, fullModel, initialBinding);
try{
ResultSet results = qExec.execSelect();
while(results.hasNext()){
QuerySolution soln = results.nextSolution();
RDFNode advisee = soln.get("advisee");
if(advisee != null){
propertyValues.append(" " + advisee.toString());
}else{
log.debug("advisee is null ");
}
RDFNode degreeCandidacy = soln.get("degreeCandidacy");
if(degreeCandidacy != null){
propertyValues.append(" " + degreeCandidacy.toString());
}else{
log.debug("degreeCandidacy is null ");
}
RDFNode linkedAuthor = soln.get("linkedAuthor");
if(linkedAuthor != null){
propertyValues.append(" " + linkedAuthor.toString());
}else{
log.debug("linkedAuthor is null ");
}
RDFNode linkedInformationResource = soln.get("linkedInformationResource");
if(linkedInformationResource != null){
propertyValues.append(" " + linkedInformationResource.toString());
}else{
log.debug("linkedInformationResource is null ");
}
}
}catch(Throwable t){
log.error(t,t);
} finally{
qExec.close();
}
}finally{
fullModel.leaveCriticalSection();
}
return propertyValues.toString();
}
public String getPropertiesAssociatedWithAwardReceipt(String uri){
StringBuffer propertyValues = new StringBuffer();
QuerySolutionMap initialBinding = new QuerySolutionMap();
Resource uriResource = ResourceFactory.createResource(uri);
initialBinding.add("uri", uriResource);
String thisQuery = prefix +
"SELECT (str(?AwardConferredBy) as ?awardConferredBy) (str(?AwardOrHonorFor) as ?awardOrHonorFor) " +
" (str(?Description) as ?description) WHERE {" //(str(?AwardReceiptLabel) as ?awardReceiptLabel)
+ "?uri rdf:type foaf:Agent ; ?b ?c . "
+ " ?c rdf:type core:AwardReceipt . "
+ " OPTIONAL { ?c core:awardConferredBy ?d . ?d rdfs:label ?AwardConferredBy } . "
+ " OPTIONAL { ?c core:awardOrHonorFor ?e . ?e rdfs:label ?AwardOrHonorFor } ."
+ " OPTIONAL { ?c core:description ?Description . } . "
//+ " OPTIONAL { ?c rdfs:label ?AwardReceiptLabel . } . "
+ " } ORDER BY ?AwardReceiptLabel";
Query sparqlQuery = QueryFactory.create(thisQuery, Syntax.syntaxARQ);
fullModel.enterCriticalSection(Lock.READ);
try{
QueryExecution qExec = QueryExecutionFactory.create(sparqlQuery, fullModel, initialBinding);
try{
ResultSet results = qExec.execSelect();
while(results.hasNext()){
QuerySolution soln = results.nextSolution();
RDFNode awardConferredBy = soln.get("awardConferredBy");
if(awardConferredBy != null){
propertyValues.append(" " + awardConferredBy.toString());
}else{
log.debug("awardConferredBy is null ");
}
RDFNode awardOrHonorFor = soln.get("awardOrHonorFor");
if(awardOrHonorFor != null){
propertyValues.append(" " + awardOrHonorFor.toString());
}else{
log.debug("awardOrHonorFor is null ");
}
RDFNode description = soln.get("description");
if(description != null){
propertyValues.append(" " + description.toString());
}else{
log.debug("description is null ");
}
/*RDFNode awardReceiptLabel = soln.get("awardReceiptLabel");
if(awardReceiptLabel != null){
propertyValues.append(" " + awardReceiptLabel.toString());
}else{
log.debug("awardReceiptLabel is null ");
}*/
}
}catch(Throwable t){
log.error(t,t);
} finally{
qExec.close();
}
}finally{
fullModel.leaveCriticalSection();
}
return propertyValues.toString();
}
public String getPropertiesAssociatedWithRole(String uri){
StringBuffer propertyValues = new StringBuffer();
QuerySolutionMap initialBinding = new QuerySolutionMap();
Resource uriResource = ResourceFactory.createResource(uri);
initialBinding.add("uri", uriResource);
String thisQuery = prefix +
"SELECT DISTINCT (str(?OrganizationLabel) as ?organizationLabel) WHERE {"
+ "?uri rdf:type foaf:Agent ; ?b ?c . "
+ " ?c rdf:type core:Role ; core:roleIn ?Organization ."
+ " ?Organization rdfs:label ?OrganizationLabel . "
+ " } ORDER BY ?OrganizationLabel ";
Query sparqlQuery = QueryFactory.create(thisQuery, Syntax.syntaxARQ);
fullModel.enterCriticalSection(Lock.READ);
try{
QueryExecution qExec = QueryExecutionFactory.create(sparqlQuery, fullModel, initialBinding);
try{
ResultSet results = qExec.execSelect();
while(results.hasNext()){
QuerySolution soln = results.nextSolution();
RDFNode organizationLabel = soln.get("organizationLabel");
if(organizationLabel != null){
propertyValues.append(" " + organizationLabel.toString());
}else{
log.warn("organizationLabel is null ");
}
}
}catch(Throwable t){
log.error(t,t);
} finally{
qExec.close();
}
}finally{
fullModel.leaveCriticalSection();
}
return propertyValues.toString();
}
public String getPropertiesAssociatedWithEducationalTraining(String uri){
StringBuffer propertyValues = new StringBuffer();
QuerySolutionMap initialBinding = new QuerySolutionMap();
Resource uriResource = ResourceFactory.createResource(uri);
initialBinding.add("uri", uriResource);
String thisQuery = prefix +
"SELECT (str(?AcademicDegreeLabel) as ?academicDegreeLabel) (str(?AcademicDegreeAbbreviation) as ?academicDegreeAbbreviation) "
+ "(str(?MajorField) as ?majorField) (str(?DepartmentOrSchool) as ?departmentOrSchool) " +
"(str(?TrainingAtOrganizationLabel) as ?trainingAtOrganizationLabel) WHERE {"
+ " ?uri rdf:type foaf:Agent ; ?b ?c . "
+ " ?c rdf:type core:EducationalTraining . "
+ "OPTIONAL { ?c core:degreeEarned ?d . ?d rdfs:label ?AcademicDegreeLabel ; core:abbreviation ?AcademicDegreeAbbreviation . } . "
+ "OPTIONAL { ?c core:majorField ?MajorField .} ."
+ " OPTIONAL { ?c core:departmentOrSchool ?DepartmentOrSchool . }"
+ " OPTIONAL { ?c core:trainingAtOrganization ?e . ?e rdfs:label ?TrainingAtOrganizationLabel . } . "
+"}";
Query sparqlQuery = QueryFactory.create(thisQuery, Syntax.syntaxARQ);
fullModel.enterCriticalSection(Lock.READ);
try{
QueryExecution qExec = QueryExecutionFactory.create(sparqlQuery, fullModel, initialBinding);
try{
ResultSet results = qExec.execSelect();
while(results.hasNext()){
QuerySolution soln = results.nextSolution();
RDFNode academicDegreeLabel = soln.get("academicDegreeLabel");
if(academicDegreeLabel != null){
propertyValues.append(" " + academicDegreeLabel.toString());
}else{
log.debug("academicDegreeLabel is null ");
}
RDFNode academicDegreeAbbreviation = soln.get("academicDegreeAbbreviation");
if(academicDegreeAbbreviation != null){
propertyValues.append(" " + academicDegreeAbbreviation.toString());
}else{
log.debug("academicDegreeAbbreviation is null ");
}
RDFNode majorField = soln.get("majorField");
if(majorField != null){
propertyValues.append(" " + majorField.toString());
}else{
log.debug("majorField is null ");
}
RDFNode trainingAtDepartmentOrSchool = soln.get("departmentOrSchool");
if(trainingAtDepartmentOrSchool != null){
propertyValues.append(" " + trainingAtDepartmentOrSchool.toString());
}else{
log.debug("trainingAtDepartmentOrSchool is null ");
}
RDFNode trainingAtOrganizationLabel = soln.get("trainingAtOrganizationLabel");
if(trainingAtOrganizationLabel != null){
propertyValues.append(" " + trainingAtOrganizationLabel.toString());
}else{
log.debug("trainingAtOrganizationLabel is null ");
}
}
}catch(Throwable t){
log.error(t,t);
} finally{
qExec.close();
}
}finally{
fullModel.leaveCriticalSection();
}
return propertyValues.toString();
}
public String getPropertiesAssociatedWithInformationResource(String uri){
StringBuffer propertyValues = new StringBuffer();
QuerySolutionMap initialBinding = new QuerySolutionMap();
Resource uriResource = ResourceFactory.createResource(uri);
initialBinding.add("uri", uriResource);
String thisQuery = prefix +
"SELECT (str(?LinkedAuthor) as ?linkedAuthor) (str(?LinkedInformationResource) as ?linkedInformationResource) "
+ "(str(?Editor) as ?editor) (str(?SubjectArea) as ?subjectArea) (str(?ResearchAreaOf) as ?researchAreaOf) " +
"(str(?Features) as ?features) WHERE {"
+ " ?uri rdf:type core:InformationResource . "
+ "OPTIONAL { ?uri core:informationResourceInAuthorship ?a . ?a core:linkedAuthor ?b ; core:linkedInformationResource ?d ." +
"?b rdfs:label ?LinkedAuthor . ?d rdfs:label ?LinkedInformationResource } . "
+ "OPTIONAL { ?uri bibo:editor ?e . ?e rdfs:label ?Editor . } ."
+ " OPTIONAL { ?uri core:hasSubjectArea ?f . ?f rdfs:label ?SubjectArea ; core:researchAreaOf ?h . ?h rdfs:label ?ResearchAreaOf . } "
+ " OPTIONAL { ?uri core:features ?i . ?i rdfs:label ?Features . } . "
+"}";
Query sparqlQuery = QueryFactory.create(thisQuery, Syntax.syntaxARQ);
fullModel.enterCriticalSection(Lock.READ);
try{
QueryExecution qExec = QueryExecutionFactory.create(sparqlQuery, fullModel, initialBinding);
try{
ResultSet results = qExec.execSelect();
while(results.hasNext()){
QuerySolution soln = results.nextSolution();
RDFNode linkedAuthor = soln.get("linkedAuthor");
if(linkedAuthor != null){
propertyValues.append(" publications " + linkedAuthor.toString() + " publications ");
}else{
log.debug("linkedAuthor is null ");
}
RDFNode linkedInformationResource = soln.get("linkedInformationResource");
if(linkedInformationResource != null){
propertyValues.append(" " + linkedInformationResource.toString());
}else{
log.debug("linkedInformationResource is null ");
}
RDFNode editor = soln.get("editor");
if(editor != null){
propertyValues.append(" " + editor.toString());
}else{
log.debug("editor is null ");
}
RDFNode subjectArea = soln.get("subjectArea");
if(subjectArea != null){
propertyValues.append(" " + subjectArea.toString());
}else{
log.debug("subjectArea is null ");
}
RDFNode researchAreaOf = soln.get("researchAreaOf");
if(researchAreaOf != null){
propertyValues.append(" " + researchAreaOf.toString());
}else{
log.debug("researchAreaOf is null ");
}
RDFNode features = soln.get("features");
if(features != null){
propertyValues.append(" publications " + features.toString() + " publications ");
}else{
log.debug("features is null ");
}
}
}catch(Throwable t){
log.error(t,t);
} finally{
qExec.close();
}
}finally{
fullModel.leaveCriticalSection();
}
return propertyValues.toString();
}
public String[] getAdjacentNodes(String uri,boolean isPerson){
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 <http://vivoweb.org/ontology/core#InformationResource> . " +
" ?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 <http://vivoweb.org/ontology/core#InformationResource> . } " +
" 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();
fullModel.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,fullModel,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){
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){
log.error(t,t);
}finally{
fullModel.leaveCriticalSection();
adjacentNodes = null;
adjacentNodesConcat = null;
coauthorBuff = null;
}
return info;
}
}

View file

@ -23,7 +23,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.search.IndexingException;
import edu.cornell.mannlib.vitro.webapp.search.beans.SearchQueryHandler;
import edu.cornell.mannlib.vitro.webapp.search.beans.IndividualProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.search.docbuilder.Obj2DocIface;
@ -113,8 +113,6 @@ public class Entity2LuceneDoc implements Obj2DocIface{
private ProhibitedFromSearch classesProhibitedFromSearch;
private IndividualProhibitedFromSearch individualProhibited;
private SearchQueryHandler searchQueryHandler;
private static HashMap<String, String> IndividualURIToObjectProperties = new HashMap<String, String>();
@ -122,10 +120,9 @@ public class Entity2LuceneDoc implements Obj2DocIface{
public Entity2LuceneDoc(
ProhibitedFromSearch classesProhibitedFromSearch,
IndividualProhibitedFromSearch individualProhibited, SearchQueryHandler searchQueryHandler){
IndividualProhibitedFromSearch individualProhibited){
this.classesProhibitedFromSearch = classesProhibitedFromSearch;
this.individualProhibited = individualProhibited;
this.searchQueryHandler = searchQueryHandler;
}
public boolean canTranslate(Object obj) {

View file

@ -42,7 +42,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.SearchReindexingListener;
import edu.cornell.mannlib.vitro.webapp.search.beans.IndividualProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.search.beans.ObjectSourceIface;
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.search.beans.SearchQueryHandler;
import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup;
@ -119,8 +119,7 @@ public class LuceneSetup implements javax.servlet.ServletContextListener {
OntModel displayOntModel = (OntModel) sce.getServletContext().getAttribute("displayOntModel");
Entity2LuceneDoc translator = new Entity2LuceneDoc(
new ProhibitedFromSearch(DisplayVocabulary.PRIMARY_LUCENE_INDEX_URI, displayOntModel),
new IndividualProhibitedFromSearch(context),
new SearchQueryHandler(DisplayVocabulary.CONTEXT_NODES_URI, displayOntModel, context)
new IndividualProhibitedFromSearch(context)
);
indexer.addObj2Doc(translator);

View file

@ -27,7 +27,6 @@ import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilterUtils;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
import edu.cornell.mannlib.vitro.webapp.dao.jena.SearchReindexingListener;
import edu.cornell.mannlib.vitro.webapp.search.beans.SearchQueryHandler;
import edu.cornell.mannlib.vitro.webapp.search.beans.IndividualProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
@ -93,8 +92,8 @@ public class LuceneSetupCJK implements javax.servlet.ServletContextListener {
OntModel displayOntModel = (OntModel) sce.getServletContext().getAttribute("displayOntModel");
Entity2LuceneDoc translator = new Entity2LuceneDoc(
new ProhibitedFromSearch(DisplayVocabulary.PRIMARY_LUCENE_INDEX_URI, displayOntModel),
new IndividualProhibitedFromSearch(context),
new SearchQueryHandler(DisplayVocabulary.CONTEXT_NODES_URI, displayOntModel, context));
new IndividualProhibitedFromSearch(context)
);
indexer.addObj2Doc(translator);
indexer.setLuceneIndexFactory(lif);

View file

@ -33,7 +33,7 @@ import com.hp.hpl.jena.ontology.OntModel;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.search.VitroTermNames;
import edu.cornell.mannlib.vitro.webapp.search.beans.SearchQueryHandler;
public class CalculateParameters implements DocumentModifier {
@ -270,8 +270,11 @@ public class CalculateParameters implements DocumentModifier {
for(String term: fieldsToMultiplyBetaBy){
SolrInputField f = doc.getField( term );
f.setBoost( getBeta(uri)*phi*IndividualToSolrDocument.ALL_TEXT_BOOST);
f.addValue(info.toString(),getBeta(uri)*phi*IndividualToSolrDocument.ALL_TEXT_BOOST);
}
SolrInputField f = doc.getField(VitroTermNames.targetInfo);
f.addValue(adjInfo[1],f.getBoost());
doc.setDocumentBoost(getBeta(uri)*phi*IndividualToSolrDocument.ALL_TEXT_BOOST);
}

View file

@ -24,6 +24,7 @@ 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.VitroTermNames;
import edu.cornell.mannlib.vitro.webapp.search.lucene.Entity2LuceneDoc.VitroLuceneTermNames;
public class ContextNodeFields implements DocumentModifier{
@ -49,22 +50,25 @@ public class ContextNodeFields implements DocumentModifier{
@Override
public void modifyDocument(Individual individual, SolrInputDocument doc) {
SolrInputField field = doc.getField(VitroLuceneTermNames.ALLTEXT);
SolrInputField field = doc.getField(VitroTermNames.ALLTEXT);
SolrInputField targetField = doc.getField(VitroTermNames.targetInfo);
StringBuffer objectProperties = new StringBuffer();
objectProperties.append(" ");
objectProperties.append(getPropertiesAssociatedWithEducationalTraining(individual.getURI()));
objectProperties.append(" ");
objectProperties.append(getPropertiesAssociatedWithRole(individual.getURI()));
objectProperties.append(" ");
objectProperties.append(getPropertiesAssociatedWithPosition(individual.getURI()));
objectProperties.append(" ");
objectProperties.append(getPropertiesAssociatedWithRelationship(individual.getURI()));
objectProperties.append(" ");
objectProperties.append(getPropertiesAssociatedWithAwardReceipt(individual.getURI()));
objectProperties.append(" ");
objectProperties.append(getPropertiesAssociatedWithInformationResource(individual.getURI()));
if(IndividualToSolrDocument.superClassNames.contains("Agent")){
objectProperties.append(" ");
objectProperties.append(getPropertiesAssociatedWithEducationalTraining(individual.getURI()));
objectProperties.append(" ");
objectProperties.append(getPropertiesAssociatedWithRole(individual.getURI()));
objectProperties.append(" ");
objectProperties.append(getPropertiesAssociatedWithPosition(individual.getURI()));
objectProperties.append(" ");
objectProperties.append(getPropertiesAssociatedWithRelationship(individual.getURI()));
objectProperties.append(" ");
objectProperties.append(getPropertiesAssociatedWithAwardReceipt(individual.getURI()));
}
if(IndividualToSolrDocument.superClassNames.contains("InformationResource")){
targetField.addValue(" " + getPropertiesAssociatedWithInformationResource(individual.getURI()), targetField.getBoost());
}
field.addValue(objectProperties, field.getBoost());

View file

@ -32,7 +32,6 @@ import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.search.IndexingException;
import edu.cornell.mannlib.vitro.webapp.search.VitroTermNames;
import edu.cornell.mannlib.vitro.webapp.search.beans.SearchQueryHandler;
import edu.cornell.mannlib.vitro.webapp.search.beans.IndividualProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.search.docbuilder.Obj2DocIface;
@ -51,8 +50,6 @@ public class IndividualToSolrDocument implements Obj2DocIface {
private IndividualProhibitedFromSearch individualProhibitedFromSearch;
private SearchQueryHandler searchQueryHandler;
public static ArrayList<String> superClassNames = null;
public static StringBuffer addUri = null;
@ -62,19 +59,16 @@ public class IndividualToSolrDocument implements Obj2DocIface {
private static List<String> contextNodeClassNames = new ArrayList<String>();
public IndividualToSolrDocument(ProhibitedFromSearch classesProhibitedFromSearch,
IndividualProhibitedFromSearch individualProhibitedFromSearch,
SearchQueryHandler searchQueryHandler){
this(classesProhibitedFromSearch,individualProhibitedFromSearch,searchQueryHandler,null);
IndividualProhibitedFromSearch individualProhibitedFromSearch){
this(classesProhibitedFromSearch,individualProhibitedFromSearch,null);
}
public IndividualToSolrDocument(ProhibitedFromSearch classesProhibitedFromSearch,
IndividualProhibitedFromSearch individualProhibitedFromSearch,
SearchQueryHandler searchQueryHandler,
List<DocumentModifier> docModifiers){
this.classesProhibitedFromSearch = classesProhibitedFromSearch;
this.individualProhibitedFromSearch = individualProhibitedFromSearch;
this.documentModifiers = docModifiers;
this.searchQueryHandler = searchQueryHandler;
fillContextNodes();
}
@ -230,10 +224,9 @@ public class IndividualToSolrDocument implements Obj2DocIface {
// collecting context node information
StringBuffer targetInfo = new StringBuffer();
targetInfo.append("");
doc.addField(term.targetInfo, targetInfo.toString() + adjInfo[1]);
log.debug("time to fire contextnode queries and include them in the index: " + Long.toString(System.currentTimeMillis() - tContextNodes));
@ -298,6 +291,7 @@ public class IndividualToSolrDocument implements Obj2DocIface {
//run the document modifiers
if( documentModifiers != null ){
doc.addField(term.targetInfo,"");
for(DocumentModifier modifier: documentModifiers){
modifier.modifyDocument(ent, doc);
}

View file

@ -136,8 +136,8 @@ public class SolrIndexer implements IndexerIface {
} catch (Exception e) {
log.error("Could not commit to solr server", e);
}finally{
IndividualToSolrDocument.betas.clear();
IndividualToSolrDocument.betas = null;
CalculateParameters.betaMap.clear();
CalculateParameters.betaMap = null;
}
try {

View file

@ -23,7 +23,6 @@ import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilterUtils;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
import edu.cornell.mannlib.vitro.webapp.dao.jena.SearchReindexingListener;
import edu.cornell.mannlib.vitro.webapp.search.beans.SearchQueryHandler;
import edu.cornell.mannlib.vitro.webapp.search.beans.IndividualProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.search.beans.ObjectSourceIface;
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
@ -70,15 +69,12 @@ public class SolrSetup implements javax.servlet.ServletContextListener{
OntModel displayOntModel = (OntModel) sce.getServletContext().getAttribute("displayOntModel");
List<DocumentModifier> modifiers = new ArrayList<DocumentModifier>();
CalculateBeta betas = new CalculateBeta(ModelContext.getJenaOntModel(context));
modifiers.add( new CalculateBeta(ModelContext.getJenaOntModel(context)));
modifiers.add( new CalculatePhi(betas));
modifiers.add( new ContextNodeFields() );
modifiers.add(new CalculateParameters(ModelContext.getJenaOntModel(context)));
modifiers.add(new ContextNodeFields(ModelContext.getJenaOntModel(context)));
IndividualToSolrDocument indToSolrDoc = new IndividualToSolrDocument(
new ProhibitedFromSearch(DisplayVocabulary.PRIMARY_LUCENE_INDEX_URI, displayOntModel),
new IndividualProhibitedFromSearch(context),
new SearchQueryHandler(DisplayVocabulary.CONTEXT_NODES_URI, displayOntModel, context),
modifiers);
List<Obj2DocIface> o2d = new ArrayList<Obj2DocIface>();
o2d.add(indToSolrDoc);