Fixed getVClassesForProperty to return subclasses NIHVIVO-3814
Added unit test for getVClassesForProperty Changes to debugging messages for solr indexing
This commit is contained in:
parent
d7b3f0e3f1
commit
ea3e05fb80
4 changed files with 79 additions and 15 deletions
|
@ -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);
|
||||
}
|
||||
} */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String, Long> entry: docModClassToTime.entrySet()){
|
||||
if( docModCount % 200 == 0 ){
|
||||
log.debug("DocumentModifier timings");
|
||||
for( Entry<String, Long> entry: docModClassToTime.entrySet()){
|
||||
log.debug("average msec to run " + entry.getKey() + ": " + (entry.getValue()/docModCount));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<VClass> classesForProp = wdfj.getVClassDao().getVClassesForProperty(propURI, true);
|
||||
assertNotNull( classesForProp );
|
||||
assertEquals(3, classesForProp.size());
|
||||
|
||||
List<VClass> classesForPropNoRange = wdfj.getVClassDao().getVClassesForProperty(propNoRangeURI, true);
|
||||
assertNotNull( classesForPropNoRange );
|
||||
assertEquals(0, classesForPropNoRange.size());
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue