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) {
|
if (superclass == null) {
|
||||||
superclass = (domainSide) ? op.getRange() : op.getDomain();
|
superclass = (domainSide) ? op.getRange() : op.getDomain();
|
||||||
if (superclass == null) {
|
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) {
|
if (superclass != null) {
|
||||||
|
@ -755,11 +758,15 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
||||||
} else {
|
} else {
|
||||||
superVclass = getVClassByURI(superclass.getURI());
|
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) {
|
if (superVclass != null) {
|
||||||
vClasses.add(superVclass);
|
vClasses.add(superVclass);
|
||||||
//Commenting out this section to prevent all subclasses of owl:Thing
|
String isInferencing = getWebappDaoFactory().getProperties().get("infersTypes");
|
||||||
//returned if range is owl:Thing, refer to NIHVIVO-3357
|
|
||||||
/* String isInferencing = getWebappDaoFactory().getProperties().get("infersTypes");
|
|
||||||
// if this model infers types based on the taxonomy, adding the subclasses will only
|
// if this model infers types based on the taxonomy, adding the subclasses will only
|
||||||
// waste time for no benefit
|
// waste time for no benefit
|
||||||
PelletListener pl = getWebappDaoFactory().getPelletListener();
|
PelletListener pl = getWebappDaoFactory().getPelletListener();
|
||||||
|
@ -772,7 +779,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
||||||
if (vClass != null)
|
if (vClass != null)
|
||||||
vClasses.add(vClass);
|
vClasses.add(vClass);
|
||||||
}
|
}
|
||||||
} */
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -437,7 +437,8 @@ public class IndexBuilder extends VitroBackgroundThread {
|
||||||
work.get( counter % workers ).add( uris.next() );
|
work.get( counter % workers ).add( uris.next() );
|
||||||
counter ++;
|
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;
|
return work;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,14 +119,14 @@ public class IndividualToSolrDocument {
|
||||||
throws SkipIndividualException{
|
throws SkipIndividualException{
|
||||||
//run the document modifiers
|
//run the document modifiers
|
||||||
if( documentModifiers != null && !documentModifiers.isEmpty()){
|
if( documentModifiers != null && !documentModifiers.isEmpty()){
|
||||||
|
docModCount++;
|
||||||
for(DocumentModifier modifier: documentModifiers){
|
for(DocumentModifier modifier: documentModifiers){
|
||||||
|
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
|
|
||||||
modifier.modifyDocument(ind, doc, addUri);
|
modifier.modifyDocument(ind, doc, addUri);
|
||||||
|
|
||||||
if( log.isDebugEnabled()){
|
if( log.isDebugEnabled()){
|
||||||
docModCount++;
|
|
||||||
long delta = System.currentTimeMillis() - start;
|
long delta = System.currentTimeMillis() - start;
|
||||||
synchronized(docModClassToTime){
|
synchronized(docModClassToTime){
|
||||||
Class clz = modifier.getClass();
|
Class clz = modifier.getClass();
|
||||||
|
@ -137,8 +137,9 @@ public class IndividualToSolrDocument {
|
||||||
docModClassToTime.put(clz.getName(), delta);
|
docModClassToTime.put(clz.getName(), delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( docModCount % 100 == 0 ){
|
if( docModCount % 200 == 0 ){
|
||||||
for( Entry<String, Long> entry: docModClassToTime.entrySet()){
|
log.debug("DocumentModifier timings");
|
||||||
|
for( Entry<String, Long> entry: docModClassToTime.entrySet()){
|
||||||
log.debug("average msec to run " + entry.getKey() + ": " + (entry.getValue()/docModCount));
|
log.debug("average msec to run " + entry.getKey() + ": " + (entry.getValue()/docModCount));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,18 @@
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
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 org.junit.Test;
|
||||||
|
|
||||||
|
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;
|
||||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
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.beans.VClass;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
|
@ -94,7 +98,7 @@ public class VClassDaoTest {
|
||||||
// information already in the jena model.
|
// 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
|
vcdj.updateVClass(vClass); // we haven't changed any values here, so
|
||||||
|
@ -114,8 +118,8 @@ public class VClassDaoTest {
|
||||||
wipeOutModTime(subModel);
|
wipeOutModTime(subModel);
|
||||||
wipeOutModTime(superModel);
|
wipeOutModTime(superModel);
|
||||||
|
|
||||||
Assert.assertTrue(subModel.isIsomorphicWith(origSubModel));
|
assertTrue(subModel.isIsomorphicWith(origSubModel));
|
||||||
Assert.assertTrue(superModel.isIsomorphicWith(origSuperModel));
|
assertTrue(superModel.isIsomorphicWith(origSuperModel));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,4 +148,55 @@ public class VClassDaoTest {
|
||||||
model.removeAll(null, model.createProperty(VitroVocabulary.MODTIME), null);
|
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