NIHVIVO-2900, NIHVIVO-2891
This commit is contained in:
parent
b0ba33338e
commit
a4f90721f3
2 changed files with 49 additions and 22 deletions
|
@ -7,8 +7,6 @@ import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
@ -951,17 +949,26 @@ public class SimpleReasoner extends StatementListener {
|
||||||
aboxModel.enterCriticalSection(Lock.WRITE);
|
aboxModel.enterCriticalSection(Lock.WRITE);
|
||||||
tboxModel.enterCriticalSection(Lock.READ);
|
tboxModel.enterCriticalSection(Lock.READ);
|
||||||
|
|
||||||
|
StmtIterator iter = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
log.info("Computing class-based ABox inferences.");
|
log.info("Computing class-based ABox inferences.");
|
||||||
inferenceRebuildModel.removeAll();
|
inferenceRebuildModel.removeAll();
|
||||||
StmtIterator iter = aboxModel.listStatements((Resource) null, RDF.type, (RDFNode) null);
|
iter = aboxModel.listStatements((Resource) null, RDF.type, (RDFNode) null);
|
||||||
|
|
||||||
int numStmts = 0;
|
int numStmts = 0;
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
Statement stmt = iter.next();
|
Statement stmt = iter.next();
|
||||||
|
try {
|
||||||
addedABoxTypeAssertion(stmt, inferenceRebuildModel, unknownTypes);
|
addedABoxTypeAssertion(stmt, inferenceRebuildModel, unknownTypes);
|
||||||
setMostSpecificTypes(stmt.getSubject(), inferenceRebuildModel, unknownTypes);
|
setMostSpecificTypes(stmt.getSubject(), inferenceRebuildModel, unknownTypes);
|
||||||
|
} catch (NullPointerException npe) {
|
||||||
|
log.error("a NullPointerException was received while recomputing the ABox inferences. Halting inference computation.");
|
||||||
|
return;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Exception while recomputing ABox inference model", e);
|
||||||
|
}
|
||||||
|
|
||||||
numStmts++;
|
numStmts++;
|
||||||
if ((numStmts % 8000) == 0) {
|
if ((numStmts % 8000) == 0) {
|
||||||
|
@ -1023,6 +1030,7 @@ public class SimpleReasoner extends StatementListener {
|
||||||
// where there isn't an exception
|
// where there isn't an exception
|
||||||
return;
|
return;
|
||||||
} finally {
|
} finally {
|
||||||
|
iter.close();
|
||||||
aboxModel.leaveCriticalSection();
|
aboxModel.leaveCriticalSection();
|
||||||
tboxModel.leaveCriticalSection();
|
tboxModel.leaveCriticalSection();
|
||||||
inferenceRebuildModel.leaveCriticalSection();
|
inferenceRebuildModel.leaveCriticalSection();
|
||||||
|
@ -1043,7 +1051,7 @@ public class SimpleReasoner extends StatementListener {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
scratchpadModel.removeAll();
|
scratchpadModel.removeAll();
|
||||||
StmtIterator iter = inferenceModel.listStatements();
|
iter = inferenceModel.listStatements();
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
Statement stmt = iter.next();
|
Statement stmt = iter.next();
|
||||||
|
@ -1064,6 +1072,7 @@ public class SimpleReasoner extends StatementListener {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Exception while reconciling the current and recomputed ABox inference models", e);
|
log.error("Exception while reconciling the current and recomputed ABox inference models", e);
|
||||||
} finally {
|
} finally {
|
||||||
|
iter.close();
|
||||||
inferenceModel.leaveCriticalSection();
|
inferenceModel.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1072,6 +1081,7 @@ public class SimpleReasoner extends StatementListener {
|
||||||
inferenceModel.remove(scratchpadModel);
|
inferenceModel.remove(scratchpadModel);
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
log.error("Exception while reconciling the current and recomputed ABox inference models", e);
|
log.error("Exception while reconciling the current and recomputed ABox inference models", e);
|
||||||
|
return;
|
||||||
} finally {
|
} finally {
|
||||||
inferenceModel.leaveCriticalSection();
|
inferenceModel.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
|
@ -1082,7 +1092,7 @@ public class SimpleReasoner extends StatementListener {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
scratchpadModel.removeAll();
|
scratchpadModel.removeAll();
|
||||||
StmtIterator iter = inferenceRebuildModel.listStatements();
|
iter = inferenceRebuildModel.listStatements();
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
Statement stmt = iter.next();
|
Statement stmt = iter.next();
|
||||||
|
@ -1102,7 +1112,9 @@ public class SimpleReasoner extends StatementListener {
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Exception while reconciling the current and recomputed ABox inference models", e);
|
log.error("Exception while reconciling the current and recomputed ABox inference models", e);
|
||||||
|
return;
|
||||||
} finally {
|
} finally {
|
||||||
|
iter.close();
|
||||||
inferenceModel.leaveCriticalSection();
|
inferenceModel.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1111,6 +1123,7 @@ public class SimpleReasoner extends StatementListener {
|
||||||
inferenceModel.add(scratchpadModel);
|
inferenceModel.add(scratchpadModel);
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
log.error("Exception while reconciling the current and recomputed ABox inference models", e);
|
log.error("Exception while reconciling the current and recomputed ABox inference models", e);
|
||||||
|
return;
|
||||||
} finally {
|
} finally {
|
||||||
inferenceModel.leaveCriticalSection();
|
inferenceModel.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
|
@ -1127,7 +1140,7 @@ public class SimpleReasoner extends StatementListener {
|
||||||
/*
|
/*
|
||||||
* Special for version 1.3
|
* Special for version 1.3
|
||||||
*/
|
*/
|
||||||
public synchronized void recomputeMostSpecificType() {
|
public synchronized void computeMostSpecificType() {
|
||||||
|
|
||||||
HashSet<String> unknownTypes = new HashSet<String>();
|
HashSet<String> unknownTypes = new HashSet<String>();
|
||||||
|
|
||||||
|
@ -1136,16 +1149,26 @@ public class SimpleReasoner extends StatementListener {
|
||||||
aboxModel.enterCriticalSection(Lock.WRITE);
|
aboxModel.enterCriticalSection(Lock.WRITE);
|
||||||
tboxModel.enterCriticalSection(Lock.READ);
|
tboxModel.enterCriticalSection(Lock.READ);
|
||||||
|
|
||||||
|
StmtIterator iter = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
inferenceRebuildModel.removeAll();
|
inferenceRebuildModel.removeAll();
|
||||||
StmtIterator iter = aboxModel.listStatements((Resource) null, RDF.type, (RDFNode) null);
|
iter = aboxModel.listStatements((Resource) null, RDF.type, (RDFNode) null);
|
||||||
|
|
||||||
log.info("Computing mostSpecificType annotations.");
|
log.info("Computing mostSpecificType annotations.");
|
||||||
int numStmts = 0;
|
int numStmts = 0;
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
Statement stmt = iter.next();
|
Statement stmt = iter.next();
|
||||||
|
|
||||||
|
try {
|
||||||
setMostSpecificTypes(stmt.getSubject(), inferenceRebuildModel, unknownTypes);
|
setMostSpecificTypes(stmt.getSubject(), inferenceRebuildModel, unknownTypes);
|
||||||
|
} catch (NullPointerException npe) {
|
||||||
|
log.error("a NullPointerException was received while computing mostSpecificType annotations. Halting inference computation.");
|
||||||
|
return;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Exception while computing mostSpecificType annotations", e);
|
||||||
|
}
|
||||||
|
|
||||||
numStmts++;
|
numStmts++;
|
||||||
if ((numStmts % 8000) == 0) {
|
if ((numStmts % 8000) == 0) {
|
||||||
|
@ -1153,7 +1176,7 @@ public class SimpleReasoner extends StatementListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stopRequested) {
|
if (stopRequested) {
|
||||||
log.info("a stopRequested signal was received during recomputeMostSpecificType. Halting Processing.");
|
log.info("a stopRequested signal was received during computeMostSpecificType. Halting Processing.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1163,6 +1186,7 @@ public class SimpleReasoner extends StatementListener {
|
||||||
// where there isn't an exception
|
// where there isn't an exception
|
||||||
return;
|
return;
|
||||||
} finally {
|
} finally {
|
||||||
|
iter.close();
|
||||||
aboxModel.leaveCriticalSection();
|
aboxModel.leaveCriticalSection();
|
||||||
tboxModel.leaveCriticalSection();
|
tboxModel.leaveCriticalSection();
|
||||||
inferenceRebuildModel.leaveCriticalSection();
|
inferenceRebuildModel.leaveCriticalSection();
|
||||||
|
@ -1183,7 +1207,7 @@ public class SimpleReasoner extends StatementListener {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
scratchpadModel.removeAll();
|
scratchpadModel.removeAll();
|
||||||
StmtIterator iter = inferenceRebuildModel.listStatements();
|
iter = inferenceRebuildModel.listStatements();
|
||||||
|
|
||||||
int numStmts = 0;
|
int numStmts = 0;
|
||||||
|
|
||||||
|
@ -1205,7 +1229,9 @@ public class SimpleReasoner extends StatementListener {
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Exception while reconciling the current and recomputed ABox inference models", e);
|
log.error("Exception while reconciling the current and recomputed ABox inference models", e);
|
||||||
|
return;
|
||||||
} finally {
|
} finally {
|
||||||
|
iter.close();
|
||||||
inferenceModel.leaveCriticalSection();
|
inferenceModel.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1214,6 +1240,7 @@ public class SimpleReasoner extends StatementListener {
|
||||||
inferenceModel.add(scratchpadModel);
|
inferenceModel.add(scratchpadModel);
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
log.error("Exception while reconciling the current and recomputed ABox inference models", e);
|
log.error("Exception while reconciling the current and recomputed ABox inference models", e);
|
||||||
|
return;
|
||||||
} finally {
|
} finally {
|
||||||
inferenceModel.leaveCriticalSection();
|
inferenceModel.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
|
@ -1312,13 +1339,13 @@ public class SimpleReasoner extends StatementListener {
|
||||||
retractions.leaveCriticalSection();
|
retractions.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (abort) {
|
if (stopRequested) {
|
||||||
log.info("a NullPointerException was received while computing inferences in batch " + qualifier + " mode. Halting inference computation.");
|
log.info("a stopRequested signal was received during DeltaComputer.run. Halting Processing.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stopRequested) {
|
if (abort) {
|
||||||
log.info("a stopRequested signal was received during DeltaComputer.run. Halting Processing.");
|
log.error("a NullPointerException was received while computing inferences in batch " + qualifier + " mode. Halting inference computation.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
||||||
sleeps++;
|
sleeps++;
|
||||||
}
|
}
|
||||||
|
|
||||||
new Thread(new ABoxRecomputer(simpleReasoner),"ABoxRecompuer").start();
|
new Thread(new ABoxRecomputer(simpleReasoner),"ABoxRecomputer").start();
|
||||||
} else if ( isMSTComputeRequired(sce.getServletContext()) ) {
|
} else if ( isMSTComputeRequired(sce.getServletContext()) ) {
|
||||||
log.info("mostSpecificType computation required. It will be done in a separate thread.");
|
log.info("mostSpecificType computation required. It will be done in a separate thread.");
|
||||||
|
|
||||||
|
@ -200,7 +200,7 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
simpleReasoner.recomputeMostSpecificType();
|
simpleReasoner.computeMostSpecificType();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue