Search in sources :

Example 1 with OWLAnnotationValue

use of org.semanticweb.owlapi.model.OWLAnnotationValue in project stanbol by apache.

the class RegistryManagerImpl method populateOntology.

protected RegistryOntology populateOntology(OWLNamedObject ind, Set<OWLOntology> registries) throws RegistryContentException {
    IRI ontId = ind.getIRI();
    RegistryItem ront = null;
    if (population.containsKey(ontId)) {
        // We are not allowing multityping either.
        ront = population.get(ontId);
        if (!(ront instanceof RegistryOntology))
            throw new RegistryContentException("Inconsistent multityping: for item " + ontId + " : {" + RegistryOntology.class + ", " + ront.getClass() + "}");
    } else {
        ront = riFactory.createRegistryOntology(ind);
        try {
            population.put(ront.getIRI(), ront);
        } catch (Exception e) {
            log.error("Invalid identifier for library item " + ront, e);
            return null;
        }
    }
    // EXIT nodes.
    Set<OWLNamedObject> libs = new HashSet<OWLNamedObject>();
    OWLDataFactory df = OWLManager.getOWLDataFactory();
    for (OWLOntology o : registries) {
        if (ind instanceof OWLIndividual) {
            // Get usages of isOntologyOf as an object property
            for (OWLIndividual value : ((OWLIndividual) ind).getObjectPropertyValues(isOntologyOf, o)) if (value.isNamed())
                libs.add(value.asOWLNamedIndividual());
            // Get usages of isOntologyOf as an annotation property
            for (OWLAnnotationAssertionAxiom ann : o.getAnnotationAssertionAxioms(ind.getIRI())) if (isOntologyOfAnn.equals(ann.getProperty())) {
                OWLAnnotationValue value = ann.getValue();
                if (value instanceof OWLNamedObject)
                    libs.add((OWLNamedObject) value);
                else if (value instanceof IRI)
                    libs.add(df.getOWLNamedIndividual((IRI) value));
            }
        }
    }
    for (OWLNamedObject ilib : libs) {
        IRI parentId = ilib.getIRI();
        // If some populate*() method has created it, it will be there.
        RegistryItem rlib = population.get(parentId);
        // Otherwise populating it will also put it in population.
        if (rlib == null)
            rlib = populateLibrary(ilib, registries);
        ront.addParent(rlib);
        if (ontologyIndex.get(ontId) == null)
            ontologyIndex.put(ontId, new HashSet<IRI>());
        ontologyIndex.get(ontId).add(parentId);
    }
    return (RegistryOntology) ront;
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) OWLAnnotationAssertionAxiom(org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom) RegistryOntology(org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntologyAlreadyExistsException(org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException) RegistryContentException(org.apache.stanbol.ontologymanager.registry.api.RegistryContentException) OWLNamedObject(org.semanticweb.owlapi.model.OWLNamedObject) OWLAnnotationValue(org.semanticweb.owlapi.model.OWLAnnotationValue) RegistryContentException(org.apache.stanbol.ontologymanager.registry.api.RegistryContentException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) RegistryItem(org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem) HashSet(java.util.HashSet) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual)

Example 2 with OWLAnnotationValue

use of org.semanticweb.owlapi.model.OWLAnnotationValue in project stanbol by apache.

the class RegistryManagerImpl method populateLibrary.

protected Library populateLibrary(OWLNamedObject ind, Set<OWLOntology> registries) throws RegistryContentException {
    IRI libId = ind.getIRI();
    RegistryItem lib = null;
    if (population.containsKey(libId)) {
        // We are not allowing multityping either.
        lib = population.get(libId);
        if (!(lib instanceof Library))
            throw new RegistryContentException("Inconsistent multityping: for item " + libId + " : {" + Library.class + ", " + lib.getClass() + "}");
    } else {
        lib = riFactory.createLibrary(ind);
        try {
            population.put(lib.getIRI(), lib);
        } catch (Exception e) {
            log.error("Invalid identifier for library item " + lib, e);
            return null;
        }
    }
    // EXIT nodes.
    Set<OWLNamedObject> ironts = new HashSet<OWLNamedObject>();
    OWLDataFactory df = OWLManager.getOWLDataFactory();
    for (OWLOntology o : registries) {
        if (ind instanceof OWLIndividual) {
            // Get usages of hasOntology as an object property
            for (OWLIndividual value : ((OWLIndividual) ind).getObjectPropertyValues(hasOntology, o)) if (value.isNamed())
                ironts.add(value.asOWLNamedIndividual());
            // Get usages of hasOntology as an annotation property
            for (OWLAnnotationAssertionAxiom ann : o.getAnnotationAssertionAxioms(ind.getIRI())) if (hasOntologyAnn.equals(ann.getProperty())) {
                OWLAnnotationValue value = ann.getValue();
                if (value instanceof OWLNamedObject)
                    ironts.add((OWLNamedObject) value);
                else if (value instanceof IRI)
                    ironts.add(df.getOWLNamedIndividual((IRI) value));
            }
        }
    }
    for (OWLNamedObject iront : ironts) {
        IRI childId = iront.getIRI();
        // If some populate*() method has created it, it will be there.
        RegistryItem ront = population.get(childId);
        // Otherwise populating it will also put it in population.
        if (ront == null)
            ront = populateOntology(iront, registries);
        lib.addChild(ront);
        if (ontologyIndex.get(childId) == null)
            ontologyIndex.put(childId, new HashSet<IRI>());
        ontologyIndex.get(childId).add(libId);
    }
    return (Library) lib;
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) OWLAnnotationAssertionAxiom(org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntologyAlreadyExistsException(org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException) RegistryContentException(org.apache.stanbol.ontologymanager.registry.api.RegistryContentException) OWLNamedObject(org.semanticweb.owlapi.model.OWLNamedObject) OWLAnnotationValue(org.semanticweb.owlapi.model.OWLAnnotationValue) RegistryContentException(org.apache.stanbol.ontologymanager.registry.api.RegistryContentException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) Library(org.apache.stanbol.ontologymanager.registry.api.model.Library) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) RegistryItem(org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem) HashSet(java.util.HashSet) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual)

Aggregations

HashSet (java.util.HashSet)2 RegistryContentException (org.apache.stanbol.ontologymanager.registry.api.RegistryContentException)2 RegistryItem (org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem)2 IRI (org.semanticweb.owlapi.model.IRI)2 OWLAnnotationAssertionAxiom (org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom)2 OWLAnnotationValue (org.semanticweb.owlapi.model.OWLAnnotationValue)2 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)2 OWLIndividual (org.semanticweb.owlapi.model.OWLIndividual)2 OWLNamedObject (org.semanticweb.owlapi.model.OWLNamedObject)2 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)2 OWLOntologyAlreadyExistsException (org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException)2 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)2 Library (org.apache.stanbol.ontologymanager.registry.api.model.Library)1 RegistryOntology (org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology)1