org.semanticweb.owlapi.model.OWLOntologyChange Java Examples

The following examples show how to use org.semanticweb.owlapi.model.OWLOntologyChange. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReasonerUtil.java    From SciGraph with Apache License 2.0 6 votes vote down vote up
public boolean reason() {
  if (config.isRemoveUnsatisfiableClasses()) {
    removeUnsatisfiableClasses();
  }
  if (!shouldReason()) {
    return false;
  }

  List<OWLOntologyChange> changes = new ArrayList<>();

  for (OWLClass ce: ont.getClassesInSignature(true)) {
    if (config.isAddInferredEquivalences()) {
      changes.add(getCompleteEquivalence(ce));
    }
    if (config.isAddDirectInferredEdges()) {
      changes.addAll(getDirectInferredEdges(ce));
    }
  }

  logger.info("Applying reasoned axioms: " + changes.size());
  manager.applyChanges(changes);
  logger.info("Completed applying reasoning changes");
  removeRedundantAxioms();
  reasoner.dispose();
  return true;
}
 
Example #2
Source File: ReasonerUtil.java    From SciGraph with Apache License 2.0 6 votes vote down vote up
void removeRedundantAxioms() {
  final List<RemoveAxiom> changes = new ArrayList<RemoveAxiom>();
  Set<OWLClass> allClasses = ont.getClassesInSignature(true);
  logger.info("Check classes for redundant super class axioms, all OWL classes count: " + allClasses.size());
  for (OWLClass cls: allClasses) {
    final Set<OWLClass> directSuperClasses = reasoner.getSuperClasses(cls, true).getFlattened();
    for (final OWLOntology importedOntology: ont.getImportsClosure()) {
      Set<OWLSubClassOfAxiom> subClassAxioms = importedOntology.getSubClassAxiomsForSubClass(cls);
      for (final OWLSubClassOfAxiom subClassAxiom : subClassAxioms) {
        subClassAxiom.getSuperClass().accept(new OWLClassExpressionVisitorAdapter(){
          @Override
          public void visit(OWLClass desc) {
            if (directSuperClasses.contains(desc) == false) {
              changes.add(new RemoveAxiom(importedOntology, subClassAxiom));
            }
          }
        });
      }
    }
  }
  logger.info("Found redundant axioms: " + changes.size());
  List<OWLOntologyChange> result = manager.applyChanges(changes);
  logger.info("Removed axioms: " + result.size());
}
 
Example #3
Source File: AssertInferenceTool.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static List<OWLOntologyChange> handleSupportOntologies(OWLGraphWrapper graph)
{
	OWLOntology ontology = graph.getSourceOntology();
	OWLOntologyManager manager = ontology.getOWLOntologyManager();
	OWLDataFactory factory = manager.getOWLDataFactory();
	
	List<OWLOntologyChange> removeImportChanges = new ArrayList<OWLOntologyChange>();
	Set<OWLOntology> supportOntologySet = graph.getSupportOntologySet();
	for (OWLOntology support : supportOntologySet) {
		Optional<IRI> supportIRI = support.getOntologyID().getOntologyIRI();
		if(supportIRI.isPresent()) {
			IRI ontologyIRI = supportIRI.get();
			OWLImportsDeclaration importDeclaration = factory.getOWLImportsDeclaration(ontologyIRI);
			ChangeApplied status = manager.applyChange(new AddImport(ontology, importDeclaration));
			if (ChangeApplied.SUCCESSFULLY == status) {
				// the change was successful, create remove import for later
				removeImportChanges.add(new RemoveImport(ontology, importDeclaration));
			}
		}
	}
	return removeImportChanges;
}
 
Example #4
Source File: TemplatedTransformer.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Set<OWLOntologyChange> tr() {
	Set<OWLOntologyChange> chgs = new HashSet<OWLOntologyChange>();
	for (Mapping m : getMappings()) {
		chgs.addAll(tr(m));
	}
	return chgs;
}
 
Example #5
Source File: SatisfiabilityChecker.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
  OWLOntology ont = manager.loadOntology(IRI.create(args[0]));
  ReasonerConfiguration config = new ReasonerConfiguration();
  config.setFactory(ElkReasonerFactory.class.getCanonicalName());
  ReasonerUtil util = new ReasonerUtil(config, manager, ont);
  Collection<OWLOntologyChange> removals = util.removeUnsatisfiableClasses();
  if (!removals.isEmpty()) {
    logger.info("Removed " + removals.size() + " to help prevent unsatisfiable classes.");
    for (OWLOntologyChange removal: removals) {
      logger.info(removal.toString());
    }
  }
  OWLReasoner reasoner = util.getReasoner();
  if (!reasoner.isConsistent()) {
    logger.severe("Ontology is inconsistent");
    System.exit(1);
  }
  Collection<OWLClass> unsatisfiableClasses = util.getUnsatisfiableClasses();
  if (!unsatisfiableClasses.isEmpty()) {
    logger.severe("Ontology is unsatisfiable");
     for (OWLClass unsatisfiableClass: unsatisfiableClasses) {
       logger.severe(unsatisfiableClass.toString());
     }
     System.exit(2);
  }
  logger.info("Ontology is consistent and satisfiable");
  System.exit(0);
}
 
Example #6
Source File: ReasonerUtil.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
/***
 * Remove all axioms that would generate extra unsatisfiable classes for the reasoner
 */
Collection<OWLOntologyChange> removeUnsatisfiableClasses() {
  Collection<OWLOntologyChange> removals = new HashSet<>();
  removals.addAll(removeAxioms(AxiomType.DISJOINT_CLASSES));
  removals.addAll(removeAxioms(AxiomType.DATA_PROPERTY_DOMAIN));
  removals.addAll(removeAxioms(AxiomType.DATA_PROPERTY_RANGE));
  if (removals.size() > 0) {
    reasoner.flush();
  }
  logger.info("Removed " + removals.size() + " axioms to prevent unsatisfiable classes");
  return removals;
}
 
Example #7
Source File: ReasonerUtil.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
Collection<OWLOntologyChange> removeAxioms(AxiomType<?> type) {
  Collection<OWLOntologyChange> removals = new HashSet<>();
  for (OWLOntology importedOnt: ont.getImportsClosure()) {
    Set<? extends OWLAxiom> axioms = importedOnt.getAxioms(type);
    removals.addAll(manager.removeAxioms(importedOnt, axioms));
  }
  return removals;
}
 
Example #8
Source File: TemplatedTransformerTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testTr() throws Exception {
	CatalogXmlIRIMapper m = new CatalogXmlIRIMapper("src/test/resources/catalog-v001.xml");
	ParserWrapper p = new ParserWrapper();
	OWLOntology owlOntology = p.parse(getResourceIRIString("test-tr.owl"));
	TemplatedTransformer tt = new TemplatedTransformer(owlOntology);
	Set<OWLOntologyChange> chgs = tt.tr();
	for (OWLOntologyChange chg : chgs) {
		LOG.info(chg);
	}
	assertNotNull(owlOntology);
}
 
Example #9
Source File: OWLGsonParser.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public OWLOntology convertOntology(Map<Object,Object> m) throws OWLOntologyCreationException {
	Set<OWLAxiom> axioms = null;
	IRI ontologyIRI = null;
	List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
	List<IRI> importsIRIs = new ArrayList<IRI>();
	for (Object k : m.keySet()) {
		if (k.equals("axioms")) {
			axioms = convertAxioms((Object[]) m.get(k));			
		}
		else if (k.equals("iri")) {
			ontologyIRI = IRI.create((String) m.get(k));
		}
		else if (k.equals("annotations")) {
			// TODO
		}
		else if (k.equals("imports")) {
			IRI importIRI = IRI.create((String) m.get(k));
			importsIRIs.add(importIRI);
			
		}
	}
	OWLOntology ont = manager.createOntology(ontologyIRI);
	for (IRI importsIRI : importsIRIs) {
		AddImport ai = new AddImport(ont, manager.getOWLDataFactory().getOWLImportsDeclaration(importsIRI));
		changes.add(ai);
	}
	manager.applyChanges(changes);
	return ont;
}
 
Example #10
Source File: OWLGraphManipulator.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Convenient method to apply {@code changes} to the ontology.
 * 
 * @param changes 	The {@code List} of {@code OWLOntologyChange}s 
 * 					to be applied to the ontology. 
 * @return 			{@code true} if all changes were applied, 
 * 					{@code false} otherwise. 
 */
private boolean applyChanges(List<? extends OWLOntologyChange> changes) {
	
	ChangeApplied status = this.getOwlGraphWrapper().getManager().applyChanges(changes);
	if (status != ChangeApplied.UNSUCCESSFULLY) {
    	return true;
	}
	return false;
}
 
Example #11
Source File: TemplatedTransformer.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Set<OWLOntologyChange> tr(OWLAxiom inAxiom, Mapping m) {
	Set<OWLOntologyChange> chgs = new HashSet<OWLOntologyChange>();
	boolean isModified = false;
	OWLAxiom newAxiom = null;
	if (inAxiom instanceof OWLEquivalentClassesAxiom) {
		OWLEquivalentClassesAxiom aa = (OWLEquivalentClassesAxiom)inAxiom;
		Set<OWLClassExpression> xs = new HashSet<OWLClassExpression>();
		for (OWLClassExpression x : aa.getClassExpressions()) {
			OWLClassExpression x2 = replace(x, m);
			if (x2 == null) {
				xs.add(x);
			}
			else {
				isModified = true;
				xs.add(x2);
				LOG.info("  TR : "+x+ " ---> "+x2);
			}
		}
		if (isModified) {
			newAxiom = getOWLDataFactory().getOWLEquivalentClassesAxiom(xs);
		}
	}
	if (isModified) {
		if (m.isReplace) {
			chgs.add(new RemoveAxiom(ontology, inAxiom));
		}
		chgs.add(new AddAxiom(ontology, newAxiom));
	}
	return chgs;
	
}
 
Example #12
Source File: TemplatedTransformer.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Set<OWLOntologyChange> tr(OWLOntology o, Mapping m) {
	Set<OWLOntologyChange> chgs = new HashSet<OWLOntologyChange>();
	for (OWLAxiom ax : o.getAxioms()) {
		chgs.addAll(tr(ax, m));
	}
	return chgs;
}
 
Example #13
Source File: TemplatedTransformer.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Set<OWLOntologyChange> tr(Mapping m) {
	Set<OWLOntologyChange> chgs = new HashSet<OWLOntologyChange>();
	for (OWLOntology o : ontology.getImportsClosure()) {
		chgs.addAll(tr(o, m));
	}
	return chgs;
}
 
Example #14
Source File: ElkReasoner.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
@Override
public void ontologiesChanged(List<? extends OWLOntologyChange> changes) {
	Set<OWLOntology> importClosure = null;
	for (OWLOntologyChange change : changes) {
		OWLOntology changedOntology = change.getOntology();
		if (!changedOntology.equals(owlOntology_)) {
			if (importClosure == null) {
				importClosure = owlOntology_.getImportsClosure();
			}
			if (!importClosure.contains(changedOntology)) {
				LOGGER_.trace(
						"Ignoring the change not applicable to the current ontology: {}"
								+ change);
				continue;
			}
		}

		if (!change.isAxiomChange()) {
			LOGGER_.trace(
					"Non-axiom change: {}\n The ontology will be reloaded.",
					change);
			// cannot handle non-axiom changes incrementally
			ontologyReloadRequired_ = true;
		} else {
			bufferedChangesLoader_.registerChange(change);
		}
	}
	if (!isBufferingMode_)
		flush();
}
 
Example #15
Source File: OwlChangesLoaderFactory.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
Set<OWLAxiom> getPendingAxiomAdditions() {
	Set<OWLAxiom> added = new HashSet<OWLAxiom>();
	for (OWLOntologyChange change : pendingChanges_) {
		if (change instanceof AddAxiom) {
			added.add(change.getAxiom());
		}
	}
	return added;
}
 
Example #16
Source File: OwlChangesLoaderFactory.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
Set<OWLAxiom> getPendingAxiomRemovals() {
	Set<OWLAxiom> removed = new HashSet<OWLAxiom>();
	for (OWLOntologyChange change : pendingChanges_) {
		if (change instanceof RemoveAxiom) {
			removed.add(change.getAxiom());
		}
	}
	return removed;
}
 
Example #17
Source File: OWLGraphManipulator.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Relaxes all {@code OWLObjectIntersectionOf}s. This method will relax 
 * {@code OWLSubClassOfAxiom}s, whose superclass is an {@code OWLObjectIntersectionOf}, 
 * into multiple {@code OWLSubClassOfAxiom}s, using a <a 
 * href='http://owlapi.sourceforge.net/javadoc/org/semanticweb/owlapi/SplitSubClassAxioms.html'>
 * SplitSubClassAxioms</a>. It will also relax {@code OWLSubClassOfAxiom}s, whose 
 * superclass is an {@code OWLObjectSomeValuesFrom} with a filler being an 
 * {@code OWLObjectIntersectionOf}, into multiple {@code OWLSubClassOfAxiom}s with 
 * an {@code OWLObjectSomeValuesFrom} as superclass, with the same 
 * {@code OWLPropertyExpression}, and individual operands as filler. 
 * <p>
 * Note that it is likely that the {@code OWLObjectIntersectionOf}s where used in
 * {@code OWLEquivalentClassesAxiom}s, rather than in {@code OWLSubClassOfAxiom}s. 
 * But the method {@link #convertEquivalentClassesToSuperClasses()} would have transformed 
 * them into {@code OWLSubClassOfAxiom}s. It must be called before this method.
 * 
 * @see #performDefaultModifications()
 * @see #convertEquivalentClassesToSuperClasses()
 */
private void splitSubClassAxioms() {
    log.info("Relaxing OWLSubClassOfAxioms whose superclass is an OWLObjectIntersectionOf");
    
    //first, split subClassOf axioms whose superclass is an OWLObjectIntersectionOf
    SplitSubClassAxioms split = new SplitSubClassAxioms(
            this.getOwlGraphWrapper().getAllOntologies(), 
            this.getOwlGraphWrapper().getDataFactory());
    this.getOwlGraphWrapper().getManager().applyChanges(split.getChanges());
    this.triggerWrapperUpdate();
    
    //some ontologies use an OWLObjectIntersectionOf as the filler of 
    //an OWLObjectSomeValuesFrom class expression. We go only one level down 
    //(i.e., we would not translate another OWLObjectSomeValuesFrom part of the 
    //OWLObjectIntersectionOf)
    OWLDataFactory dataFactory = this.getOwlGraphWrapper().getDataFactory();
    List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
    for (OWLOntology ont : this.getOwlGraphWrapper().getAllOntologies()) {
        for (OWLSubClassOfAxiom ax : ont.getAxioms(AxiomType.SUBCLASS_OF)) {
            OWLClassExpression superClsExpr = ax.getSuperClass();
            if (superClsExpr instanceof OWLObjectSomeValuesFrom) {
                OWLObjectSomeValuesFrom someValuesFrom = 
                        (OWLObjectSomeValuesFrom) superClsExpr;
                if (someValuesFrom.getFiller() instanceof OWLObjectIntersectionOf) {
                    //remove original axiom
                    changes.add(new RemoveAxiom(ont, ax));
                    
                    OWLObjectIntersectionOf filler = 
                            (OWLObjectIntersectionOf) someValuesFrom.getFiller();
                    for (OWLClassExpression op : filler.getOperands()) {
                        //we accept only OWLClasses, otherwise we would need to compose 
                        //OWLObjectPropertyExpressions
                        if (op instanceof OWLClass) {
                            OWLAxiom replAx = dataFactory.
                                    getOWLSubClassOfAxiom(ax.getSubClass(), 
                                    dataFactory.getOWLObjectSomeValuesFrom(
                                                someValuesFrom.getProperty(), op));
                            changes.add(new AddAxiom(ont, replAx));
                        }
                    }
                }
                
            }
        }
    }
    this.getOwlGraphWrapper().getManager().applyChanges(changes);
    this.triggerWrapperUpdate();
    
    log.info("OWLObjectIntersectionOf relaxation done.");
}
 
Example #18
Source File: ElkReasoner.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
@Override
public List<OWLOntologyChange> getPendingChanges() {
	LOGGER_.trace("getPendingChanges()");
	return bufferedChangesLoader_.getPendingChanges();
}
 
Example #19
Source File: ElkReasoner.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
@Override
public void appliedChange(OWLOntologyChange change) {
	// nothing to do

}
 
Example #20
Source File: OwlOntologyChangeProcessorVisitor.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
protected void defaultVisit(OWLOntologyChange change) {
	error_ = new ElkLoadingException(
			"Ontology change " + change.toString() + " is not supported");
}
 
Example #21
Source File: OwlChangesLoaderFactory.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
OwlChangesLoaderFactory(final ProgressMonitor progressMonitor) {
	this.progressMonitor = progressMonitor;
	this.pendingChanges_ = new LinkedList<OWLOntologyChange>();
}
 
Example #22
Source File: AssertInferenceTool.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static void  cleanupSupportOntologies(OWLGraphWrapper graph, List<OWLOntologyChange> remove)
{
	OWLOntology ontology = graph.getSourceOntology();
	OWLOntologyManager manager = ontology.getOWLOntologyManager();
	manager.applyChanges(remove);
}
 
Example #23
Source File: OwlChangesLoaderFactory.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
synchronized void registerChange(OWLOntologyChange change) {
	LOGGER_.trace("Registering change: {}", change);

	pendingChanges_.add(change);
}
 
Example #24
Source File: OwlChangesLoaderFactory.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
List<OWLOntologyChange> getPendingChanges() {
	return pendingChanges_;
}
 
Example #25
Source File: ElkReasonerTest.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
/**
 * Testing correctness of the reasoner with respect to ontology changes
 * <p>
 * removing the import declaration for </impA>,
 * adding the import declaration for </impB> and removing
 * ":Y is-a B:B"
 */
@Test
public void testRemovingImpAAddingImpBRemovingYB() throws Exception {

	OWLOntologyManager man = TestOWLManager.createOWLOntologyManager();
	OWLDataFactory dataFactory = man.getOWLDataFactory();

	// set up resolution of prefixes
	PrefixManager pm = new DefaultPrefixManager();
	pm.setDefaultPrefix("http://www.example.com/main#");
	pm.setPrefix("A:", "http://www.example.com/A#");
	pm.setPrefix("B:", "http://www.example.com/B#");

	// define query classes
	OWLClass mainX = dataFactory.getOWLClass(":X", pm);
	OWLClass mainY = dataFactory.getOWLClass(":Y", pm);
	OWLClass extA = dataFactory.getOWLClass("A:A", pm);
	OWLClass extB = dataFactory.getOWLClass("B:B", pm);
	OWLClass extC = dataFactory.getOWLClass("B:C", pm);

	// loading the root ontology
	OWLOntology root = loadOntology(man, "root.owl");

	// Create an ELK reasoner.
	OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
	OWLReasoner reasoner = reasonerFactory.createReasoner(root);

	try {

		// ************************************
		// ** adding the import declaration for </impB> and removing
		// ":Y is-a B:B"
		// ************************************

		OWLImportsDeclaration importA = new OWLImportsDeclarationImpl(
				IRI.create("http://www.example.com#impA"));
		OWLOntologyChange change = new RemoveImport(root, importA);
		man.applyChange(change);
		OWLImportsDeclaration importB = new OWLImportsDeclarationImpl(
				IRI.create("http://www.example.com#impB"));
		change = new AddImport(root, importB);
		man.applyChange(change);
		OWLSubClassOfAxiom axiom = dataFactory.getOWLSubClassOfAxiom(mainY, extB);
		man.removeAxiom(root, axiom);
		reasoner.flush();

		// Now ontology should import only ontology </impB>
		assertEquals(root.getAxiomCount(), 2);
		assertEquals(root.getImportsClosure().size(), 2);
		assertEquals(getAxioms(root).size(), 4);

		// reasoner queries -- only subsumptions of the root
		// ontology </impB> and there
		assertTrue(reasoner.getSuperClasses(mainX, true).containsEntity(
				mainY));
		assertTrue(reasoner.getSuperClasses(mainX, true).containsEntity(
				extA));
		assertFalse(reasoner.getSuperClasses(mainY, true).containsEntity(
				extB));
		assertFalse(reasoner.getSuperClasses(extA, true).containsEntity(
				extB));
		assertTrue(reasoner.getSuperClasses(extB, true)
				.containsEntity(extC));

	} finally {
		reasoner.dispose();
	}

}
 
Example #26
Source File: OWLGraphManipulator.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Relaxes all {@code OWLEquivalentClassesAxiom}s into {@code OWLSubClassOfAxiom}s 
 * using a <a href=
 * 'http://owlapi.sourceforge.net/javadoc/org/semanticweb/owlapi/ConvertEquivalentClassesToSuperClasses.html'>
 * ConvertEquivalentClassesToSuperClasses</a>. It will allow split any operands 
 * that are {@code OWLObjectIntersectionOf}s.
 * <p>
 * Note that if several named class expressions are part of a same 
 * {@code OWLEquivalentClassesAxiom}, no {@code OWLSubClassOfAxiom} will be created 
 * between them, to avoid generating a cycle.
 * 
 * @see #performDefaultModifications()
 */
private void convertEquivalentClassesToSuperClasses() {
    log.info("Relaxing OWLEquivalentClassesAxioms into OWLSubClassOfAxioms...");
    //first, get all OWLClasses in all OWLOntologies, as the 
    //ConvertEquivalentClassesToSuperClasses will then remove axioms for an OWLClass 
    //in all ontologies, so, if a class was present in several ontologies, 
    //it would be redundant.
    Set<OWLClass> allClasses = new HashSet<OWLClass>();
    for (OWLOntology ont: this.getOwlGraphWrapper().getAllOntologies()) {
        allClasses.addAll(ont.getClassesInSignature());
    }
    
    //now, remove for each class the ECAs. Store all changes before applying them, 
    //so that if several named classes are part of an ECA, the ECA is not removed 
    //after the iteration of the first named class. Also, changes will be filtered 
    //to avoid creating a cycle between such multiple named classes of an ECA.
    List<OWLOntologyChange> allChanges = new ArrayList<OWLOntologyChange>();
    for (OWLClass cls: allClasses) {
        ConvertEquivalentClassesToSuperClasses convert = 
                new ConvertEquivalentClassesToSuperClasses(
                        this.getOwlGraphWrapper().getDataFactory(), cls, 
                        this.getOwlGraphWrapper().getAllOntologies(), 
                        this.getOwlGraphWrapper().getSourceOntology(), 
                        false); //disable splitting of OWLObjectIntersectionOf, 
                                //otherwise it would be difficult to filter 
                                //axioms created between named classes (see below)
        List<OWLOntologyChange> localChanges = convert.getChanges();
        
        //filter the changes to avoid creating a cycle between named classes
        Set<OWLOntologyChange> addAxiomsToCancel = new HashSet<OWLOntologyChange>();
        for (OWLOntologyChange change: localChanges) {
            if (change.isAddAxiom() && 
                change.getAxiom() instanceof OWLSubClassOfAxiom && 
                !((OWLSubClassOfAxiom) change.getAxiom()).getSuperClass().isAnonymous()) {
                
                //TODO: maybe we should store the OWLClasses involved, and share/exchange 
                //all their related SubClassOfAxioms afterwards.
                addAxiomsToCancel.add(change);
                log.warn("An EquivalentClassesAxiom contained several named " +
                		"class expressions, no SubClassOfAxiom will be created " +
                		"between them. Axiom that will NOT be added: " + 
                		change.getAxiom());
            }
        }
        localChanges.removeAll(addAxiomsToCancel);
        allChanges.addAll(localChanges);
    }
    this.getOwlGraphWrapper().getManager().applyChanges(allChanges);

    this.triggerWrapperUpdate();
    log.info("ECA relaxation done.");
}
 
Example #27
Source File: LazyExpressionMaterializingReasoner.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public List<OWLOntologyChange> getPendingChanges() {
	return getWrappedReasoner().getPendingChanges();
}
 
Example #28
Source File: DelegatingOWLReasoner.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
@Override
public List<OWLOntologyChange> getPendingChanges() {
	return delegate_.getPendingChanges();
}
 
Example #29
Source File: ProofTestUtils.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
public static <I extends Inference<?>> void proofCompletenessTest(
		final OWLProver prover, final OWLAxiom entailment,
		final Object conclusion, final Proof<? extends I> proof,
		final InferenceJustifier<? super I, ? extends Set<? extends OWLAxiom>> justifier,
		final boolean mustNotBeATautology) {

	final OWLOntology ontology = prover.getRootOntology();
	final OWLOntologyManager manager = ontology.getOWLOntologyManager();

	// compute repairs

	final Set<Set<? extends OWLAxiom>> repairs = new HashSet<Set<? extends OWLAxiom>>();
	MinimalSubsetEnumerators.enumerateRepairs(conclusion, proof, justifier,
			InterruptMonitor.DUMMY,
			new MinimalSubsetCollector<OWLAxiom>(repairs));

	if (mustNotBeATautology) {
		assertFalse("Entailment is a tautology; there are no repairs!",
				repairs.isEmpty());
	}

	for (final Set<? extends OWLAxiom> repair : repairs) {

		final List<OWLOntologyChange> deletions = new ArrayList<OWLOntologyChange>();
		final List<OWLOntologyChange> additions = new ArrayList<OWLOntologyChange>();
		for (final OWLAxiom axiom : repair) {
			deletions.add(new RemoveAxiom(ontology, axiom));
			additions.add(new AddAxiom(ontology, axiom));
		}

		manager.applyChanges(deletions);

		final boolean conclusionDerived = prover.isEntailed(entailment);

		manager.applyChanges(additions);

		assertFalse("Not all proofs were found!\n" + "Conclusion: "
				+ conclusion + "\n" + "Repair: " + repair,
				conclusionDerived);
	}

}
 
Example #30
Source File: ElkReasonerTest.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
/**
 * Testing correctness of the reasoner with respect to ontology changes
 * <p>
 * removing the import declaration for </impA>
 */
@Test
public void testRemovingImpA() throws Exception {

	OWLOntologyManager man = TestOWLManager.createOWLOntologyManager();
	OWLDataFactory dataFactory = man.getOWLDataFactory();

	// set up resolution of prefixes
	PrefixManager pm = new DefaultPrefixManager();
	pm.setDefaultPrefix("http://www.example.com/main#");
	pm.setPrefix("A:", "http://www.example.com/A#");
	pm.setPrefix("B:", "http://www.example.com/B#");

	// define query classes
	OWLClass mainX = dataFactory.getOWLClass(":X", pm);
	OWLClass mainY = dataFactory.getOWLClass(":Y", pm);
	OWLClass extA = dataFactory.getOWLClass("A:A", pm);
	OWLClass extB = dataFactory.getOWLClass("B:B", pm);
	OWLClass extC = dataFactory.getOWLClass("B:C", pm);

	// loading the root ontology
	OWLOntology root = loadOntology(man, "root.owl");

	// Create an ELK reasoner.
	OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
	OWLReasoner reasoner = reasonerFactory.createReasoner(root);

	try {

		// ************************************
		// ** removing the import declaration for </impA>
		// ************************************

		OWLImportsDeclaration importA = new OWLImportsDeclarationImpl(
				IRI.create("http://www.example.com#impA"));
		OWLOntologyChange change = new RemoveImport(root, importA);
		man.applyChange(change);
		reasoner.flush();

		// Now the root ontology should not import anything
		assertEquals(root.getAxiomCount(), 3);
		assertEquals(root.getImportsClosure().size(), 1);
		assertEquals(getAxioms(root).size(), 3);

		// reasoner queries -- only subsumptions of the root ontology are
		// there
		assertTrue(reasoner.getSuperClasses(mainX, true).containsEntity(
				mainY));
		assertTrue(reasoner.getSuperClasses(mainX, true).containsEntity(
				extA));
		assertTrue(reasoner.getSuperClasses(mainY, true).containsEntity(
				extB));
		assertFalse(reasoner.getSuperClasses(extA, true).containsEntity(
				extB));
		assertFalse(reasoner.getSuperClasses(extB, true).containsEntity(
				extC));

	} finally {
		reasoner.dispose();
	}

}