Search in sources :

Example 1 with Origin

use of org.apache.stanbol.ontologymanager.servicesapi.io.Origin in project stanbol by apache.

the class AbstractOntologyCollectorImpl method addOntology.

@Override
public synchronized OWLOntologyID addOntology(OntologyInputSource<?> ontologySource) throws UnmodifiableOntologyCollectorException {
    // Check for error conditions.
    if (locked)
        throw new UnmodifiableOntologyCollectorException(this);
    if (ontologySource == null)
        throw new IllegalArgumentException("Ontology source cannot be null.");
    log.debug("Adding ontology to collector {}", getID());
    OWLOntologyID key = null;
    if (ontologySource.hasRootOntology()) {
        long before = System.currentTimeMillis();
        Object o = ontologySource.getRootOntology();
        // Check the origin anyhow, as it may be useful for setting aliases with physical locations etc.
        if (ontologySource.hasOrigin())
            key = ontologyProvider.loadInStore(o, false, ontologySource.getOrigin());
        else
            key = ontologyProvider.loadInStore(o, false);
        if (key != null) {
            managedOntologies.add(key);
            // Note that imported ontologies are not considered as managed! TODO should we change this?
            log.info("Add ontology completed in {} ms.", (System.currentTimeMillis() - before));
            // Fire the event
            fireOntologyAdded(key);
        }
    } else if (ontologySource.hasOrigin()) {
        // Just the origin : see if it is satisfiable
        log.debug("Checking origin satisfiability...");
        Origin<?> origin = ontologySource.getOrigin();
        Object ref = origin.getReference();
        log.debug("Origin wraps a {}", ref.getClass().getCanonicalName());
        if (ref instanceof org.semanticweb.owlapi.model.IRI)
            try {
                log.debug("Deferring addition to physical IRI {} (if available).", ref);
                key = addOntology(new RootOntologySource((org.semanticweb.owlapi.model.IRI) ref));
            } catch (OWLOntologyCreationException e) {
                throw new RuntimeException(e);
            }
        else if (ref instanceof IRI) {
            log.debug("Deferring addition to stored Clerezza graph {} (if available).", ref);
            key = addOntology(new GraphSource((IRI) ref));
        } else if (ref instanceof OWLOntologyID) {
            OWLOntologyID idref = (OWLOntologyID) ref;
            log.debug("Deferring addition to stored ontology with public key {} (if available).", ref);
            if (!ontologyProvider.hasOntology(idref))
                throw new MissingOntologyException(this, idref);
            key = idref;
            if (managedOntologies.add(idref))
                fireOntologyAdded(idref);
        } else
            throw new IllegalArgumentException("Invalid origin " + origin);
    } else
        throw new IllegalArgumentException("Ontology source must provide either an ontology object, or a way to reference one (i.e. an origin).");
    log.info("Public key : {}", key);
    return key;
}
Also used : Origin(org.apache.stanbol.ontologymanager.servicesapi.io.Origin) IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) MissingOntologyException(org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) UnmodifiableOntologyCollectorException(org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) RootOntologySource(org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource) GraphSource(org.apache.stanbol.ontologymanager.sources.clerezza.GraphSource)

Aggregations

BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)1 IRI (org.apache.clerezza.commons.rdf.IRI)1 MissingOntologyException (org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException)1 UnmodifiableOntologyCollectorException (org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException)1 Origin (org.apache.stanbol.ontologymanager.servicesapi.io.Origin)1 GraphSource (org.apache.stanbol.ontologymanager.sources.clerezza.GraphSource)1 RootOntologySource (org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource)1 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)1 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)1