NIHVIVO-3036 fixed lockup of system when adding superclass of class with many individuals
This commit is contained in:
parent
4fa16f31ac
commit
f46e4b46f0
2 changed files with 52 additions and 57 deletions
|
@ -30,9 +30,11 @@ public class Classes2ClassesDaoJena extends JenaBaseDao implements Classes2Class
|
||||||
deleteClasses2Classes(c2c, getOntModelSelector().getTBoxModel());
|
deleteClasses2Classes(c2c, getOntModelSelector().getTBoxModel());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO restore write locks once reasoner is able to handle these update asynchronously.
|
||||||
|
|
||||||
public void deleteClasses2Classes( Classes2Classes c2c, OntModel ontModel )
|
public void deleteClasses2Classes( Classes2Classes c2c, OntModel ontModel )
|
||||||
{
|
{
|
||||||
ontModel.enterCriticalSection(Lock.WRITE);
|
// ontModel.enterCriticalSection(Lock.WRITE);
|
||||||
getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true));
|
getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true));
|
||||||
try {
|
try {
|
||||||
OntResource subclass = getOntClass(ontModel,c2c.getSubclassURI());
|
OntResource subclass = getOntClass(ontModel,c2c.getSubclassURI());
|
||||||
|
@ -48,7 +50,7 @@ public class Classes2ClassesDaoJena extends JenaBaseDao implements Classes2Class
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false));
|
getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false));
|
||||||
ontModel.leaveCriticalSection();
|
// ontModel.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +60,7 @@ public class Classes2ClassesDaoJena extends JenaBaseDao implements Classes2Class
|
||||||
|
|
||||||
public void insertNewClasses2Classes( Classes2Classes c2c, OntModel ontModel )
|
public void insertNewClasses2Classes( Classes2Classes c2c, OntModel ontModel )
|
||||||
{
|
{
|
||||||
ontModel.enterCriticalSection(Lock.WRITE);
|
// ontModel.enterCriticalSection(Lock.WRITE);
|
||||||
getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true));
|
getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true));
|
||||||
try {
|
try {
|
||||||
Resource subclass = ontModel.getResource(c2c.getSubclassURI());
|
Resource subclass = ontModel.getResource(c2c.getSubclassURI());
|
||||||
|
@ -68,7 +70,7 @@ public class Classes2ClassesDaoJena extends JenaBaseDao implements Classes2Class
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false));
|
getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false));
|
||||||
ontModel.leaveCriticalSection();
|
// ontModel.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -602,35 +602,33 @@ public class SimpleReasoner extends StatementListener {
|
||||||
* inferred model, assert that it is of type A.
|
* inferred model, assert that it is of type A.
|
||||||
*/
|
*/
|
||||||
public void addedSubClass(OntClass subClass, OntClass superClass, Model inferenceModel) {
|
public void addedSubClass(OntClass subClass, OntClass superClass, Model inferenceModel) {
|
||||||
|
|
||||||
log.debug("subClass = " + subClass.getURI() + " superClass = " + superClass.getURI());
|
log.debug("subClass = " + subClass.getURI() + " superClass = " + superClass.getURI());
|
||||||
|
OntModel unionModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||||
aboxModel.enterCriticalSection(Lock.WRITE);
|
unionModel.addSubModel(aboxModel);
|
||||||
inferenceModel.enterCriticalSection(Lock.WRITE);
|
unionModel.addSubModel(inferenceModel);
|
||||||
|
List<Resource> subjectList = new ArrayList<Resource>();
|
||||||
|
aboxModel.enterCriticalSection(Lock.READ);
|
||||||
try {
|
try {
|
||||||
OntModel unionModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
|
||||||
unionModel.addSubModel(aboxModel);
|
|
||||||
unionModel.addSubModel(inferenceModel);
|
|
||||||
|
|
||||||
StmtIterator iter = unionModel.listStatements((Resource) null, RDF.type, subClass);
|
StmtIterator iter = unionModel.listStatements((Resource) null, RDF.type, subClass);
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
|
|
||||||
Statement stmt = iter.next();
|
Statement stmt = iter.next();
|
||||||
Statement infStmt = ResourceFactory.createStatement(stmt.getSubject(), RDF.type, superClass);
|
subjectList.add(stmt.getSubject());
|
||||||
|
}
|
||||||
inferenceModel.enterCriticalSection(Lock.WRITE);
|
|
||||||
|
|
||||||
if (!inferenceModel.contains(infStmt)) {
|
|
||||||
inferenceModel.add(infStmt);
|
|
||||||
setMostSpecificTypes(infStmt.getSubject(), inferenceModel, new HashSet<String>());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
aboxModel.leaveCriticalSection();
|
aboxModel.leaveCriticalSection();
|
||||||
inferenceModel.leaveCriticalSection();
|
|
||||||
}
|
}
|
||||||
|
for (Resource subject : subjectList) {
|
||||||
|
Statement infStmt = ResourceFactory.createStatement(subject, RDF.type, superClass);
|
||||||
|
inferenceModel.enterCriticalSection(Lock.WRITE);
|
||||||
|
try {
|
||||||
|
if (!inferenceModel.contains(infStmt)) {
|
||||||
|
inferenceModel.add(infStmt);
|
||||||
|
setMostSpecificTypes(subject, inferenceModel, new HashSet<String>());
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
inferenceModel.leaveCriticalSection();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -641,38 +639,33 @@ public class SimpleReasoner extends StatementListener {
|
||||||
* of A (including A itself)
|
* of A (including A itself)
|
||||||
*/
|
*/
|
||||||
public void removedSubClass(OntClass subClass, OntClass superClass, Model inferenceModel) {
|
public void removedSubClass(OntClass subClass, OntClass superClass, Model inferenceModel) {
|
||||||
|
|
||||||
log.debug("subClass = " + subClass.getURI() + ". superClass = " + superClass.getURI());
|
log.debug("subClass = " + subClass.getURI() + ". superClass = " + superClass.getURI());
|
||||||
|
OntModel unionModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||||
aboxModel.enterCriticalSection(Lock.WRITE);
|
unionModel.addSubModel(aboxModel);
|
||||||
inferenceModel.enterCriticalSection(Lock.WRITE);
|
unionModel.addSubModel(inferenceModel);
|
||||||
|
List<Resource> subjectList = new ArrayList<Resource>();
|
||||||
try {
|
aboxModel.enterCriticalSection(Lock.READ);
|
||||||
OntModel unionModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
try {
|
||||||
unionModel.addSubModel(aboxModel);
|
StmtIterator iter = unionModel.listStatements((Resource) null, RDF.type, subClass);
|
||||||
unionModel.addSubModel(inferenceModel);
|
while (iter.hasNext()) {
|
||||||
|
Statement stmt = iter.next();
|
||||||
StmtIterator iter = unionModel.listStatements((Resource) null, RDF.type, subClass);
|
subjectList.add(stmt.getSubject());
|
||||||
|
}
|
||||||
while (iter.hasNext()) {
|
} finally {
|
||||||
|
aboxModel.leaveCriticalSection();
|
||||||
Statement stmt = iter.next();
|
}
|
||||||
Resource ind = stmt.getSubject();
|
for (Resource ind : subjectList) {
|
||||||
|
if (entailedType(ind,superClass)) continue;
|
||||||
if (entailedType(ind,superClass)) continue;
|
Statement infStmt = ResourceFactory.createStatement(ind, RDF.type, superClass);
|
||||||
|
inferenceModel.enterCriticalSection(Lock.WRITE);
|
||||||
Statement infStmt = ResourceFactory.createStatement(ind, RDF.type, superClass);
|
try {
|
||||||
|
if (inferenceModel.contains(infStmt)) {
|
||||||
inferenceModel.enterCriticalSection(Lock.WRITE);
|
inferenceModel.remove(infStmt);
|
||||||
|
setMostSpecificTypes(infStmt.getSubject(), inferenceModel, new HashSet<String>());
|
||||||
if (inferenceModel.contains(infStmt)) {
|
}
|
||||||
inferenceModel.remove(infStmt);
|
} finally {
|
||||||
setMostSpecificTypes(infStmt.getSubject(), inferenceModel, new HashSet<String>());
|
inferenceModel.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
aboxModel.leaveCriticalSection();
|
|
||||||
inferenceModel.leaveCriticalSection();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1414,4 +1407,4 @@ public class SimpleReasoner extends StatementListener {
|
||||||
"] [object = " + (statement.getObject().isLiteral() ? ((Literal)statement.getObject()).getLexicalForm() + " (Literal)"
|
"] [object = " + (statement.getObject().isLiteral() ? ((Literal)statement.getObject()).getLexicalForm() + " (Literal)"
|
||||||
: ((Resource)statement.getObject()).getURI() + " (Resource)") + "]";
|
: ((Resource)statement.getObject()).getURI() + " (Resource)") + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue