Java Code Examples for org.semanticweb.owlapi.model.OWLOntology#equals()

The following examples show how to use org.semanticweb.owlapi.model.OWLOntology#equals() . 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: OWLGraphWrapperBasic.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Each ontology in the import closure of the source ontology
 * (and the import closure of each existing support ontology, if
 * doForAllSupportOntologies is true) is added to
 * the list of support ontologies
 * 
 * @param doForAllSupportOntologies
 */
public void addSupportOntologiesFromImportsClosure(boolean doForAllSupportOntologies) {
	Set<OWLOntology> ios = new HashSet<OWLOntology>();
	ios.add(sourceOntology);

	if (doForAllSupportOntologies) {
		ios.addAll(getSupportOntologySet());
	}
	for (OWLOntology so : ios) {
		for (OWLOntology o : so.getImportsClosure()) {
			if (o.equals(sourceOntology))
				continue;
			addSupportOntology(o);
		}
	}
}
 
Example 2
Source File: OWLGraphWrapperBasic.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void mergeImportClosure(boolean isRemovedImportsDeclarations) throws OWLOntologyCreationException {
	OWLOntologyManager manager = getManager();
	Set<OWLOntology> imports = sourceOntology.getImportsClosure();
	for (OWLOntology o : imports) {
		if (o.equals(sourceOntology))
			continue;

		String comment = "Includes "+summarizeOntology(o);
		LOG.info(comment);
		addCommentToOntology(sourceOntology, comment);

		manager.addAxioms(sourceOntology, o.getAxioms());
	}
	Set<OWLImportsDeclaration> oids = sourceOntology.getImportsDeclarations();
	for (OWLImportsDeclaration oid : oids) {
		RemoveImport ri = new RemoveImport(sourceOntology, oid);
		getManager().applyChange(ri);
	}
}
 
Example 3
Source File: OWLGraphWrapperBasic.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Merge a specific ontology from the import closure into the main ontology.
 * Removes the import statement.
 * 
 * @param ontologyIRI id of the ontology to merge
 * @throws OWLOntologyCreationException
 */
public void mergeSpecificImport(IRI ontologyIRI) throws OWLOntologyCreationException {
	OWLOntologyManager manager = getManager();
	Set<OWLOntology> imports = sourceOntology.getImportsClosure();
	for (OWLOntology o : imports) {
		if (o.equals(sourceOntology))
			continue;
		Optional<IRI> currentIRI = o.getOntologyID().getOntologyIRI();
		if (currentIRI.isPresent() && currentIRI.get().equals(ontologyIRI)) {
			String comment = "Includes "+summarizeOntology(o);
			LOG.info(comment);
			addCommentToOntology(sourceOntology, comment);
			manager.addAxioms(sourceOntology, o.getAxioms());	
		}
	}
	Set<OWLImportsDeclaration> oids = sourceOntology.getImportsDeclarations();
	for (OWLImportsDeclaration oid : oids) {
		if (ontologyIRI.equals(oid.getIRI())) {
			RemoveImport ri = new RemoveImport(sourceOntology, oid);
			getManager().applyChange(ri);
		}
	}
}
 
Example 4
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 5
Source File: OntologySetMetadata.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public OntologySetMetadata(OWLOntology ont) {
	ontologies = new HashSet<OntologyMetadata>();
	for (OWLOntology io : ont.getImportsClosure()) {
		OntologyMetadata om = new OntologyMetadata(io);
		ontologies.add(om);
		if (io.equals(ont)) {
			om.isRoot = true;
		}
	}
}
 
Example 6
Source File: ProvenanceReasonerWrapper.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void reasonLeavingOneOut(OWLOntology leaveOutOntology) throws OWLOntologyCreationException {
	OWLOntologyManager m = getManager();
	OWLOntology ont2 = m.createOntology();
	
	LOG.info("LEAVE ONE OUT: "+leaveOutOntology);
	for (OWLOntology io : ontology.getImportsClosure()) {
		if (io.equals(leaveOutOntology)) {
			LOG.info("SKIPPING:"+io);
			continue;
		}
		m.addAxioms(ont2, io.getAxioms());
		
	}
	
	OWLReasoner reasoner = rf.createReasoner(ont2);
	for (OWLEdge e : edges) {
		if (!e.isJustified) {
			// there is no point checking unjustified edges;
			// these are edges that when removed cannot be re-inferred using the entire ontology set.
			// as reasoning is monotonic, removing imports cannot bring it back.
			continue;
		}
		//LOG.info("Testing "+e); 
		if (!isEdgeEntailed(e, ont2, reasoner)) {
			IRI req = leaveOutOntology.getOntologyID().getOntologyIRI().orNull();
			LOG.info(e + " requires "+req);
			e.requires.add(req);
			
		}
	}
	reasoner.dispose();
}
 
Example 7
Source File: OWLGraphManipulator.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
     * Merges {@code OWLAxiom}s from the import ontology closure, with the source ontology.
     * This method is similar to {@link OWLGraphWrapperBasic#mergeImportClosure(boolean)}, 
     * except that: i) an {@code OWLAxiom} will be added to the source ontology only if 
     * it is not already present in the source (without taking annotations into account); 
     * ii) a check is performed to ensure that there will not be more than 
     * one annotation axiom for a given subject, when the annotation property 
     * corresponds to a tag with max cardinality one in OBO format 
     * (see {@code org.obolibrary.oboformat.model.Frame#check()}). As for 
     * {@link OWLGraphWrapperBasic#mergeImportClosure(boolean)}, annotations on the ontology 
     * itself are not imported, and the import declarations are removed after execution. 
     */
    private void mergeImportClosure() {
        log.info("Merging axioms from import closure with source ontology...");
        OWLOntology sourceOnt = this.getOwlGraphWrapper().getSourceOntology();
        
        //the method OWLOntology.containsAxiomIgnoreAnnotations is really 
        //not well optimized, so we get all OWLAxioms without annotations 
        //from the source ontology. 
        log.debug("Retrieving OWLAxioms without annotations from source ontology...");
        Set<OWLAxiom> sourceAxiomsNoAnnots = new HashSet<OWLAxiom>();
        for (OWLAxiom ax: sourceOnt.getAxioms()) {
            sourceAxiomsNoAnnots.add(ax.getAxiomWithoutAnnotations());
        }
        if (log.isDebugEnabled()) {
            log.debug(sourceAxiomsNoAnnots.size() + " axioms without annotations retrieved " +
            		"over " + sourceOnt.getAxiomCount() + " axioms.");
        }
        
        for (OWLOntology importedOnt: sourceOnt.getImportsClosure()) {
            if (importedOnt.equals(sourceOnt)) {
                continue;
            }
            log.info("Merging " + importedOnt);
            
//            OWLDataFactory df = sourceOnt.getOWLOntologyManager().getOWLDataFactory();
//            OWLAnnotationProperty p = 
//                    df.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_COMMENT.getIRI());
//            OWLLiteral v = df.getOWLLiteral("Imported " + importedOnt);
//            OWLAnnotation ann = df.getOWLAnnotation(p, v);
//            AddOntologyAnnotation addAnn = 
//                    new AddOntologyAnnotation(sourceOnt, ann);
//            sourceOnt.getOWLOntologyManager().applyChange(addAnn);
            
            //filter the axioms imported to avoid redundancy (too bad there is not 
            //a method OWLOntology.getAxiomsIgnoreAnnotations())
            int importedAxiomCount = 0;
            importAxioms: for (OWLAxiom importedAx: importedOnt.getAxioms()) {
                if (sourceAxiomsNoAnnots.contains(importedAx.getAxiomWithoutAnnotations())) {
                    continue importAxioms;
                }
                    
                //if it is an annotation axion, we need to ensure that 
                //there will not be more than one axiom for a given subject, 
                //when the annotation corresponds to a tag with max cardinality one 
                //in OBO format (see org.obolibrary.oboformat.model.Frame#check()).
                if (importedAx instanceof OWLAnnotationAssertionAxiom) {
                    OWLAnnotationAssertionAxiom castAx = 
                            (OWLAnnotationAssertionAxiom) importedAx;

                    if (maxOneCardinalityAnnots.contains(
                            castAx.getProperty().getIRI().toString()) || 
                            maxOneCardinalityAnnots.contains(
                                    this.getOwlGraphWrapper().getIdentifier(
                                            castAx.getProperty()))) {

                        //check whether we have an annotation for the same subject 
                        //in the source ontology.
                        for (OWLAnnotationAssertionAxiom sourceAnnotAx: 
                            sourceOnt.getAnnotationAssertionAxioms(
                                    castAx.getSubject())) {
                            if (sourceAnnotAx.getProperty().equals(
                                    castAx.getProperty())) {
                                //discard the axiom from import ontology, there is already 
                                //an annotation with same property on same subject
                                log.trace("Discarding axiom: " + castAx);
                                continue importAxioms;
                            }
                        }
                    }
                }
                
                //all verifications passed, include the axiom
                importedAxiomCount++;
                sourceAxiomsNoAnnots.add(importedAx.getAxiomWithoutAnnotations());
                sourceOnt.getOWLOntologyManager().addAxiom(sourceOnt, importedAx);
            }
            log.info(importedAxiomCount + " axioms imported.");
        }

        //remove the import declarations
        Set<OWLImportsDeclaration> oids = sourceOnt.getImportsDeclarations();
        for (OWLImportsDeclaration oid : oids) {
            RemoveImport ri = new RemoveImport(sourceOnt, oid);
            sourceOnt.getOWLOntologyManager().applyChange(ri);
        }
        
        log.info("Done merging axioms.");
    }