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

The following examples show how to use org.semanticweb.owlapi.model.OWLOntology#getSignature() . 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: Mooncat.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 
 * returns set of entities that belong to a referenced ontology that are referenced in the source ontology.
 * 
 * If the source ontology is not explicitly declared, then all entities that are referenced in the source
 * ontology and declared in a reference ontology are returned.
 * 
 * Example: if the source ontology is cl, and cl contains axioms that reference go:1, go:2, ...
 * and go is in the set of referenced ontologies, then {go:1,go:2,...} will be in the returned set.
 * It is irrelevant whether go:1, ... is declared in the source (e.g. MIREOTed)
 * 
 * Note this only returns direct references. See
 * {@link #getClosureOfExternalReferencedEntities()} for closure of references
 * 
 * @return all objects referenced by source ontology
 */
public Set<OWLEntity> getExternalReferencedEntities() {
	OWLOntology ont = graph.getSourceOntology();
	Set<OWLEntity> objs = ont.getSignature(Imports.EXCLUDED);
	Set<OWLEntity> refObjs = new HashSet<OWLEntity>();
	LOG.info("testing "+objs.size()+" objs to see if they are contained in: "+getReferencedOntologies());
	for (OWLEntity obj : objs) {
		//LOG.info("considering: "+obj);
		// a reference ontology may have entities from the source ontology MIREOTed in..
		// allow a configuration with the URI prefix specified
		if (isInExternalOntology(obj)) {
			refObjs.add(obj);

		}
	}
	LOG.info("#refObjs: "+refObjs.size());

	return refObjs;
}
 
Example 2
Source File: OWLGraphWrapperExtended.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Generate a OboGraphs JSON ontology blob for the local axioms for an object.
 * 
 * This will include
 * 
 *  - all logical axioms about the object
 *  - all annotations for all entities in the signature
 *  
 * In other words, direct parents plus labels and other metadata on all entities
 * 
 * @param obj
 * @return JSON string
 * @throws JsonProcessingException
 * @throws OWLOntologyCreationException
 */
public String getOboGraphJSONString(OWLObject obj) throws JsonProcessingException, OWLOntologyCreationException {
	FromOwl fromOwl = new FromOwl();
	OWLOntologyManager m = sourceOntology.getOWLOntologyManager();
	if (obj instanceof OWLNamedObject) {
		OWLNamedObject nobj = (OWLNamedObject)obj;
		OWLOntology ont = m.createOntology(nobj.getIRI());
		Set<OWLAxiom> axioms = new HashSet<>();
		if (nobj instanceof OWLClass) {
			axioms.addAll(sourceOntology.getAxioms((OWLClass)nobj, Imports.INCLUDED));
		}
		else if (nobj instanceof OWLObjectProperty) {
			axioms.addAll(sourceOntology.getAxioms((OWLObjectProperty)nobj, Imports.INCLUDED));
		}
		m.addAxioms(ont, axioms);
		axioms = new HashSet<>();
		for (OWLEntity e : ont.getSignature()) {
			axioms.addAll(sourceOntology.getAnnotationAssertionAxioms(e.getIRI()));
		}
		axioms.addAll(sourceOntology.getAnnotationAssertionAxioms(nobj.getIRI()));
		m.addAxioms(ont, axioms);

		GraphDocument gd = fromOwl.generateGraphDocument(ont);
		return OgJsonGenerator.render(gd);
	}
	else {
		return "{}";
	}

}
 
Example 3
Source File: Mooncat.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * removes external entities:
 *  - anything marked with IAO_0000412 is removed
 *  - if isMain is true then anything that is also present in an external ontology is removed
 * 
 * @param isMain
 * @param ont
 */
public void removeExternalEntities(boolean isMain, OWLOntology ont) {
	Set<OWLEntity> objs = ont.getSignature(Imports.EXCLUDED);
	Set<OWLClass> rmClasses = new HashSet<OWLClass>();
	Set<OWLObjectProperty> rmProperties = new HashSet<OWLObjectProperty>();
	Set<OWLIndividual> rmIndividuals = new HashSet<OWLIndividual>();
	LOG.info("removing external entities marked with IAO_0000412 from: "+ont);
	if (isMain) {
		LOG.info("testing " + objs.size()
				+ " objs to see if they are contained in the follow referenced ontologies: "
				+ getReferencedOntologies());
	}
	for (OWLEntity obj : objs) {
		final boolean isMarked = isImportMarkedEntity(obj, ont);
		if (obj instanceof OWLClass) {
			if ((isMain && isInExternalOntology(obj)) || isMarked) {
				rmClasses.add((OWLClass) obj);
			}
		}
		else if (obj instanceof OWLObjectProperty && isMarked) {
			rmProperties.add((OWLObjectProperty) obj);
		}
		else if (obj instanceof OWLIndividual  && isMarked) {
			rmIndividuals.add((OWLIndividual) obj);
		}
	}
	Set<OWLAxiom> rmAxioms = new HashSet<OWLAxiom>();
	for (OWLClass c : rmClasses) {
		rmAxioms.addAll(ont.getAnnotationAssertionAxioms(c.getIRI()));
		rmAxioms.addAll(ont.getDeclarationAxioms(c));
		rmAxioms.addAll(ont.getAxioms(c, Imports.EXCLUDED));
	}
	for (OWLObjectProperty p : rmProperties) {
		rmAxioms.addAll(ont.getAnnotationAssertionAxioms(p.getIRI()));
		rmAxioms.addAll(ont.getDeclarationAxioms(p));
		rmAxioms.addAll(ont.getAxioms(p, Imports.EXCLUDED));
	}
	for (OWLIndividual i : rmIndividuals) {
		rmAxioms.addAll(ont.getAxioms(i, Imports.EXCLUDED));
	}
	if (!rmAxioms.isEmpty()) {
		LOG.info("Removing "+rmAxioms.size()+" external axioms for: "+ ont.getOntologyID());
		ont.getOWLOntologyManager().removeAxioms(ont, rmAxioms);
	}
}