From ef25ee4dd6773f5d68c69001765b5ad58121f94f Mon Sep 17 00:00:00 2001 From: j2blake Date: Wed, 6 Nov 2013 09:23:43 -0500 Subject: [PATCH 1/3] Make it easier to monitor the ABoxReasoner thread. --- .../vitro/webapp/servlet/setup/SimpleReasonerSetup.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/SimpleReasonerSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/SimpleReasonerSetup.java index 4256de861..6d99d4c52 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/SimpleReasonerSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/SimpleReasonerSetup.java @@ -33,6 +33,7 @@ import edu.cornell.mannlib.vitro.webapp.reasoner.ReasonerPlugin; import edu.cornell.mannlib.vitro.webapp.reasoner.SimpleReasoner; import edu.cornell.mannlib.vitro.webapp.reasoner.SimpleReasonerTBoxListener; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; +import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread; public class SimpleReasonerSetup implements ServletContextListener { @@ -121,7 +122,7 @@ public class SimpleReasonerSetup implements ServletContextListener { simpleReasoner.recompute(); } else if (RecomputeMode.BACKGROUND.equals(mode)) { log.info("starting ABox inference recompute in a separate thread."); - new Thread( + new VitroBackgroundThread( new ABoxRecomputer( simpleReasoner),"ABoxRecomputer").start(); } From 7f67b1b7daf0319c199a5babbb2c5ed0b745a741 Mon Sep 17 00:00:00 2001 From: j2blake Date: Wed, 6 Nov 2013 11:43:33 -0500 Subject: [PATCH 2/3] VIVO-495 fix bug in query-binding code. --- .../shortview/FakeApplicationOntologyService.java | 2 +- .../utils/dataGetter/SparqlQueryDataGetter.java | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/services/shortview/FakeApplicationOntologyService.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/services/shortview/FakeApplicationOntologyService.java index 8096c799c..92fcc8ae7 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/services/shortview/FakeApplicationOntologyService.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/services/shortview/FakeApplicationOntologyService.java @@ -442,7 +442,7 @@ public class FakeApplicationOntologyService { private static String QUERY_STRING = "" + "PREFIX obo: \n" + "PREFIX vcard: \n" - + "SELECT ?uri ?pt \n" + "WHERE { \n" + + "SELECT ?pt \n" + "WHERE { \n" + " ?uri obo:ARG_2000028 ?vIndividual . \n" + " ?vIndividual vcard:hasTitle ?vTitle . \n" + " ?vTitle vcard:title ?pt . \n" + "} LIMIT 1"; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SparqlQueryDataGetter.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SparqlQueryDataGetter.java index e7ded50e9..341e2e030 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SparqlQueryDataGetter.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SparqlQueryDataGetter.java @@ -148,6 +148,10 @@ public class SparqlQueryDataGetter extends DataGetterBase implements DataGetter{ for (String key: pageData.keySet()) { merged.put(key, String.valueOf(pageData.get(key))); } + if (log.isDebugEnabled()) { + log.debug("Merging request parameters " + parameterMap + + " with page data " + pageData + " results in " + merged); + } return merged; } @@ -161,9 +165,13 @@ public class SparqlQueryDataGetter extends DataGetterBase implements DataGetter{ private String bindParameters(String text, Map merged) { String bound = text; for (String key : merged.keySet()) { - bound.replace('?' + key, '<' + merged.get(key) + '>'); + bound = bound.replace('?' + key, '<' + merged.get(key) + '>'); + } + if (log.isDebugEnabled()) { + log.debug("parameters: " + merged); + log.debug("query before binding parameters:" + text); + log.debug("query after binding parameters: " + bound); } - log.debug("query after binding parameters: " + bound); return bound; } From 98f80dfd7115223141bb5a97993bc953b92a3c5c Mon Sep 17 00:00:00 2001 From: j2blake Date: Wed, 6 Nov 2013 12:26:59 -0500 Subject: [PATCH 3/3] VIVO-483 Adjust indexing code for the ISF This class should not have been in Vitro, since it uses VIVO URIs and is never referenced in Vitro. Also, it needed updating to match the ISF. --- .../documentBuilding/CalculateParameters.java | 300 ------------------ 1 file changed, 300 deletions(-) delete mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/CalculateParameters.java diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/CalculateParameters.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/CalculateParameters.java deleted file mode 100644 index 0ae3eca19..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/CalculateParameters.java +++ /dev/null @@ -1,300 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.StringTokenizer; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.solr.common.SolrInputDocument; -import org.apache.solr.common.SolrInputField; - -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; - - -public class CalculateParameters implements DocumentModifier { - - private boolean shutdown = false; - private Dataset dataset; - // public static int totalInd=1; - - private static final String prefix = "prefix owl: " - + " prefix vitroDisplay: " - + " prefix rdf: " - + " prefix core: " - + " prefix foaf: " - + " prefix rdfs: " - + " prefix localNav: " - + " prefix 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 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 queryList = new ArrayList(); - Set adjacentNodes = new HashSet(); - Set coauthorNames = new HashSet(); - 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 . " + - " ?uri ?prop ?obj . " + - " ?obj rdf:type . " + - " ?obj ?prop2 ?obj2 . " + - " ?obj2 rdf:type . " + - " ?obj2 ?prop3 ?obj3 . " + - " ?obj3 rdf:type . " + - " ?obj3 ?prop4 ?adjobj . " + - " ?adjobj rdfs:label ?adjobjLabel . " + - " ?adjobj rdf:type . " + - - " 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 . } " + - " UNION " + - " { ?adjobj rdf:type . } " + - " UNION " + - " { ?adjobj rdf:type . } " + - " UNION " + - " { ?adjobj rdf:type . } ." + - "}"); - - Query query; - - QuerySolution soln; - QuerySolutionMap initialBinding = new QuerySolutionMap(); - Resource uriResource = ResourceFactory.createResource(uri); - - initialBinding.add("uri", uriResource); - - Iterator 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 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 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(); - } - - } -}