From ea3e05fb80600cfc493eba5f1a74a085607053f9 Mon Sep 17 00:00:00 2001 From: briancaruso Date: Tue, 26 Jun 2012 21:35:17 +0000 Subject: [PATCH] Fixed getVClassesForProperty to return subclasses NIHVIVO-3814 Added unit test for getVClassesForProperty Changes to debugging messages for solr indexing --- .../vitro/webapp/dao/jena/VClassDaoJena.java | 19 ++++-- .../webapp/search/indexing/IndexBuilder.java | 3 +- .../IndividualToSolrDocument.java | 9 +-- .../vitro/webapp/dao/jena/VClassDaoTest.java | 63 +++++++++++++++++-- 4 files changed, 79 insertions(+), 15 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoJena.java index 481470a8f..e26729272 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoJena.java @@ -745,7 +745,10 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { if (superclass == null) { superclass = (domainSide) ? op.getRange() : op.getDomain(); if (superclass == null) { - superclass = getOntModel().getOntResource(OWL.Thing.getURI()); + //this section to prevent all subclasses of owl:Thing + //returned if range is owl:Thing, refer to NIHVIVO-3357 NIHVIVO-3814 + //This is unfortunate case of warping the model for the ease of the display. + return Collections.emptyList(); } } if (superclass != null) { @@ -755,11 +758,15 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { } else { superVclass = getVClassByURI(superclass.getURI()); } + if( OWL.Thing.equals( superclass )){ + //this section to prevent all subclasses of owl:Thing + //returned if range is owl:Thing, refer to NIHVIVO-3357 NIHVIVO-3814 + //This is unfortunate case of warping the model for the ease of the display. + return Collections.emptyList(); + } if (superVclass != null) { - vClasses.add(superVclass); - //Commenting out this section to prevent all subclasses of owl:Thing - //returned if range is owl:Thing, refer to NIHVIVO-3357 - /* String isInferencing = getWebappDaoFactory().getProperties().get("infersTypes"); + vClasses.add(superVclass); + String isInferencing = getWebappDaoFactory().getProperties().get("infersTypes"); // if this model infers types based on the taxonomy, adding the subclasses will only // waste time for no benefit PelletListener pl = getWebappDaoFactory().getPelletListener(); @@ -772,7 +779,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { if (vClass != null) vClasses.add(vClass); } - } */ + } } } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilder.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilder.java index 67b8419e6..e11d72195 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilder.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilder.java @@ -437,7 +437,8 @@ public class IndexBuilder extends VitroBackgroundThread { work.get( counter % workers ).add( uris.next() ); counter ++; } - log.info("Number of individuals to be indexed : " + counter); + log.info("Number of individuals to be indexed : " + counter + " by " + + workers + " worker theads."); return work; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/IndividualToSolrDocument.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/IndividualToSolrDocument.java index a08d4238c..3317506c8 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/IndividualToSolrDocument.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/IndividualToSolrDocument.java @@ -119,14 +119,14 @@ public class IndividualToSolrDocument { throws SkipIndividualException{ //run the document modifiers if( documentModifiers != null && !documentModifiers.isEmpty()){ + docModCount++; for(DocumentModifier modifier: documentModifiers){ long start = System.currentTimeMillis(); modifier.modifyDocument(ind, doc, addUri); - if( log.isDebugEnabled()){ - docModCount++; + if( log.isDebugEnabled()){ long delta = System.currentTimeMillis() - start; synchronized(docModClassToTime){ Class clz = modifier.getClass(); @@ -137,8 +137,9 @@ public class IndividualToSolrDocument { docModClassToTime.put(clz.getName(), delta); } } - if( docModCount % 100 == 0 ){ - for( Entry entry: docModClassToTime.entrySet()){ + if( docModCount % 200 == 0 ){ + log.debug("DocumentModifier timings"); + for( Entry entry: docModClassToTime.entrySet()){ log.debug("average msec to run " + entry.getKey() + ": " + (entry.getValue()/docModCount)); } } diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoTest.java index 711220115..27c509918 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoTest.java @@ -3,14 +3,18 @@ package edu.cornell.mannlib.vitro.webapp.dao.jena; -import org.junit.Assert; +import java.util.List; + +import static org.junit.Assert.*; import org.junit.Test; +import com.hp.hpl.jena.ontology.ObjectProperty; import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModelSpec; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; +import com.hp.hpl.jena.vocabulary.OWL; import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; @@ -94,7 +98,7 @@ public class VClassDaoTest { // information already in the jena model. - Assert.assertEquals(vClass.getName(), class1.getLabel(lang)); // + assertEquals(vClass.getName(), class1.getLabel(lang)); // vcdj.updateVClass(vClass); // we haven't changed any values here, so @@ -114,8 +118,8 @@ public class VClassDaoTest { wipeOutModTime(subModel); wipeOutModTime(superModel); - Assert.assertTrue(subModel.isIsomorphicWith(origSubModel)); - Assert.assertTrue(superModel.isIsomorphicWith(origSuperModel)); + assertTrue(subModel.isIsomorphicWith(origSubModel)); + assertTrue(superModel.isIsomorphicWith(origSuperModel)); } @@ -144,4 +148,55 @@ public class VClassDaoTest { model.removeAll(null, model.createProperty(VitroVocabulary.MODTIME), null); } + + @Test + public void getVClassesForPropertyTest(){ + String lang = "en-US"; + String superClassURI = "http://example.com/SUPER_class"; + String subClassAURI = "http://example.com/SUB_class_A"; + String subClassBURI = "http://example.com/SUB_class_B"; + String propURI = "http://example.com/PROP"; + + String propNoRangeURI = "http://example.com/PROP_NO_RANGE"; + + OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); + + + //Define super class and sub classes + OntClass superClass = model.createClass( superClassURI ); + superClass.addLabel("SUPER",lang); + superClass.setPropertyValue(model.createProperty(VitroVocabulary.IN_CLASSGROUP), model.createResource("http://thisIsTheClassGroupURI")); + superClass.addSuperClass( OWL.Thing ); + + OntClass subA = model.createClass(subClassAURI); + subA.addLabel("subA",lang); + subA.setPropertyValue(model.createProperty(VitroVocabulary.IN_CLASSGROUP), model.createResource("http://thisIsTheClassGroupURI")); + superClass.addSubClass(subA); + + OntClass subB = model.createClass(subClassBURI); + subB.addLabel("subB",lang); + subB.setPropertyValue(model.createProperty(VitroVocabulary.IN_CLASSGROUP), model.createResource("http://thisIsTheClassGroupURI")); + superClass.addSubClass(subB); + + //Define property using the super class + ObjectProperty prop = model.createObjectProperty( propURI ); + prop.setLabel("PROP", lang); + prop.setRange( superClass ); + + ObjectProperty propNoRange = model.createObjectProperty( propNoRangeURI ); + propNoRange.setLabel("PROP_NO_RANGE", lang); + + WebappDaoFactoryJena wdfj = new WebappDaoFactoryJena(model); + + List classesForProp = wdfj.getVClassDao().getVClassesForProperty(propURI, true); + assertNotNull( classesForProp ); + assertEquals(3, classesForProp.size()); + + List classesForPropNoRange = wdfj.getVClassDao().getVClassesForProperty(propNoRangeURI, true); + assertNotNull( classesForPropNoRange ); + assertEquals(0, classesForPropNoRange.size()); + + + } + }