Search in sources :

Example 11 with OWLIndividual

use of org.semanticweb.owlapi.model.OWLIndividual in project webprotege by protegeproject.

the class GetIndividualsActionHandler method execute.

@Nonnull
@Override
public GetIndividualsResult execute(@Nonnull GetIndividualsAction action, @Nonnull ExecutionContext executionContext) {
    Stream<OWLNamedIndividual> stream;
    if (action.getType().isOWLThing()) {
        stream = rootOntology.getIndividualsInSignature(Imports.INCLUDED).stream();
    } else {
        stream = rootOntology.getImportsClosure().stream().flatMap(o -> o.getClassAssertionAxioms(action.getType()).stream()).map(OWLClassAssertionAxiom::getIndividual).filter(OWLIndividual::isNamed).map(OWLIndividual::asOWLNamedIndividual);
    }
    Counter counter = new Counter();
    List<OWLNamedIndividualData> individualsData = stream.peek(i -> counter.increment()).map(renderingManager::getRendering).filter(i -> {
        String searchString = action.getFilterString();
        return searchString.isEmpty() || StringUtils.containsIgnoreCase(i.getBrowserText(), searchString);
    }).distinct().sorted().collect(toList());
    PageRequest pageRequest = action.getPageRequest();
    Pager<OWLNamedIndividualData> pager = Pager.getPagerForPageSize(individualsData, pageRequest.getPageSize());
    Page<OWLNamedIndividualData> page = pager.getPage(pageRequest.getPageNumber());
    OWLClassData type = renderingManager.getRendering(action.getType());
    logger.info(BROWSING, "{} {} retrieved instances of {} ({})", projectId, executionContext.getUserId(), action.getType(), renderingManager.getRendering(action.getType()).getBrowserText());
    return new GetIndividualsResult(type, page, counter.getCount(), individualsData.size());
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) RootOntology(edu.stanford.bmir.protege.web.server.inject.project.RootOntology) LoggerFactory(org.slf4j.LoggerFactory) OWLNamedIndividualData(edu.stanford.bmir.protege.web.shared.entity.OWLNamedIndividualData) Inject(javax.inject.Inject) PageRequest(edu.stanford.bmir.protege.web.shared.pagination.PageRequest) RenderingManager(edu.stanford.bmir.protege.web.server.renderer.RenderingManager) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) AccessManager(edu.stanford.bmir.protege.web.server.access.AccessManager) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Page(edu.stanford.bmir.protege.web.shared.pagination.Page) Imports(org.semanticweb.owlapi.model.parameters.Imports) Logger(org.slf4j.Logger) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) OWLClassAssertionAxiom(org.semanticweb.owlapi.model.OWLClassAssertionAxiom) VIEW_PROJECT(edu.stanford.bmir.protege.web.shared.access.BuiltInAction.VIEW_PROJECT) BuiltInAction(edu.stanford.bmir.protege.web.shared.access.BuiltInAction) Pager(edu.stanford.bmir.protege.web.server.pagination.Pager) GetIndividualsResult(edu.stanford.bmir.protege.web.shared.individualslist.GetIndividualsResult) AbstractProjectActionHandler(edu.stanford.bmir.protege.web.server.dispatch.AbstractProjectActionHandler) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) ExecutionContext(edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext) OWLClassData(edu.stanford.bmir.protege.web.shared.entity.OWLClassData) GetIndividualsAction(edu.stanford.bmir.protege.web.shared.individualslist.GetIndividualsAction) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) BROWSING(edu.stanford.bmir.protege.web.server.logging.Markers.BROWSING) OWLClassData(edu.stanford.bmir.protege.web.shared.entity.OWLClassData) PageRequest(edu.stanford.bmir.protege.web.shared.pagination.PageRequest) GetIndividualsResult(edu.stanford.bmir.protege.web.shared.individualslist.GetIndividualsResult) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) OWLNamedIndividualData(edu.stanford.bmir.protege.web.shared.entity.OWLNamedIndividualData) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual) Nonnull(javax.annotation.Nonnull)

Example 12 with OWLIndividual

use of org.semanticweb.owlapi.model.OWLIndividual 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 OWLIndividual

use of org.semanticweb.owlapi.model.OWLIndividual 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)

Example 14 with OWLIndividual

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

the class TestOntologySpaces method setup.

@BeforeClass
public static void setup() throws Exception {
    factory = onManager.getOntologySpaceFactory();
    if (factory == null)
        fail("Could not instantiate ontology space factory");
    OWLOntologyManager mgr = OWLOntologyManagerFactory.createOWLOntologyManager(onManager.getOfflineConfiguration().getOntologySourceLocations().toArray(new IRI[0]));
    OWLDataFactory df = mgr.getOWLDataFactory();
    ont = mgr.createOntology(baseIri);
    inMemorySrc = new RootOntologySource(ont);
    // Let's state that Linus is a human being
    OWLClass cHuman = df.getOWLClass(IRI.create(baseIri + "/" + Constants.humanBeing));
    OWLIndividual iLinus = df.getOWLNamedIndividual(IRI.create(baseIri + "/" + Constants.linus));
    linusIsHuman = df.getOWLClassAssertionAxiom(cHuman, iLinus);
    mgr.applyChange(new AddAxiom(ont, linusIsHuman));
    ont2 = mgr.createOntology(baseIri2);
    minorSrc = new RootOntologySource(ont2);
    dropSrc = getLocalSource("/ontologies/droppedcharacters.owl", mgr);
    nonexSrc = getLocalSource("/ontologies/nonexistentcharacters.owl", mgr);
    minorSrc = new RootOntologySource(ont2);
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) AddAxiom(org.semanticweb.owlapi.model.AddAxiom) RootOntologySource(org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource) OWLClass(org.semanticweb.owlapi.model.OWLClass) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual) BeforeClass(org.junit.BeforeClass)

Example 15 with OWLIndividual

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

the class OntologyNetworkConfigurationUtils method getScopesToActivate.

/**
 * Get the list of scopes to activate on startup
 *
 * @param config
 * @return
 */
public static String[] getScopesToActivate(OWLOntology config) {
    Set<OWLIndividual> scopes = cScope.getIndividuals(config);
    List<String> result = new ArrayList<String>();
    boolean doActivate = false;
    for (OWLIndividual iScope : scopes) {
        Set<OWLLiteral> activate = iScope.getDataPropertyValues(activateOnStart, config);
        Iterator<OWLLiteral> it = activate.iterator();
        while (it.hasNext() && !doActivate) {
            OWLLiteral l = it.next();
            doActivate |= Boolean.parseBoolean(l.getLiteral());
        }
        if (iScope.isNamed() && doActivate)
            result.add(((OWLNamedIndividual) iScope).getIRI().toString());
    }
    return result.toArray(EMPTY_IRI_ARRAY);
}
Also used : OWLLiteral(org.semanticweb.owlapi.model.OWLLiteral) ArrayList(java.util.ArrayList) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual)

Aggregations

OWLIndividual (org.semanticweb.owlapi.model.OWLIndividual)20 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)10 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)9 IRI (org.semanticweb.owlapi.model.IRI)7 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)6 OWLClass (org.semanticweb.owlapi.model.OWLClass)5 OWLNamedIndividual (org.semanticweb.owlapi.model.OWLNamedIndividual)5 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 RegistryContentException (org.apache.stanbol.ontologymanager.registry.api.RegistryContentException)4 Logger (org.slf4j.Logger)4 LinkedList (java.util.LinkedList)3 Graph (org.apache.clerezza.commons.rdf.Graph)3 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)3 OWLClassExpression (org.semanticweb.owlapi.model.OWLClassExpression)3 Atom (fr.lirmm.graphik.graal.api.core.Atom)2 Term (fr.lirmm.graphik.graal.api.core.Term)2 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)2 File (java.io.File)2