various small fixes

This commit is contained in:
brianjlowe 2013-10-01 10:21:08 -04:00
parent e375dc33f6
commit 1db72b3397
2 changed files with 62 additions and 48 deletions

View file

@ -2,7 +2,6 @@
package edu.cornell.mannlib.vitro.webapp.dao.jena; package edu.cornell.mannlib.vitro.webapp.dao.jena;
import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
@ -61,7 +60,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent; import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener; import edu.cornell.mannlib.vitro.webapp.web.URLEncoder;
public class VClassDaoJena extends JenaBaseDao implements VClassDao { public class VClassDaoJena extends JenaBaseDao implements VClassDao {
@ -148,8 +147,9 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
labelStr += getLabelForClass(ccls.getOperand(),withPrefix,forPickList); labelStr += getLabelForClass(ccls.getOperand(),withPrefix,forPickList);
} else if (cls.isIntersectionClass()) { } else if (cls.isIntersectionClass()) {
IntersectionClass icls = cls.as(IntersectionClass.class); IntersectionClass icls = cls.as(IntersectionClass.class);
for (Iterator operandIt = icls.listOperands(); operandIt.hasNext();) { for (Iterator<? extends OntClass> operandIt =
OntClass operand = (OntClass) operandIt.next(); icls.listOperands(); operandIt.hasNext();) {
OntClass operand = operandIt.next();
labelStr += getLabelForClass(operand,withPrefix,forPickList); labelStr += getLabelForClass(operand,withPrefix,forPickList);
if (operandIt.hasNext()) { if (operandIt.hasNext()) {
labelStr += " and "; labelStr += " and ";
@ -157,8 +157,9 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
} }
} else if (cls.isUnionClass()) { } else if (cls.isUnionClass()) {
UnionClass icls = cls.as(UnionClass.class); UnionClass icls = cls.as(UnionClass.class);
for (Iterator operandIt = icls.listOperands(); operandIt.hasNext();) { for (Iterator<? extends OntClass> operandIt =
OntClass operand = (OntClass) operandIt.next(); icls.listOperands(); operandIt.hasNext();) {
OntClass operand = operandIt.next();
labelStr += getLabelForClass(operand,withPrefix,forPickList); labelStr += getLabelForClass(operand,withPrefix,forPickList);
if (operandIt.hasNext()) { if (operandIt.hasNext()) {
labelStr += " or "; labelStr += " or ";
@ -170,7 +171,9 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
// BJL23 2009-02-19 // BJL23 2009-02-19
// I'm putting the link markup in because I need it, // I'm putting the link markup in because I need it,
// but obviously we need to factor this out into the display layer. // but obviously we need to factor this out into the display layer.
return "<a href=\"vclassEdit?uri="+URLEncoder.encode(getClassURIStr(cls),"UTF-8")+"\">[anonymous class]</a>"; return "<a href=\"vclassEdit?uri=" +
URLEncoder.encode(getClassURIStr(cls)) +
"\">[anonymous class]</a>";
} }
} else { } else {
if (withPrefix || forPickList) { if (withPrefix || forPickList) {
@ -244,8 +247,9 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
List<String> uriList = new ArrayList<String>(); List<String> uriList = new ArrayList<String>();
getOntModel().enterCriticalSection(Lock.READ); getOntModel().enterCriticalSection(Lock.READ);
try { try {
for (Iterator i = ontClass.listDisjointWith(); i.hasNext(); ) { for (Iterator<? extends OntClass> i =
OntClass disjointClass = (OntClass) i.next(); ontClass.listDisjointWith(); i.hasNext(); ) {
OntClass disjointClass = i.next();
uriList.add(getClassURIStr(disjointClass)); uriList.add(getClassURIStr(disjointClass));
} }
} catch (ProfileException pe) { } catch (ProfileException pe) {
@ -288,10 +292,11 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
getOntModel().enterCriticalSection(Lock.READ); getOntModel().enterCriticalSection(Lock.READ);
try { try {
OntClass ontClass = getOntClass(getOntModel(), classURI); OntClass ontClass = getOntClass(getOntModel(), classURI);
ClosableIterator equivalentOntClassIt = ontClass.listEquivalentClasses(); ClosableIterator<OntClass> equivalentOntClassIt = ontClass.listEquivalentClasses();
try { try {
for (Iterator eqOntClassIt = equivalentOntClassIt; eqOntClassIt.hasNext(); ) { for (Iterator<OntClass> eqOntClassIt =
OntClass eqClass = (OntClass) eqOntClassIt.next(); equivalentOntClassIt; eqOntClassIt.hasNext(); ) {
OntClass eqClass = eqOntClassIt.next();
equivalentClassURIs.add(getClassURIStr(eqClass)); equivalentClassURIs.add(getClassURIStr(eqClass));
} }
} finally { } finally {
@ -482,10 +487,6 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
return classes; return classes;
} }
private Iterator<OntClass> smarterListHierarchyRootClasses(OntModel ontModel) {
return smarterListHierarchyRootClasses(ontModel, null);
}
/** /**
* The basic idea here is that we ignore anonymous superclasses for the purpose * The basic idea here is that we ignore anonymous superclasses for the purpose
* of determining whether something is a root class. * of determining whether something is a root class.
@ -569,16 +570,21 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
OntModel ontModel = getOntModel(); OntModel ontModel = getOntModel();
ontModel.enterCriticalSection(Lock.READ); ontModel.enterCriticalSection(Lock.READ);
try { try {
Iterator<OntClass> ontClassIt = ontModel.listClasses(); Iterator<Resource> ontClassIt = ontModel.listResourcesWithProperty(
RDF.type, OWL.Class);
while (ontClassIt.hasNext()) { while (ontClassIt.hasNext()) {
OntClass ontClass = ontClassIt.next(); Resource ontClass = ontClassIt.next();
if (ontologyURI.equals(ontClass.getNameSpace())) { if (ontologyURI.equals(ontClass.getNameSpace())) {
boolean root = true; boolean root = true;
StmtIterator superStmtIt = ontModel.listStatements(ontClass, RDFS.subClassOf, (RDFNode) null); StmtIterator superStmtIt = ontModel.listStatements(
ontClass, RDFS.subClassOf, (RDFNode) null);
try { try {
while (superStmtIt.hasNext()) { while (superStmtIt.hasNext()) {
Statement superStmt = superStmtIt.nextStatement(); Statement superStmt = superStmtIt.nextStatement();
if ( superStmt.getObject().isResource() && ontologyURI.equals(((Resource) superStmt.getObject()).getNameSpace()) ) { if ( superStmt.getObject().isResource()
&& ontologyURI.equals(
((Resource) superStmt.getObject())
.getNameSpace()) ) {
root = false; root = false;
break; break;
} }
@ -586,8 +592,10 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
} finally { } finally {
superStmtIt.close(); superStmtIt.close();
} }
if (root) { if (root && ontClass.canAs(OntClass.class)) {
ontologyRootClasses.add(new VClassJena(ontClass,getWebappDaoFactory())); ontologyRootClasses.add(new VClassJena(
(OntClass) ontClass.as(OntClass.class),
getWebappDaoFactory()));
} }
} }
} }
@ -598,12 +606,12 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
} }
public List <String> getSubClassURIs(String classURI) { public List <String> getSubClassURIs(String classURI) {
List subURIs = new ArrayList(); List<String> subURIs = new ArrayList<String>();
OntClass superClass = getOntClass(getOntModel(),classURI); OntClass superClass = getOntClass(getOntModel(),classURI);
try { try {
Iterator subIt = superClass.listSubClasses(true); Iterator<OntClass> subIt = superClass.listSubClasses(true);
while (subIt.hasNext()) { while (subIt.hasNext()) {
OntClass cls = (OntClass) subIt.next(); OntClass cls = subIt.next();
subURIs.add(getClassURIStr(cls)); subURIs.add(getClassURIStr(cls));
} }
} catch (Exception e) { } catch (Exception e) {
@ -617,10 +625,10 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
} }
public List <String> getSuperClassURIs(String classURI, boolean direct) { public List <String> getSuperClassURIs(String classURI, boolean direct) {
List supURIs = new ArrayList(); List<String> supURIs = new ArrayList<String>();
OntClass subClass = getOntClass(getOntModel(), classURI); OntClass subClass = getOntClass(getOntModel(), classURI);
try { try {
Iterator supIt = subClass.listSuperClasses(direct); Iterator<OntClass> supIt = subClass.listSuperClasses(direct);
while (supIt.hasNext()) { while (supIt.hasNext()) {
OntClass cls = (OntClass) supIt.next(); OntClass cls = (OntClass) supIt.next();
supURIs.add(getClassURIStr(cls)); supURIs.add(getClassURIStr(cls));
@ -717,12 +725,16 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
OntResource superclass = null; OntResource superclass = null;
if (vclassURI != null) { if (vclassURI != null) {
// TODO need a getAllSuperPropertyURIs method in ObjectPropertyDao // TODO need a getAllSuperPropertyURIs method in ObjectPropertyDao
List<String> superproperties = getWebappDaoFactory().getObjectPropertyDao().getSuperPropertyURIs(propertyURI,false); List<String> superproperties = getWebappDaoFactory()
.getObjectPropertyDao()
.getSuperPropertyURIs(propertyURI, false);
superproperties.add(propertyURI); superproperties.add(propertyURI);
HashSet<String> subjSuperclasses = new HashSet<String>(getAllSuperClassURIs(vclassURI)); HashSet<String> subjSuperclasses = new HashSet<String>(
getAllSuperClassURIs(vclassURI));
subjSuperclasses.add(vclassURI); subjSuperclasses.add(vclassURI);
for (String objectPropertyURI : superproperties) { for (String objectPropertyURI : superproperties) {
for (Iterator restStmtIt = getOntModel().listStatements(null,OWL.onProperty,getOntModel().getProperty(objectPropertyURI)); restStmtIt.hasNext();) { for (Iterator restStmtIt = getOntModel().listStatements(
null,OWL.onProperty,getOntModel().getProperty(objectPropertyURI)); restStmtIt.hasNext();) {
Statement restStmt = (Statement) restStmtIt.next(); Statement restStmt = (Statement) restStmtIt.next();
Resource restRes = restStmt.getSubject(); Resource restRes = restStmt.getSubject();
for (Iterator axStmtIt = getOntModel().listStatements(null,null,restRes); axStmtIt.hasNext();) { for (Iterator axStmtIt = getOntModel().listStatements(null,null,restRes); axStmtIt.hasNext();) {

View file

@ -138,6 +138,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
KnowledgeBaseUpdater ontologyUpdater = new KnowledgeBaseUpdater(settings); KnowledgeBaseUpdater ontologyUpdater = new KnowledgeBaseUpdater(settings);
boolean requiredUpdate = ontologyUpdater.updateRequired(ctx); boolean requiredUpdate = ontologyUpdater.updateRequired(ctx);
if(!JenaDataSourceSetupBase.isFirstStartup()) {
try { try {
ctx.setAttribute(KBM_REQURIED_AT_STARTUP, Boolean.TRUE); ctx.setAttribute(KBM_REQURIED_AT_STARTUP, Boolean.TRUE);
log.info("Data migration required"); log.info("Data migration required");
@ -156,6 +157,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
} catch (Exception ioe) { } catch (Exception ioe) {
ss.fatal(this, "Exception updating knowledge base for ontology changes: ", ioe); ss.fatal(this, "Exception updating knowledge base for ontology changes: ", ioe);
} }
}
SimpleReasoner simpleReasoner = (SimpleReasoner) sce.getServletContext() SimpleReasoner simpleReasoner = (SimpleReasoner) sce.getServletContext()
.getAttribute(SimpleReasoner.class.getName()); .getAttribute(SimpleReasoner.class.getName());