{
System.out.println("Running Approximation No. " + runCounter);
OWLReasonerFactory reasonerFactory = new PelletReasonerFactory();
// OWLReasonerFactory reasonerFactory = new
// FaCTPlusPlusReasonerFactory();
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLReasoner reasoner = null;
OWLOntology aboxOntology = null;
ApproximationResult approximationResult = null;
OWLOntology approximatedTboxOntology = null;
HashMap<OWLClass, Integer> allIndividualsCounts = new HashMap<OWLClass, Integer>();
HashMap<OWLClass, Integer> directIndividualsCounts = new HashMap<OWLClass, Integer>();
HashMap<OWLClass, Integer> indirectIndividualsCounts = new HashMap<OWLClass, Integer>();
int cumulativeDirectIndividualsCounts = 0;
int cumulativeIndirectIndividualsCounts = 0;
Timers timers = new Timers();
double classificationTime = 0;
double approximationTime = 0;
double instanceRetrievalTime = 0;
double aboxUpdateTime = 0;
double time = 0;
// System.out.println("--->approximating...");
timers.createTimer("approximation");
Timer timerApproximation = timers.startTimer("approximation");
approximationResult = approximation.getNextTBox();
timerApproximation.stop();
if (measureApproximationTime)
{
approximationTime += timerApproximation.getTotal();
}
if (approximationResult != null)
{
approximatedTboxOntology = approximationResult
.approximatedOntology();
URI tboxPhysicalURI = createURI(tmpTboxPhysicalURI, runCounter);
if (saveApproximatedTbox)
{
saveOntology(approximatedTboxOntology, tboxPhysicalURI);
}
// System.out.println("--->classifying...");
reasoner = reasonerFactory.createReasoner(manager);
reasoner.loadOntologies(Collections
.singleton(approximatedTboxOntology));
timers.createTimer("classification");
if (!(reasoner.isClassified()))
{
Timer timerClassify = timers.startTimer("classification");
reasoner.classify();
timerClassify.stop();
classificationTime += timerClassify.getTotal();
}
if (approximationResult.isOriginal())
{
aboxPhysicalURI = originalAboxPhysicalURI;
}
aboxOntology = manager
.loadOntologyFromPhysicalURI(aboxPhysicalURI);
reasoner.loadOntologies(Collections.singleton(aboxOntology));
// System.out.println("--->retrieving instances...");
for (OWLClass cc : concepts)
{
Set<OWLIndividual> individuals = new HashSet<OWLIndividual>();
Set<OWLIndividual> directIndividuals = new HashSet<OWLIndividual>();
if (reasoner.isDefined(cc))
{
timers.createTimer("retrieval");
Timer timerRetrieval = timers.startTimer("retrieval");
individuals = reasoner.getIndividuals(cc, false);
timerRetrieval.stop();
instanceRetrievalTime += timerRetrieval.getTotal();
}
directIndividuals = reasoner.getIndividuals(cc, true);
allIndividualsCounts.put(cc,
new Integer(individuals.size()));
directIndividualsCounts.put(cc, new Integer(
directIndividuals.size()));
indirectIndividualsCounts.put(cc, new Integer(individuals
.size()
- directIndividuals.size()));
if (isInterruptible)
{
List<OWLOntologyChange> changesToMake = new Vector<OWLOntologyChange>();
OWLDataFactory factory = manager.getOWLDataFactory();
timers.createTimer("aboxupdate");
Timer timerAboxUpdate = timers.startTimer("aboxupdate");
for (OWLIndividual ci : individuals)
{
changesToMake.add(new AddAxiom(aboxOntology,
factory.getOWLClassAssertionAxiom(ci, cc)));
}
timerAboxUpdate.stop();
aboxUpdateTime += timerAboxUpdate.getTotal();
}
cumulativeDirectIndividualsCounts += directIndividuals
.size();
cumulativeIndirectIndividualsCounts += (individuals.size() - directIndividuals
.size());
}
time = approximationTime + classificationTime
+ instanceRetrievalTime + aboxUpdateTime;
/* Save the results of the run */
runResult = new RunResult(allIndividualsCounts, time,
approximation.getCurrentVocabularyConceptSize(),
approximation.getCurrentVocabularyPropertySize());
runResult.setIndirectIndividuals(indirectIndividualsCounts);
runResult.setDirectIndividuals(directIndividualsCounts);
runResult.setClassificationTime(classificationTime);
runResult.setAboxUpdateTime(aboxUpdateTime);
runResult.setInstanceRetrievalTime(instanceRetrievalTime);
runResult.setApproximationTime(approximationTime);
runResult.setInstances(approximateClassInstances);
runResult.setAxiomRewriteTime(approximationResult
.axiomRewriteTime());
runResult.setVocabularySelectionTime(approximationResult
.selectionTime());
runResult.setRunNumber(runCounter);
if (StrategyManager.getLastSelectionStrategy() != null)
StrategyManager.getLastSelectionStrategy().feedback(
runResult);
results.addRunResult(runResult);
if (isInterruptible)
{
URI newAboxURI = createURI(aboxOntology.getURI(), runResult
.getRunNumber());
URI newAboxPhysicalURI = createURI(tmpAboxURI, runResult
.getRunNumber());
SimpleURIMapper mapper = new SimpleURIMapper(newAboxURI,
newAboxPhysicalURI);
manager.addURIMapper(mapper);
modifiedAboxOntology = manager.createOntology(newAboxURI);
manager.addAxioms(modifiedAboxOntology, aboxOntology
.getAxioms());
/*
* System.out.println(newAboxPhysicalURI.toString() + ", " +
* newAboxURI);
*/
manager.saveOntology(modifiedAboxOntology,
newAboxPhysicalURI);
aboxPhysicalURI = newAboxPhysicalURI;
}
reasoner.unloadOntologies(Collections
.singleton(approximatedTboxOntology));
reasoner.unloadOntologies(Collections.singleton(aboxOntology));
reasoner.dispose();
manager.removeOntology(aboxOntology.getURI());
manager = null;
reasoner = null;
runCounter++;
} else
{