// get the starting point for the simulated annealing process
ArrayList<OWLClass> currentPoint = getStartingPoint(tboxPhysicalURI,
aboxPhysicalURI, method, ontology);
Set<OWLProperty<?, ?>> currentProperties = new HashSet<OWLProperty<?, ?>>();
StepSizeStrategy currentStepSizeStrategy = StrategyFactory
.newStepSizeStrategy("EqualParts", currentPoint.size());
TrivialStrategy currentSelectionStrategy = new TrivialStrategy(
new HashSet<OWLClass>(currentPoint), currentProperties,
currentStepSizeStrategy, currentPoint, currentID + "");
/*new ExperimentManager().run(currentSelectionStrategy,
datasetsDirectory, ontology, resultsDirectory, tmpDirectory);
currentGainScore = new IntegralCalculator().getGainScore(
resultsDirectory, ontology, currentSelectionStrategy.getID());*/
double maxGainScore = currentGainScore;
ArrayList<OWLClass> maxPoint = new ArrayList<OWLClass>(currentPoint);
double maxID = currentID;
currentID++;
for (int i = 0; i < maxIterations; i++)
{
ArrayList<OWLClass> neighborPoint = getNeighborPoint(currentPoint);
for (int j = 0; j < 7; j++)
neighborPoint = getNeighborPoint(neighborPoint);
Set<OWLProperty<?, ?>> neighborProperties = new HashSet<OWLProperty<?, ?>>();
StepSizeStrategy neighborStepSizeStrategy = StrategyFactory
.newStepSizeStrategy("EqualParts", currentPoint.size());
TrivialStrategy neighborSelectionStrategy = new TrivialStrategy(
new HashSet<OWLClass>(neighborPoint), neighborProperties,
neighborStepSizeStrategy, neighborPoint, currentID + "");
/*new ExperimentManager()
.run(neighborSelectionStrategy, datasetsDirectory,
ontology, resultsDirectory, tmpDirectory);*/
double neighborGainScore = new IntegralCalculator().getGainScore(
resultsDirectory, ontology, neighborSelectionStrategy
.getID());
double probability = 1;
if (neighborGainScore < currentGainScore)
{
double c = 1 - (i + 1) / (double) maxIterations;
probability = Math.pow(Math.E,
(neighborGainScore - currentGainScore) / c);
}
if (random.nextDouble() < probability)
{
currentPoint = new ArrayList<OWLClass>(neighborPoint);
currentGainScore = neighborGainScore;
currentID++;
}
if (maxGainScore < currentGainScore)
{
maxGainScore = currentGainScore;
maxPoint = new ArrayList<OWLClass>(currentPoint);
maxID = currentID;
}
}
try
{
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology tboxOntology = null, aboxOntology = null;
try
{
// load the Tbox and Abox
tboxOntology = manager.loadOntology(tboxPhysicalURI);
aboxOntology = manager
.loadOntologyFromPhysicalURI(aboxPhysicalURI);
} catch (OWLOntologyCreationException e)
{
e.printStackTrace();
System.exit(0);
}
StepSizeStrategy stepSizeStrategy = StrategyFactory
.newStepSizeStrategy("EqualParts", maxPoint.size());
String methodString = "Random";
if (method == 1)
{
methodString = "Google";
}
File file = new File(resultsDirectory + ontology + "_"
+ methodString + "_" + round2Decimals(maxGainScore)
+ ".csv");
DataOutputStream dos = new DataOutputStream(new FileOutputStream(
file));
// dos.writeBytes("Gain Score, " + maxGainScore + "\n");
dos
.writeBytes("Concept, Google Score, No Descendats, No Ancestors, No Definig Axioms, No Referencing Axioms, Classes in Signature, No Superclasses, No Subclasses, No Disjoint Classes, No Equivalent Clases, No Direct Individuals, Bin No\n");
int s = stepSizeStrategy.getNextStepSize();
int bin = 1;
int i = 0;
for (OWLClass c : maxPoint)
{
dos.writeBytes(c.getURI().toString() + ", ");
dos.writeBytes(((Integer) googleScores.get(c.getURI()
.toString())).toString()
+ ", ");
dos.writeBytes(getNoDescendants(c, tboxOntology) + ", ");
dos.writeBytes(getNoAncestors(c, tboxOntology) + ", ");
dos.writeBytes(tboxOntology.getAxioms(c).size() + ", ");
dos.writeBytes(tboxOntology.getReferencingAxioms(c).size()
+ ", ");
dos.writeBytes(c.getClassesInSignature().size() + ", ");
dos.writeBytes(c.getSuperClasses(tboxOntology).size() + ", ");
dos.writeBytes(c.getSubClasses(tboxOntology).size() + ", ");
dos
.writeBytes(c.getDisjointClasses(tboxOntology).size()
+ ", ");
dos.writeBytes(c.getEquivalentClasses(tboxOntology).size()
+ ", ");
dos.writeBytes(c.getIndividuals(aboxOntology).size() + ", ");
dos.writeBytes(bin + "\n");
if (i == s - 1)
{
s = stepSizeStrategy.getNextStepSize();
bin++;
i = 0;
} else
{
i++;