Search in sources :

Example 1 with OWLAnnotation

use of org.semanticweb.owlapi.model.OWLAnnotation 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 2 with OWLAnnotation

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

the class ConversionTester method testAxiomOwlToJenaResource.

public void testAxiomOwlToJenaResource() {
    JenaToOwlConvert j2o = new JenaToOwlConvert();
    OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
    OWLOntology ont = null;
    try {
        ont = mgr.createOntology();
    } catch (OWLOntologyCreationException e) {
        e.printStackTrace();
        fail("Can not create ontology");
    }
    OWLDataFactory factory = mgr.getOWLDataFactory();
    StmtIterator resource = null;
    OWLClass cls = factory.getOWLClass(IRI.create(CLAZZ));
    OWLDataProperty dp = factory.getOWLDataProperty(IRI.create(DP));
    OWLObjectProperty op = factory.getOWLObjectProperty(IRI.create(OP));
    OWLAnnotationProperty oa = factory.getOWLAnnotationProperty(IRI.create(label));
    OWLAnnotation oav = factory.getOWLAnnotation(oa, factory.getOWLStringLiteral(clazzlabel, "en"));
    OWLDatatype dt = factory.getOWLDatatype(IRI.create(DATATYPE));
    OWLNamedIndividual sub = factory.getOWLNamedIndividual(IRI.create(SUBJECT));
    OWLNamedIndividual obj = factory.getOWLNamedIndividual(IRI.create(OBJECT));
    OWLLiteral literal1 = factory.getOWLTypedLiteral(VALUE, dt);
    // Classe
    OWLDeclarationAxiom daxiomcls = factory.getOWLDeclarationAxiom(cls);
    // obj prop
    OWLDeclarationAxiom daxiomop = factory.getOWLDeclarationAxiom(op);
    // data prop
    OWLDeclarationAxiom daxiomdp = factory.getOWLDeclarationAxiom(dp);
    // subject
    OWLDeclarationAxiom daxiomsub = factory.getOWLDeclarationAxiom(sub);
    // object
    OWLDeclarationAxiom daxiomobj = factory.getOWLDeclarationAxiom(obj);
    // Istanza
    OWLClassAssertionAxiom axiomsub = factory.getOWLClassAssertionAxiom(cls, sub);
    // Istanza
    OWLClassAssertionAxiom axiomobj = factory.getOWLClassAssertionAxiom(cls, obj);
    // Obj
    OWLObjectPropertyAssertionAxiom axiomop = factory.getOWLObjectPropertyAssertionAxiom(op, sub, obj);
    // prop
    // tra
    // individui
    OWLDataPropertyAssertionAxiom axiomvalue = factory.getOWLDataPropertyAssertionAxiom(dp, obj, // Dataprop all'istanza;
    literal1);
    // Annotazione
    OWLAnnotationAssertionAxiom axioman = factory.getOWLAnnotationAssertionAxiom(cls.getIRI(), oav);
    mgr.addAxiom(ont, daxiomcls);
    mgr.addAxiom(ont, daxiomop);
    mgr.addAxiom(ont, daxiomdp);
    mgr.addAxiom(ont, daxiomsub);
    mgr.addAxiom(ont, daxiomobj);
    mgr.addAxiom(ont, axiomsub);
    mgr.addAxiom(ont, axiomobj);
    mgr.addAxiom(ont, axiomop);
    mgr.addAxiom(ont, axiomvalue);
    mgr.addAxiom(ont, axioman);
    Set<OWLAxiom> setaxiom = ont.getAxioms();
    try {
        resource = j2o.AxiomOwlToJenaResource(setaxiom, RDFXML);
        if (resource == null) {
            fail("Some errors occur");
        } else {
            String statment = "[http://www.w3.org/2000/01/rdf-schema#label, http://www.w3.org/2000/01/rdf-schema#range, http://www.w3.org/2000/01/rdf-schema#Literal] " + "[http://example.org/dummy#hasAge, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#DatatypeProperty] " + "[http://example.org/dummy#Linus, http://example.org/dummy#hasAge, \"8\"^^http://www.w3.org/2001/XMLSchema#int] " + "[http://example.org/dummy#Linus, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://example.org/dummy#Peanut] " + "[http://example.org/dummy#hasSibling, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#ObjectProperty] " + "[http://example.org/dummy#Lucy, http://example.org/dummy#hasSibling, http://example.org/dummy#Linus] " + "[http://example.org/dummy#Lucy, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://example.org/dummy#Peanut] " + "[http://www.w3.org/2000/01/rdf-schema#label, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#AnnotationProperty] " + "[http://example.org/dummy#Peanut, http://www.w3.org/2000/01/rdf-schema#label, \"Peanut\"@en] " + "[http://example.org/dummy#Peanut, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#Class]";
            int size = setaxiom.size();
            int count = 0;
            while (resource.hasNext()) {
                Statement stm = resource.nextStatement();
                Resource jsubj = stm.getSubject();
                if (jsubj.getURI().equals(OP.toString()) || jsubj.getURI().equals(DP.toString()) || jsubj.getURI().equals(CLAZZ.toString()) || jsubj.getURI().equals(OBJECT.toString()) || jsubj.getURI().equals(SUBJECT.toString()) || jsubj.getURI().equals(label.toString()))
                    if (statment.contains(stm.toString()))
                        count++;
            }
            assertEquals(size, count);
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Exception caugth");
    } finally {
        assertNotNull(resource);
    }
}
Also used : OWLDeclarationAxiom(org.semanticweb.owlapi.model.OWLDeclarationAxiom) OWLDatatype(org.semanticweb.owlapi.model.OWLDatatype) OWLAnnotationProperty(org.semanticweb.owlapi.model.OWLAnnotationProperty) OWLDataPropertyAssertionAxiom(org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom) OWLDataProperty(org.semanticweb.owlapi.model.OWLDataProperty) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom) OWLClassAssertionAxiom(org.semanticweb.owlapi.model.OWLClassAssertionAxiom) StmtIterator(com.hp.hpl.jena.rdf.model.StmtIterator) OWLAnnotationAssertionAxiom(org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom) OWLAnnotation(org.semanticweb.owlapi.model.OWLAnnotation) Statement(com.hp.hpl.jena.rdf.model.Statement) Resource(com.hp.hpl.jena.rdf.model.Resource) OWLObjectProperty(org.semanticweb.owlapi.model.OWLObjectProperty) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLLiteral(org.semanticweb.owlapi.model.OWLLiteral) OWLObjectPropertyAssertionAxiom(org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom) OWLClass(org.semanticweb.owlapi.model.OWLClass) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory)

Example 3 with OWLAnnotation

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

the class IRITreeBuilder method getClassLabel.

private String getClassLabel(OWLOntology ontology, OWLClass cls) {
    OWLDataFactory factory = ontology.getOWLOntologyManager().getOWLDataFactory();
    OWLAnnotationProperty label = factory.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI());
    String className = null;
    for (OWLAnnotation annotation : cls.getAnnotations(ontology, label)) {
        if (annotation.getValue() instanceof OWLLiteral) {
            OWLLiteral val = (OWLLiteral) annotation.getValue();
            className = val.getLiteral();
        }
        if (cls.getAnnotations(ontology, label).size() != 1) {
            throw new UnexpectedOntologyStructureException("More than one label for class " + cls);
        }
    }
    if (className != null) {
        return className;
    } else {
        throw new UnexpectedOntologyStructureException("There is no label for class " + cls);
    }
}
Also used : OWLAnnotationProperty(org.semanticweb.owlapi.model.OWLAnnotationProperty) OWLAnnotation(org.semanticweb.owlapi.model.OWLAnnotation) OWLLiteral(org.semanticweb.owlapi.model.OWLLiteral) UnexpectedOntologyStructureException(uk.ac.ebi.spot.goci.ontology.exception.UnexpectedOntologyStructureException) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory)

Example 4 with OWLAnnotation

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

the class AbstractOntologyLoader method removeExcludedClasses.

protected Set<OWLClass> removeExcludedClasses(OWLOntology ontology, Set<OWLClass> allClasses, SubclassCollector subclassCollector) {
    // remove excluded classes from allClasses by subclass
    if (getExclusionClassURI() != null) {
        OWLClass excludeClass = getFactory().getOWLClass(IRI.create(getExclusionClassURI()));
        subclassCollector.collect(excludeClass).forEach(allClasses::remove);
    }
    // remove excluded classes from allClasses by annotation property
    if (getExclusionAnnotationURI() != null) {
        OWLAnnotationProperty excludeAnnotation = getFactory().getOWLAnnotationProperty(IRI.create(getExclusionAnnotationURI()));
        Iterator<OWLClass> allClassesIt = allClasses.iterator();
        while (allClassesIt.hasNext()) {
            OWLClass owlClass = allClassesIt.next();
            Collection<OWLAnnotation> annotations = owlClass.getAnnotations(ontology, excludeAnnotation);
            if (!annotations.isEmpty()) {
                allClassesIt.remove();
            }
        }
    }
    // and return
    return allClasses;
}
Also used : OWLAnnotationProperty(org.semanticweb.owlapi.model.OWLAnnotationProperty) OWLAnnotation(org.semanticweb.owlapi.model.OWLAnnotation) OWLClass(org.semanticweb.owlapi.model.OWLClass)

Example 5 with OWLAnnotation

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

the class ConversionTester method testEntityOwlToJenaResource.

public void testEntityOwlToJenaResource() {
    JenaToOwlConvert j2o = new JenaToOwlConvert();
    OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
    OWLOntology ont = null;
    StmtIterator resource = null;
    try {
        ont = mgr.createOntology();
    } catch (OWLOntologyCreationException e) {
        e.printStackTrace();
        fail("Could not load ontology");
    }
    OWLDataFactory factory = mgr.getOWLDataFactory();
    OWLClass cls = factory.getOWLClass(IRI.create(CLAZZ));
    OWLDataProperty dp = factory.getOWLDataProperty(IRI.create(DP));
    OWLObjectProperty op = factory.getOWLObjectProperty(IRI.create(OP));
    OWLAnnotationProperty oa = factory.getOWLAnnotationProperty(IRI.create(label));
    OWLAnnotation oav = factory.getOWLAnnotation(oa, factory.getOWLStringLiteral(clazzlabel, "en"));
    OWLDatatype dt = factory.getOWLDatatype(IRI.create(DATATYPE));
    OWLNamedIndividual sub = factory.getOWLNamedIndividual(IRI.create(SUBJECT));
    OWLNamedIndividual obj = factory.getOWLNamedIndividual(IRI.create(OBJECT));
    OWLLiteral literal1 = factory.getOWLTypedLiteral(VALUE, dt);
    // Classe
    OWLDeclarationAxiom daxiomcls = factory.getOWLDeclarationAxiom(cls);
    // obj prop
    OWLDeclarationAxiom daxiomop = factory.getOWLDeclarationAxiom(op);
    // data prop
    OWLDeclarationAxiom daxiomdp = factory.getOWLDeclarationAxiom(dp);
    // subject
    OWLDeclarationAxiom daxiomsub = factory.getOWLDeclarationAxiom(sub);
    // object
    OWLDeclarationAxiom daxiomobj = factory.getOWLDeclarationAxiom(obj);
    // Istanza
    OWLClassAssertionAxiom axiomsub = factory.getOWLClassAssertionAxiom(cls, sub);
    // Istanza
    OWLClassAssertionAxiom axiomobj = factory.getOWLClassAssertionAxiom(cls, obj);
    // Obj
    OWLObjectPropertyAssertionAxiom axiomop = factory.getOWLObjectPropertyAssertionAxiom(op, sub, obj);
    // prop
    // tra
    // individui
    OWLDataPropertyAssertionAxiom axiomvalue = factory.getOWLDataPropertyAssertionAxiom(dp, sub, // Dataprop all'istanza;
    literal1);
    // Annotazione
    OWLAnnotationAssertionAxiom axioman = factory.getOWLAnnotationAssertionAxiom(cls.getIRI(), oav);
    mgr.addAxiom(ont, daxiomcls);
    mgr.addAxiom(ont, daxiomop);
    mgr.addAxiom(ont, daxiomdp);
    mgr.addAxiom(ont, daxiomsub);
    mgr.addAxiom(ont, daxiomobj);
    mgr.addAxiom(ont, axiomsub);
    mgr.addAxiom(ont, axiomobj);
    mgr.addAxiom(ont, axiomop);
    mgr.addAxiom(ont, axiomvalue);
    mgr.addAxiom(ont, axioman);
    Set<OWLIndividualAxiom> ind = ont.getAxioms(sub);
    try {
        resource = j2o.EntityOwlToJenaResource(daxiomsub.getEntity(), ont, RDFXML);
        if (resource == null) {
            fail("Some errors accour");
        } else {
            int cont = 0;
            while (resource.hasNext()) {
                Statement stm = resource.nextStatement();
                IRI subres = IRI.create(stm.getSubject().getURI());
                if (("<" + subres + ">").equals(daxiomsub.getEntity().toString()))
                    cont++;
            }
            assertEquals(ind.size(), (cont - 1));
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Exception caugth");
    } finally {
        assertNotNull(resource);
    }
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) OWLDeclarationAxiom(org.semanticweb.owlapi.model.OWLDeclarationAxiom) OWLDatatype(org.semanticweb.owlapi.model.OWLDatatype) OWLAnnotationProperty(org.semanticweb.owlapi.model.OWLAnnotationProperty) OWLDataPropertyAssertionAxiom(org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom) OWLDataProperty(org.semanticweb.owlapi.model.OWLDataProperty) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLClassAssertionAxiom(org.semanticweb.owlapi.model.OWLClassAssertionAxiom) StmtIterator(com.hp.hpl.jena.rdf.model.StmtIterator) OWLAnnotationAssertionAxiom(org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom) OWLAnnotation(org.semanticweb.owlapi.model.OWLAnnotation) Statement(com.hp.hpl.jena.rdf.model.Statement) OWLIndividualAxiom(org.semanticweb.owlapi.model.OWLIndividualAxiom) OWLObjectProperty(org.semanticweb.owlapi.model.OWLObjectProperty) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLLiteral(org.semanticweb.owlapi.model.OWLLiteral) OWLObjectPropertyAssertionAxiom(org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom) OWLClass(org.semanticweb.owlapi.model.OWLClass) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory)

Aggregations

OWLAnnotation (org.semanticweb.owlapi.model.OWLAnnotation)5 OWLAnnotationProperty (org.semanticweb.owlapi.model.OWLAnnotationProperty)5 OWLClass (org.semanticweb.owlapi.model.OWLClass)4 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)4 OWLLiteral (org.semanticweb.owlapi.model.OWLLiteral)4 OWLObjectProperty (org.semanticweb.owlapi.model.OWLObjectProperty)3 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)3 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)3 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)3 Statement (com.hp.hpl.jena.rdf.model.Statement)2 StmtIterator (com.hp.hpl.jena.rdf.model.StmtIterator)2 IRI (org.semanticweb.owlapi.model.IRI)2 OWLAnnotationAssertionAxiom (org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom)2 OWLClassAssertionAxiom (org.semanticweb.owlapi.model.OWLClassAssertionAxiom)2 OWLDataProperty (org.semanticweb.owlapi.model.OWLDataProperty)2 OWLDataPropertyAssertionAxiom (org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom)2 OWLDatatype (org.semanticweb.owlapi.model.OWLDatatype)2 OWLDeclarationAxiom (org.semanticweb.owlapi.model.OWLDeclarationAxiom)2 OWLNamedIndividual (org.semanticweb.owlapi.model.OWLNamedIndividual)2 OWLObjectPropertyAssertionAxiom (org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom)2