Search in sources :

Example 6 with OWLClass

use of org.semanticweb.owlapi.model.OWLClass in project goci by EBISPOT.

the class AbstractOntologyLoader method getStringLiteralAnnotationValues.

protected Set<String> getStringLiteralAnnotationValues(OWLOntology ontology, OWLClass ontologyClass, OWLAnnotationProperty annotationProperty) {
    Set<String> vals = new HashSet<>();
    Collection<OWLAnnotation> annotations = ontologyClass.getAnnotations(ontology, annotationProperty);
    annotations.stream().filter(annotation -> annotation.getValue() instanceof OWLLiteral).forEach(annotation -> {
        OWLLiteral val = (OWLLiteral) annotation.getValue();
        vals.add(val.getLiteral());
    });
    return vals;
}
Also used : OWLRDFVocabulary(org.semanticweb.owlapi.vocab.OWLRDFVocabulary) OWLObjectProperty(org.semanticweb.owlapi.model.OWLObjectProperty) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) OWLAnnotation(org.semanticweb.owlapi.model.OWLAnnotation) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) OWLManager(org.semanticweb.owlapi.apibinding.OWLManager) Initializable(uk.ac.ebi.spot.goci.ontology.Initializable) HashSet(java.util.HashSet) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) IRI(org.semanticweb.owlapi.model.IRI) Map(java.util.Map) URI(java.net.URI) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) Resource(org.springframework.core.io.Resource) SimpleIRIMapper(org.semanticweb.owlapi.util.SimpleIRIMapper) Iterator(java.util.Iterator) Collection(java.util.Collection) OWLLiteral(org.semanticweb.owlapi.model.OWLLiteral) Set(java.util.Set) Collectors(java.util.stream.Collectors) OWLAnnotationProperty(org.semanticweb.owlapi.model.OWLAnnotationProperty) Optional(java.util.Optional) Collections(java.util.Collections) OWLClass(org.semanticweb.owlapi.model.OWLClass) OWLAnnotation(org.semanticweb.owlapi.model.OWLAnnotation) OWLLiteral(org.semanticweb.owlapi.model.OWLLiteral) HashSet(java.util.HashSet)

Example 7 with OWLClass

use of org.semanticweb.owlapi.model.OWLClass in project goci by EBISPOT.

the class AssertedOntologyLoader method indexOntology.

protected OWLOntology indexOntology(final OWLOntology ontology) throws OWLOntologyCreationException {
    Set<OWLClass> allClasses = ontology.getClassesInSignature();
    removeExcludedClasses(ontology, allClasses, superclass -> getSubClasses(ontology, superclass));
    int labelCount = 0;
    int labelledClassCount = 0;
    int synonymCount = 0;
    int synonymedClassCount = 0;
    getLog().debug("Loading labels and synonyms...");
    for (OWLClass ontologyClass : allClasses) {
        IRI clsIri = ontologyClass.getIRI();
        // get IRI fragment/path
        Optional<String> accession = evaluateAccessionValue(ontology, ontologyClass);
        if (accession.isPresent()) {
            addClassAccession(clsIri, accession.get());
        }
        // get label annotations
        Optional<String> label = evaluateLabelAnnotationValue(ontology, ontologyClass);
        if (label.isPresent()) {
            addClassLabel(clsIri, label.get());
            labelledClassCount++;
            labelCount++;
        }
        // get all synonym annotations
        getLog().debug("Loading synonyms...");
        Set<String> synonyms = evaluateSynonymAnnotationValues(ontology, ontologyClass);
        if (!synonyms.isEmpty()) {
            addSynonyms(clsIri, synonyms);
            synonymCount += synonyms.size();
            synonymedClassCount++;
        }
        // get parent labels
        getLog().debug("Loading parents...");
        Set<String> parentLabelSet = new HashSet<>();
        Set<OWLClass> parents = getSuperClasses(ontology, ontologyClass);
        // only add type if the parent isn't excluded
        parents.stream().filter(allClasses::contains).forEach(parentClass -> {
            getLog().debug("Next parent of " + label + ": " + parentClass);
            evaluateLabelAnnotationValue(ontology, parentClass).ifPresent(parentLabelSet::add);
        });
        addClassParentLabels(clsIri, parentLabelSet);
        // get child labels
        getLog().debug("Loading children...");
        Set<String> childLabelSet = new HashSet<>();
        // always add current class to the parents
        label.ifPresent(childLabelSet::add);
        Set<OWLClass> children = getSubClasses(ontology, ontologyClass);
        // only add type if the child isn't excluded
        children.stream().filter(allClasses::contains).forEach(childClass -> {
            getLog().debug("Next child of " + label + ": " + childClass);
            evaluateLabelAnnotationValue(ontology, childClass).ifPresent(childLabelSet::add);
        });
        addClassChildLabels(clsIri, childLabelSet);
    // todo - get relationships
    }
    getLog().debug("Successfully indexed " + labelCount + " labels on " + labelledClassCount + " classes and " + synonymCount + " synonyms on " + synonymedClassCount + " classes!");
    return ontology;
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) OWLClass(org.semanticweb.owlapi.model.OWLClass) HashSet(java.util.HashSet)

Example 8 with OWLClass

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

the class ClassAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.ClassAtom tmp = (org.apache.stanbol.rules.manager.atoms.ClassAtom) ruleAtom;
    OWLDataFactory factory = OWLManager.getOWLDataFactory();
    IObjectAtom classResource = tmp.getClassResource();
    IObjectAtom argument = tmp.getArgument1();
    SWRLAtom classResourceAtom = (SWRLAtom) adapter.adaptTo(classResource, SWRLRule.class);
    SWRLAtom argumentAtom = (SWRLAtom) adapter.adaptTo(argument, SWRLRule.class);
    OWLClass classPredicate;
    SWRLIArgument argumentResource;
    if (classResourceAtom instanceof ArgumentSWRLAtom) {
        classPredicate = factory.getOWLClass(IRI.create(((ArgumentSWRLAtom) classResourceAtom).getId()));
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    if (argumentAtom instanceof ArgumentSWRLAtom) {
        argumentResource = (SWRLIArgument) ((ArgumentSWRLAtom) argumentAtom).getSwrlArgument();
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    return (T) factory.getSWRLClassAtom(classPredicate, argumentResource);
}
Also used : ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) IObjectAtom(org.apache.stanbol.rules.manager.atoms.IObjectAtom) SWRLIArgument(org.semanticweb.owlapi.model.SWRLIArgument) SWRLAtom(org.semanticweb.owlapi.model.SWRLAtom) ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) SWRLRule(org.semanticweb.owlapi.model.SWRLRule) OWLClass(org.semanticweb.owlapi.model.OWLClass) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory)

Example 9 with OWLClass

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

the class SessionManagerResource method listSessions.

@GET
@Produces(value = { RDF_XML, OWL_XML, TURTLE, X_TURTLE, FUNCTIONAL_OWL, MANCHESTER_OWL, RDF_JSON, N3, N_TRIPLE, TEXT_PLAIN })
public Response listSessions(@Context UriInfo uriInfo, @Context HttpHeaders headers) {
    OWLOntologyManager ontMgr = OWLManager.createOWLOntologyManager();
    OWLDataFactory df = ontMgr.getOWLDataFactory();
    OWLClass cSession = df.getOWLClass(IRI.create("http://stanbol.apache.org/ontologies/meta/Session"));
    OWLOntology o;
    try {
        o = ontMgr.createOntology(IRI.create(uriInfo.getRequestUri()));
        List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
        for (String id : sessionManager.getRegisteredSessionIDs()) {
            IRI sessionid = IRI.create(sessionManager.getDefaultNamespace() + sessionManager.getID() + "/" + id);
            OWLNamedIndividual ind = df.getOWLNamedIndividual(sessionid);
            changes.add(new AddAxiom(o, df.getOWLClassAssertionAxiom(cSession, ind)));
        }
        ontMgr.applyChanges(changes);
    } catch (OWLOntologyCreationException e) {
        throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
    }
    ResponseBuilder rb = Response.ok(o);
    MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
    if (mediaType != null)
        rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
    //        addCORSOrigin(servletContext, rb, headers);
    return rb.build();
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) AddAxiom(org.semanticweb.owlapi.model.AddAxiom) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntologyChange(org.semanticweb.owlapi.model.OWLOntologyChange) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) MediaType(javax.ws.rs.core.MediaType) OWLClass(org.semanticweb.owlapi.model.OWLClass) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 10 with OWLClass

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

the class TestOWLAPIInputSources method testOfflineImport.

/**
     * Uses a {@link ParentPathInputSource} to load an ontology importing a modified FOAF, both located in the
     * same resource directory.
     * 
     * @throws Exception
     */
@Test
public void testOfflineImport() throws Exception {
    URL url = getClass().getResource("/ontologies/maincharacters.owl");
    assertNotNull(url);
    File f = new File(url.toURI());
    assertNotNull(f);
    OntologyInputSource<OWLOntology> coreSource = new ParentPathInputSource(f);
    // // Check that all the imports closure is made of local files
    // Set<OWLOntology> closure = coreSource.getImports(true);
    // for (OWLOntology o : closure)
    // assertEquals("file", o.getOWLOntologyManager().getOntologyDocumentIRI(o).getScheme());
    assertEquals(coreSource.getRootOntology().getOntologyID().getOntologyIRI(), IRI.create(Constants.PEANUTS_MAIN_BASE));
    // Linus is stated to be a foaf:Person
    OWLNamedIndividual iLinus = df.getOWLNamedIndividual(IRI.create(Constants.PEANUTS_MAIN_BASE + "#Linus"));
    // Lucy is stated to be a foaf:Perzon
    OWLNamedIndividual iLucy = df.getOWLNamedIndividual(IRI.create(Constants.PEANUTS_MAIN_BASE + "#Lucy"));
    OWLClass cPerzon = df.getOWLClass(IRI.create("http://xmlns.com/foaf/0.1/Perzon"));
    Set<OWLIndividual> instances = cPerzon.getIndividuals(coreSource.getRootOntology());
    assertTrue(!instances.contains(iLinus) && instances.contains(iLucy));
}
Also used : OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) OWLClass(org.semanticweb.owlapi.model.OWLClass) File(java.io.File) URL(java.net.URL) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual) Test(org.junit.Test)

Aggregations

OWLClass (org.semanticweb.owlapi.model.OWLClass)30 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)14 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)13 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)13 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)13 OWLObjectProperty (org.semanticweb.owlapi.model.OWLObjectProperty)11 IRI (org.semanticweb.owlapi.model.IRI)10 OWLDataProperty (org.semanticweb.owlapi.model.OWLDataProperty)10 OWLNamedIndividual (org.semanticweb.owlapi.model.OWLNamedIndividual)9 OWLAnnotationProperty (org.semanticweb.owlapi.model.OWLAnnotationProperty)8 OWLAnnotationAssertionAxiom (org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom)6 OWLLiteral (org.semanticweb.owlapi.model.OWLLiteral)6 AddAxiom (org.semanticweb.owlapi.model.AddAxiom)5 OWLClassAssertionAxiom (org.semanticweb.owlapi.model.OWLClassAssertionAxiom)5 OWLDataPropertyAssertionAxiom (org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom)5 OWLIndividual (org.semanticweb.owlapi.model.OWLIndividual)5 OWLObjectPropertyAssertionAxiom (org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom)5 OntClass (com.hp.hpl.jena.ontology.OntClass)4 OntModel (com.hp.hpl.jena.ontology.OntModel)4 OWLAnnotation (org.semanticweb.owlapi.model.OWLAnnotation)4