Skip to content

Commit

Permalink
Cleanig the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Balramt committed Nov 20, 2024
1 parent 3a9c652 commit dee7f14
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions src/main/java/AbductionReasoning.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
import java.util.*;

public class AbductionReasoning {

private static final String DEFAULT_OUTPUT_DIR = "output/"; // Customize the directory as needed

public static void main(String[] args) throws OWLOntologyCreationException, IOException, OWLException {
// Record the start time
long startTime = System.currentTimeMillis();
Expand Down Expand Up @@ -74,13 +71,13 @@ public void run(String ns, String localOntologyPath, String queryStr, String ind
Set<OWLNamedIndividual> individuals = instances.getFlattened();
// Process the individuals
for (OWLNamedIndividual selectedIndividual : individuals) {
if(selectedIndividual.equals(owlIndividualWithExplan)) {
if (selectedIndividual.equals(owlIndividualWithExplan)) {

// Explain the classification of the selected individual
Set<Set<OWLAxiom>> explanations = expGen.getInstanceExplanations(selectedIndividual, query, 10);
Set<Set<OWLAxiom>> allCommonAxiomsSet = findCommonAxioms(explanations, ontology);
System.out.println("allCommonAxiomsSet : "+allCommonAxiomsSet);
System.out.println("allCommonAxiomsSet size: "+allCommonAxiomsSet.size());
System.out.println("allCommonAxiomsSet : " + allCommonAxiomsSet);
System.out.println("allCommonAxiomsSet size: " + allCommonAxiomsSet.size());
// Iterate over each element in commonAxioms
for (Set<OWLAxiom> commonAxiomSet : allCommonAxiomsSet) {
// Apply abduction reasoning for each common axiom set
Expand All @@ -98,13 +95,13 @@ public static Set<Set<OWLAxiom>> findCommonAxioms(Set<Set<OWLAxiom>> explanation
for (Set<OWLAxiom> explanationAxioms : explanationsSet) {
Set<OWLAxiom> commonAxioms = new HashSet<>();

for(OWLAxiom explanationAxiom : explanationAxioms){
{
if (aBoxAxioms.contains(explanationAxiom)) {
commonAxioms.add(explanationAxiom);
for (OWLAxiom explanationAxiom : explanationAxioms) {
{
if (aBoxAxioms.contains(explanationAxiom)) {
commonAxioms.add(explanationAxiom);
}
}
}
}
commonAxiomsSet.add(commonAxioms);
}

Expand All @@ -114,13 +111,10 @@ public static Set<Set<OWLAxiom>> findCommonAxioms(Set<Set<OWLAxiom>> explanation

public void applyAbductionForIndividuals(OWLOntology ontology, Set<Set<OWLAxiom>> explanations, OWLNamedIndividual individualWithExplan, OWLNamedIndividual individualWithoutExplan, Set<OWLAxiom> commonAxioms) {

OWLOntology ontology1= ontology;
OWLOntology ontology1 = ontology;

// Modify axioms for the first individual
Set<OWLAxiom> axiomsForFirstIndividual = new HashSet<>();
/* for (OWLAxiom axiom : commonAxioms) {
replaceIndividualInAxiom(axiom, firstIndividual, secondIndividual, axiomsForFirstIndividual);
}*/
replaceIndividualInAxiom(commonAxioms, individualWithExplan, individualWithoutExplan, axiomsForFirstIndividual);

// Check for missing axioms
Expand All @@ -135,7 +129,6 @@ public void applyAbductionForIndividuals(OWLOntology ontology, Set<Set<OWLAxiom>

// Add missing axioms to the ontology
OWLOntologyManager manager = ontology1.getOWLOntologyManager();
//manager.addAxioms(ontology1, missingAxioms);

System.out.println("Missing axioms for " + individualWithoutExplan + ": " + missingAxioms);
}
Expand Down Expand Up @@ -196,18 +189,10 @@ public void visit(OWLObjectPropertyAssertionAxiom axiom) {
}



});
}
}



/* public OWLClassExpression parseQueryString(String ns, String queryStr) {
String str = ns + queryStr;
return OWL.Class(str);
}*/

private OWLClassExpression parseQueryString(String ns, String queryStr) {
// Remove outer parentheses if present
queryStr = queryStr.trim();
Expand Down Expand Up @@ -306,7 +291,7 @@ private List<String> splitAtTopLevel(String input, String delimiter) {
i += delimiter.length() - 1; // skip the delimiter
}
}
result.add(input.substring (lastIndex).trim());
result.add(input.substring(lastIndex).trim());
return result;
}

Expand Down

0 comments on commit dee7f14

Please sign in to comment.