Adding ability to hide classes in search. NIHVIVO-643. Adding ability to have n3 files in ontology directories.

This commit is contained in:
bdc34 2010-07-02 00:24:15 +00:00
parent 28d5c6e672
commit ec7a7c23a8
7 changed files with 338 additions and 29 deletions

View file

@ -0,0 +1,135 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.search.beans;
import java.util.ArrayList;
import java.util.List;
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.rdf.listeners.StatementListener;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelChangedListener;
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.rdf.model.StmtIterator;
import com.hp.hpl.jena.shared.Lock;
import edu.cornell.mannlib.vitro.webapp.web.DisplayVocabulary;
public class ProhibitedFromSearch {
List<String> prohibitedClasses;
String ProhibitedFromSearchURI;
private static final String queryForProhibitedClasses = "SELECT ?prohibited WHERE{" +
"?searchConfig <" + DisplayVocabulary.EXCLUDE_CLASS + "> ?prohibited . }";
private static final Log log = LogFactory.getLog(ProhibitedFromSearch.class.getName());
public ProhibitedFromSearch(String URI, OntModel model){
this.ProhibitedFromSearchURI = URI;
this.prohibitedClasses = new ArrayList<String>();
addAllProhibitedClasses( buildProhibitedClassesList(URI,model) );
model.register(new ProhibitedFromSearchChangeListener( this ));
}
public synchronized boolean isClassProhibited(String classURI){
if( classURI != null ){
return prohibitedClasses.contains(classURI);
}else{
return false;
}
}
private synchronized void removeProhibitedClass(String classURI){
prohibitedClasses.remove(classURI);
}
private synchronized void addProhibitedClass(String classURI){
prohibitedClasses.add(classURI);
}
private synchronized void addAllProhibitedClasses(List<String> classURIs){
prohibitedClasses.addAll(classURIs);
}
private List<String> buildProhibitedClassesList( String URI, OntModel model){
List<String> newProhibitedClasses = new ArrayList<String>();
QuerySolutionMap initialBinding = new QuerySolutionMap();
Resource searchConfig = ResourceFactory.createResource(URI);
initialBinding.add("searchConfig", searchConfig);
Query query = QueryFactory.create(queryForProhibitedClasses);
model.enterCriticalSection(Lock.READ);
try{
QueryExecution qExec = QueryExecutionFactory.create(query,model,initialBinding);
try{
ResultSet results = qExec.execSelect();
for(;results.hasNext();){
QuerySolution soln = results.nextSolution();
RDFNode n = soln.get("prohibited");
if( n.isResource() && !n.isAnon()){
newProhibitedClasses.add(((Resource) n).getURI());
}else{
log.warn("unexpected node in object position for prohibited classes: " + n.toString());
}
}
}catch(Throwable t){
log.error(t,t);
}finally{ qExec.close(); }
}finally{ model.leaveCriticalSection(); }
return newProhibitedClasses;
}
private static enum ChangeType { ADD, REMOVE } ;
class ProhibitedFromSearchChangeListener extends StatementListener {
ProhibitedFromSearch pfs;
ProhibitedFromSearchChangeListener(ProhibitedFromSearch pfs){
this.pfs = pfs;
}
@Override
public void addedStatement(Statement s) { processChange(s,ChangeType.ADD);}
@Override
public void removedStatement(Statement s) { processChange(s,ChangeType.REMOVE); }
private void processChange( Statement s, ChangeType add){
//is it a change to an exclude class property?
if( s != null && s.getPredicate() != null
&& s.getPredicate().getURI() != null
&& s.getPredicate().getURI().equals(DisplayVocabulary.EXCLUDE_CLASS.getURI())){
//is it about this ProhibitedFromSearch?
if( s.getSubject() != null ){
String subURI = ((Resource) s.getSubject()).getURI() ;
if( subURI != null && subURI.equals( ProhibitedFromSearchURI )){
if( s.getObject() != null && s.getObject().canAs(Resource.class)){
String classURI = ((Resource)s.getObject().as(Resource.class)).getURI();
if( add == ChangeType.ADD )
pfs.addProhibitedClass(classURI);
else
pfs.removeProhibitedClass(classURI);
}
}
}
}
}
}
}

View file

@ -20,11 +20,12 @@ import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.search.IndexingException; import edu.cornell.mannlib.vitro.webapp.search.IndexingException;
import edu.cornell.mannlib.vitro.webapp.search.beans.ObjectSourceIface; import edu.cornell.mannlib.vitro.webapp.search.beans.ObjectSourceIface;
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
/** /**
* The IndexBuilder is used to rebuild or update a search index. * The IndexBuilder is used to rebuild or update a search index.
* It uses an implementation of a backend through an object that * It uses an implementation of a back-end through an object that
* implements IndexerIface. An example of a backend is LuceneIndexer. * implements IndexerIface. An example of a back-end is LuceneIndexer.
* *
* The IndexBuilder implements the EntityChangeListener so it can * The IndexBuilder implements the EntityChangeListener so it can
* be registered for Entity changes from the GenericDB classes. * be registered for Entity changes from the GenericDB classes.
@ -42,6 +43,7 @@ public class IndexBuilder implements Runnable {
List<ObjectSourceIface> sourceList = new LinkedList<ObjectSourceIface>(); List<ObjectSourceIface> sourceList = new LinkedList<ObjectSourceIface>();
IndexerIface indexer = null; IndexerIface indexer = null;
ServletContext context = null; ServletContext context = null;
ProhibitedFromSearch classesProhibitedFromSearch = null;
long lastRun = 0; long lastRun = 0;
List<String> changedUris = null; List<String> changedUris = null;
@ -256,8 +258,17 @@ public class IndexBuilder implements Runnable {
return; return;
if( ind.getVClasses() == null || ind.getVClasses().size() < 1 ) if( ind.getVClasses() == null || ind.getVClasses().size() < 1 )
return; return;
boolean prohibitedClass = false;
indexer.index(ind, newDoc); if( classesProhibitedFromSearch != null ){
for( VClass vclass : ind.getVClasses() ){
if( classesProhibitedFromSearch.isClassProhibited(vclass.getURI()) ){
prohibitedClass = true;
break;
}
}
}
if( !prohibitedClass )
indexer.index(ind, newDoc);
}catch(Throwable ex){ }catch(Throwable ex){
log.debug("IndexBuilder.indexItem() Error indexing " log.debug("IndexBuilder.indexItem() Error indexing "
+ ind + "\n" +ex); + ind + "\n" +ex);
@ -317,4 +328,13 @@ public class IndexBuilder implements Runnable {
return getAllOfThisTypeIterator(); return getAllOfThisTypeIterator();
} }
} }
public ProhibitedFromSearch getClassesProhibitedFromSearch() {
return classesProhibitedFromSearch;
}
public void setClassesProhibitedFromSearch(
ProhibitedFromSearch classesProhibitedFromSearch) {
this.classesProhibitedFromSearch = classesProhibitedFromSearch;
}
} }

View file

@ -30,8 +30,10 @@ import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilterUtils; 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.filtering.filters.VitroFilters;
import edu.cornell.mannlib.vitro.webapp.dao.jena.SearchReindexingListener; import edu.cornell.mannlib.vitro.webapp.dao.jena.SearchReindexingListener;
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.search.beans.Searcher; import edu.cornell.mannlib.vitro.webapp.search.beans.Searcher;
import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder; import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
import edu.cornell.mannlib.vitro.webapp.web.DisplayVocabulary;
/** /**
* Setup objects for lucene searching and indexing. * Setup objects for lucene searching and indexing.
@ -123,6 +125,11 @@ public class LuceneSetup implements javax.servlet.ServletContextListener {
baseOntModel.getBaseModel().register(srl); baseOntModel.getBaseModel().register(srl);
jenaOntModel.getBaseModel().register(srl); jenaOntModel.getBaseModel().register(srl);
//set the classes that the indexBuilder ignores
OntModel displayOntModel = (OntModel)sce.getServletContext().getAttribute("displayOntModel");
builder.setClassesProhibitedFromSearch(
new ProhibitedFromSearch(DisplayVocabulary.PRIMARY_LUCENE_INDEX_URI, displayOntModel));
log.debug("**** End of "+this.getClass().getName()+".contextInitialized()"); log.debug("**** End of "+this.getClass().getName()+".contextInitialized()");
} catch (Throwable t) { } catch (Throwable t) {
log.error(t); log.error(t);

View file

@ -136,18 +136,30 @@ public class JenaDataSourceSetupBase {
Set<String> paths = ctx.getResourcePaths(path); Set<String> paths = ctx.getResourcePaths(path);
if (paths != null) { if (paths != null) {
for (String p : paths) { for (String p : paths) {
log.info("Loading ontology file at " + p); String format = getRdfFormat(p);
log.info("Loading ontology file at " + p + " as format " + format);
InputStream ontologyInputStream = ctx.getResourceAsStream(p); InputStream ontologyInputStream = ctx.getResourceAsStream(p);
try { try {
model.read(ontologyInputStream, null); model.read(ontologyInputStream, null, format);
log.debug("...successful"); log.debug("...successful");
} catch (Throwable t) { } catch (Throwable t) {
log.error("Failed to load ontology file at '" + p + "'", t); log.error("Failed to load ontology file at '" + p + "' as format " + format, t);
} }
} }
} }
} }
private static String getRdfFormat(String filename){
String defaultformat = "RDF/XML";
if( filename == null )
return defaultformat;
else if( filename.endsWith("n3") )
return "N3";
else if( filename.endsWith("ttl") )
return "TURTLE";
else
return defaultformat;
}
/** /**
* If the {@link ConfigurationProperties} has a name for the initial admin * If the {@link ConfigurationProperties} has a name for the initial admin
* user, create the user and add it to the model. * user, create the user and add it to the model.

View file

@ -3,7 +3,6 @@
package edu.cornell.mannlib.vitro.webapp.web; package edu.cornell.mannlib.vitro.webapp.web;
import com.hp.hpl.jena.ontology.DatatypeProperty; import com.hp.hpl.jena.ontology.DatatypeProperty;
import com.hp.hpl.jena.ontology.Individual;
import com.hp.hpl.jena.ontology.ObjectProperty; import com.hp.hpl.jena.ontology.ObjectProperty;
import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModel;
@ -29,48 +28,58 @@ public class DisplayVocabulary {
/** <p>The namespace of the vocabulary as a resource</p> */ /** <p>The namespace of the vocabulary as a resource</p> */
public static final Resource NAMESPACE = m_model.createResource( NS ); public static final Resource NAMESPACE = m_model.createResource( NS );
public static final ObjectProperty REQUIRES_VALUES = m_model.createObjectProperty( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#requiresValues" ); public static final ObjectProperty REQUIRES_VALUES = m_model.createObjectProperty( NS + "requiresValues" );
public static final ObjectProperty TO_PAGE = m_model.createObjectProperty( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#toPage" ); public static final ObjectProperty TO_PAGE = m_model.createObjectProperty( NS + "toPage" );
public static final ObjectProperty EXCLUDE_CLASS = m_model.createObjectProperty( NS + "excludeClass" );
public static final ObjectProperty INCLUDE_CLASS = m_model.createObjectProperty( NS + "includeClass" );
/** <p>Java package and class name. ex edu.cornell.mannlib.vitro.webapps.functions.ExampleFunction</p> */ /** <p>Java package and class name. ex edu.cornell.mannlib.vitro.webapps.functions.ExampleFunction</p> */
public static final DatatypeProperty JAVA_CLASS_NAME = m_model.createDatatypeProperty( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#javaClassName" ); public static final DatatypeProperty JAVA_CLASS_NAME = m_model.createDatatypeProperty( NS + "javaClassName" );
public static final DatatypeProperty MENU_POSITION = m_model.createDatatypeProperty( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#menuPosition" ); public static final DatatypeProperty MENU_POSITION = m_model.createDatatypeProperty( NS + "menuPosition" );
public static final DatatypeProperty PARAMETER_NAME = m_model.createDatatypeProperty( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#parameterName" ); public static final DatatypeProperty PARAMETER_NAME = m_model.createDatatypeProperty( NS + "parameterName" );
public static final DatatypeProperty PARAMETER_VALUE = m_model.createDatatypeProperty( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#parameterValue" ); public static final DatatypeProperty PARAMETER_VALUE = m_model.createDatatypeProperty( NS + "parameterValue" );
public static final DatatypeProperty REQUIRES_BODY_TEMPLATE = m_model.createDatatypeProperty( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#requiresBodyTemplate" ); public static final DatatypeProperty REQUIRES_BODY_TEMPLATE = m_model.createDatatypeProperty( NS + "requiresBodyTemplate" );
/** <p>Values from HttpRequest.getPathInfo() will be mapped to values from urlMapping.</p> */ /** <p>Values from HttpRequest.getPathInfo() will be mapped to values from urlMapping.</p> */
public static final DatatypeProperty URL_MAPPING = m_model.createDatatypeProperty( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#urlMapping" ); public static final DatatypeProperty URL_MAPPING = m_model.createDatatypeProperty( NS + "urlMapping" );
/** <p>This represents a menu item or other general navigation item.</p> */ /** <p>This represents a menu item or other general navigation item.</p> */
public static final OntClass NAVIGATION_ELEMENT = m_model.createClass( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#NavigationElement" ); public static final OntClass NAVIGATION_ELEMENT = m_model.createClass( NS + "NavigationElement" );
/** <p>Class of pages.</p> */ /** <p>Class of pages.</p> */
public static final OntClass PAGE = m_model.createClass( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#Page" ); public static final OntClass PAGE = m_model.createClass( NS + "Page" );
//public static final Individual EVENTS = m_model.createIndividual( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#Events", PAGE ); /* URIs for some individuals in the dispaly ontology */
public static final String PRIMARY_LUCENE_INDEX_URI = NS + "PrimaryLuceneIndex";
//public static final Individual EVENTS_MENU_ITEM = m_model.createIndividual( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#EventsMenuItem", NAVIGATION_ELEMENT ); //public static final Individual EVENTS = m_model.createIndividual( NS + "Events", PAGE );
//public static final Individual HOME = m_model.createIndividual( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#Home", PAGE ); //public static final Individual EVENTS_MENU_ITEM = m_model.createIndividual( NS + "EventsMenuItem", NAVIGATION_ELEMENT );
//public static final Individual HOME_MENU_ITEM = m_model.createIndividual( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#HomeMenuItem", NAVIGATION_ELEMENT ); //public static final Individual HOME = m_model.createIndividual( NS + "Home", PAGE );
//public static final Individual ORGANIZATIONS = m_model.createIndividual( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#Organizations", PAGE ); //public static final Individual HOME_MENU_ITEM = m_model.createIndividual( NS + "HomeMenuItem", NAVIGATION_ELEMENT );
//public static final Individual ORGANIZATIONS_MENU_ITEM = m_model.createIndividual( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#OrganizationsMenuItem", NAVIGATION_ELEMENT ); //public static final Individual ORGANIZATIONS = m_model.createIndividual( NS + "Organizations", PAGE );
//public static final Individual PEOPLE = m_model.createIndividual( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#People", PAGE ); //public static final Individual ORGANIZATIONS_MENU_ITEM = m_model.createIndividual( NS + "OrganizationsMenuItem", NAVIGATION_ELEMENT );
//public static final Individual PEOPLE_MENU_ITEM = m_model.createIndividual( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#PeopleMenuItem", NAVIGATION_ELEMENT ); //public static final Individual PEOPLE = m_model.createIndividual( NS + "People", PAGE );
//public static final Individual PUBLICATIONS = m_model.createIndividual( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#Publications", PAGE ); //public static final Individual PEOPLE_MENU_ITEM = m_model.createIndividual( NS + "PeopleMenuItem", NAVIGATION_ELEMENT );
//public static final Individual PUBLICATIONS = m_model.createIndividual( NS + "Publications", PAGE );
//public static final Individual PUBLICATIONS_MENU_ITEM = m_model.createIndividual( NS + "PublicationsMenuItem", NAVIGATION_ELEMENT );
//public static final Individual PUBLICATIONS_MENU_ITEM = m_model.createIndividual( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#PublicationsMenuItem", NAVIGATION_ELEMENT );
} }

View file

@ -0,0 +1,126 @@
package edu.cornell.mannlib.vitro.webapp.search.beans;
import java.io.StringReader;
import org.junit.Assert;
import org.junit.Test;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
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.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import edu.cornell.mannlib.vitro.webapp.web.DisplayVocabulary;
public class ProhibitedFromSearchTest {
String SEARCH_CONFIG_URI = "http://example.com/TestSearchConfig";
String TEST_CLASS = "http://vivoweb.org/ontology/test/bogus#Class5";
String n3 =
"@prefix : <http://vitro.mannlib.cornell.edu/ns/vitroDisplay#> . \n" +
"@prefix vivo: <http://vivoweb.org/ontology/test/bogus#> . \n" +
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
"<"+SEARCH_CONFIG_URI+"> rdf:type :ProhibitedFromSearch ;\n" +
" <" + DisplayVocabulary.EXCLUDE_CLASS.getURI() + "> vivo:Class2, vivo:Class3, vivo:Class4, <"+TEST_CLASS+"> .\n" ;
@Test
public void testBuildingProhibited(){
Model r = ModelFactory.createDefaultModel().read(new StringReader(n3), null, "N3");
OntModel m = (OntModel) ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
m.add( r.listStatements() );
Assert.assertTrue(m.size() > 4);
ProhibitedFromSearch pfs = new ProhibitedFromSearch( SEARCH_CONFIG_URI , m);
Assert.assertNotNull(pfs.prohibitedClasses);
Assert.assertTrue(pfs.prohibitedClasses.size() == 4);
Assert.assertTrue(pfs.isClassProhibited(TEST_CLASS));
Assert.assertTrue(!pfs.isClassProhibited("http://someOtherClass.com/test"));
}
@Test
public void testNotFound(){
Model r = ModelFactory.createDefaultModel().read(new StringReader(n3), null, "N3");
OntModel m = (OntModel) ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
m.add( r.listStatements() );
Assert.assertTrue(m.size() > 4);
ProhibitedFromSearch pfs = new ProhibitedFromSearch( "http://NotFound.com/inModel", m);
Assert.assertNotNull(pfs.prohibitedClasses);
Assert.assertTrue(pfs.prohibitedClasses.size() == 0);
Assert.assertTrue(!pfs.isClassProhibited(TEST_CLASS));
Assert.assertTrue(!pfs.isClassProhibited("http://someOtherClass.com/test"));
}
@Test
public void testListener(){
Model r = ModelFactory.createDefaultModel().read(new StringReader(n3), null, "N3");
OntModel m = (OntModel) ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
m.add( r.listStatements() );
Assert.assertTrue(m.size() > 4);
ProhibitedFromSearch pfs = new ProhibitedFromSearch( SEARCH_CONFIG_URI , m);
Assert.assertTrue(pfs.prohibitedClasses.size() == 4);
Resource bougsClass3 = ResourceFactory.createResource("http://example.com/bougsClass3");
Resource searchConfig = ResourceFactory.createResource(SEARCH_CONFIG_URI);
m.add(searchConfig, DisplayVocabulary.EXCLUDE_CLASS, bougsClass3);
Assert.assertEquals(5, pfs.prohibitedClasses.size());
m.remove(searchConfig, DisplayVocabulary.EXCLUDE_CLASS, bougsClass3);
Assert.assertEquals(4, pfs.prohibitedClasses.size());
Resource bougsClass4 = ResourceFactory.createResource("http://vivoweb.org/ontology/test/bogus#Class4");
m.remove(searchConfig, DisplayVocabulary.EXCLUDE_CLASS, bougsClass4);
Assert.assertEquals(3, pfs.prohibitedClasses.size());
}
@Test
public void testListenerAbnormal(){
Model r = ModelFactory.createDefaultModel().read(new StringReader(n3), null, "N3");
OntModel m = (OntModel) ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
m.add( r.listStatements() );
Assert.assertTrue(m.size() > 4);
ProhibitedFromSearch pfs = new ProhibitedFromSearch( SEARCH_CONFIG_URI , m);
Assert.assertTrue(pfs.prohibitedClasses.size() == 4);
int originalSize = pfs.prohibitedClasses.size();
Literal bogusLiteral = ResourceFactory.createPlainLiteral("some bogus literal");
Resource searchConfig = ResourceFactory.createResource(SEARCH_CONFIG_URI);
m.add(searchConfig, DisplayVocabulary.EXCLUDE_CLASS, bogusLiteral);
Assert.assertEquals(originalSize, pfs.prohibitedClasses.size());
m.remove(searchConfig, DisplayVocabulary.EXCLUDE_CLASS, bogusLiteral);
Assert.assertEquals(originalSize, pfs.prohibitedClasses.size());
Resource anonRes = ResourceFactory.createResource();
m.remove(searchConfig, DisplayVocabulary.EXCLUDE_CLASS, anonRes);
Assert.assertEquals(originalSize, pfs.prohibitedClasses.size());
}
@Test
public void testPrimaryIndex(){
String primaryIndexN3 =
"<http://vitro.mannlib.cornell.edu/ontologies/display/1.1#PrimaryLuceneIndex>" +
"<http://vitro.mannlib.cornell.edu/ontologies/display/1.1#excludeClass>" +
"<http://vivoweb.org/ontology/core#NonAcademic> . ";
Model r = ModelFactory.createDefaultModel().read(new StringReader(primaryIndexN3), null, "N3");
OntModel m = (OntModel) ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
m.add( r.listStatements() );
Assert.assertTrue(m.size() == 1);
ProhibitedFromSearch pfs = new ProhibitedFromSearch( DisplayVocabulary.PRIMARY_LUCENE_INDEX_URI, m);
Assert.assertNotNull(pfs.prohibitedClasses);
Assert.assertEquals(1, pfs.prohibitedClasses.size() );
Assert.assertTrue(pfs.isClassProhibited("http://vivoweb.org/ontology/core#NonAcademic"));
Assert.assertTrue(!pfs.isClassProhibited("http://someOtherClass.com/test"));
}
}

View file

@ -1,3 +1,3 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */ <#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<h1>Welcome to VIVO</h1> <h1>Welcome to VIVO</h1>