Search in sources :

Example 1 with Type

use of org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem.Type in project stanbol by apache.

the class RegistryManagerImpl method populateRegistry.

protected Registry populateRegistry(OWLOntology registry) throws RegistryContentException {
    log.debug("Populating registry content from ontology {}", registry);
    Registry reg = riFactory.createRegistry(registry);
    Set<OWLOntology> closure = registry.getOWLOntologyManager().getImportsClosure(registry);
    // Just scan all individuals. Recurse in case the registry imports more registries.
    for (OWLIndividual ind : registry.getIndividualsInSignature(true)) {
        // We do not allow anonymous registry items.
        if (ind.isAnonymous())
            continue;
        RegistryItem item = null;
        // IRI id = ind.asOWLNamedIndividual().getIRI();
        Type t = RegistryUtils.getType(ind, closure);
        if (t == null) {
            log.warn("Undetermined type for registry ontology individual {}", ind);
            continue;
        }
        switch(t) {
            case LIBRARY:
                log.debug("Found library for individual {}", ind);
                // Create the library and attach to parent and children
                item = populateLibrary(ind.asOWLNamedIndividual(), closure);
                reg.addChild(item);
                item.addRegistryContentListener(this);
                break;
            case ONTOLOGY:
                log.debug("Found ontology for individual {}", ind);
                // Create the ontology and attach to parent
                item = populateOntology(ind.asOWLNamedIndividual(), closure);
                item.addRegistryContentListener(this);
                // We don't know where to attach it within this method.
                break;
            default:
                break;
        }
    }
    try {
        reg.addRegistryContentListener(this);
        log.info("Registry {} added.", reg.getIRI());
        population.put(reg.getIRI(), reg);
    } catch (Exception e) {
        log.error("Invalid identifier for library item " + reg, e);
        return null;
    }
    return reg;
}
Also used : Type(org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem.Type) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) Registry(org.apache.stanbol.ontologymanager.registry.api.model.Registry) RegistryItem(org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntologyAlreadyExistsException(org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException) RegistryContentException(org.apache.stanbol.ontologymanager.registry.api.RegistryContentException) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual)

Aggregations

RegistryContentException (org.apache.stanbol.ontologymanager.registry.api.RegistryContentException)1 Registry (org.apache.stanbol.ontologymanager.registry.api.model.Registry)1 RegistryItem (org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem)1 Type (org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem.Type)1 OWLIndividual (org.semanticweb.owlapi.model.OWLIndividual)1 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)1 OWLOntologyAlreadyExistsException (org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException)1 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)1