Search in sources :

Example 11 with Registry

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

the class RegistryManagerImpl method computeBestCandidate.

/**
     * @deprecated with each library having its own cache, load balancing is no longer necessary
     * @return
     */
protected Registry computeBestCandidate(Library lib) {
    Map<IRI, Float> loadFactors = computeLoadFactors();
    IRI current = null;
    float lowest = 1.0f;
    for (RegistryItem item : lib.getParents()) {
        IRI iri = item.getIRI();
        if (loadFactors.containsKey(iri)) {
            float f = loadFactors.get(iri);
            if (f < lowest) {
                lowest = f;
                current = iri;
            }
        }
    }
    return (Registry) (population.get(current));
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) Registry(org.apache.stanbol.ontologymanager.registry.api.model.Registry) RegistryItem(org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem)

Example 12 with Registry

use of org.apache.stanbol.ontologymanager.registry.api.model.Registry 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)

Example 13 with Registry

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

the class RegistryUtils method containsOntologyRecursive.

/**
     * Utility method to recurse into registry items.
     * 
     * TODO: move this to main?
     * 
     * @param item
     * @param ontologyId
     * @return
     */
public static boolean containsOntologyRecursive(RegistryItem item, IRI ontologyId) {
    boolean result = false;
    if (item instanceof RegistryOntology) {
        // An Ontology MUST have a non-null URI.
        try {
            IRI iri = item.getIRI();
            result |= iri.equals(ontologyId);
        } catch (Exception e) {
            return false;
        }
    } else if (item instanceof Library || item instanceof Registry)
        // Inspect children
        for (RegistryItem child : item.getChildren()) {
            result |= containsOntologyRecursive(child, ontologyId);
            if (result)
                break;
        }
    return result;
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) RegistryOntology(org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology) Library(org.apache.stanbol.ontologymanager.registry.api.model.Library) Registry(org.apache.stanbol.ontologymanager.registry.api.model.Registry) RegistryItem(org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem)

Aggregations

Registry (org.apache.stanbol.ontologymanager.registry.api.model.Registry)13 RegistryItem (org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem)12 Library (org.apache.stanbol.ontologymanager.registry.api.model.Library)8 Test (org.junit.Test)7 IRI (org.semanticweb.owlapi.model.IRI)6 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)6 RegistryManagerImpl (org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 RegistryContentException (org.apache.stanbol.ontologymanager.registry.api.RegistryContentException)3 RegistryOntology (org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology)3 ClerezzaOntologyProvider (org.apache.stanbol.ontologymanager.multiplexer.clerezza.ontology.ClerezzaOntologyProvider)2 OWLIndividual (org.semanticweb.owlapi.model.OWLIndividual)2 OWLObject (org.semanticweb.owlapi.model.OWLObject)2 OWLOntologyAlreadyExistsException (org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException)2 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)2 Hashtable (java.util.Hashtable)1 Type (org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem.Type)1 IRIDocumentSource (org.semanticweb.owlapi.io.IRIDocumentSource)1 OWLOntologyDocumentSource (org.semanticweb.owlapi.io.OWLOntologyDocumentSource)1