Examples of OWLOntologyManager


Examples of org.semanticweb.owlapi.model.OWLOntologyManager

    @Nonnull
    OWLPropertyExpression[] owlpropertyexpression = {};

    @Test
    public void testrun() throws Exception {
        OWLOntologyManager m = OWLManager.createOWLOntologyManager();
        m.getIRIMappers().add(new AutoIRIMapper(new File("."), false));
        OWLOntology o = m.loadOntologyFromOntologyDocument(getClass()
                .getResourceAsStream("/pizza.owl"));
        m.addAxiom(o, DF.getOWLDeclarationAxiom(DF.getOWLClass(iri)));
        m.addAxiom(
                o,
                DF.getOWLSubClassOfAxiom(c,
                        DF.getOWLClass(string, prefixmanager)));
        m.addAxiom(o, DF.getOWLEquivalentClassesAxiom(DF.getOWLClass(iri), c));
        m.addAxiom(o, DF.getOWLDisjointClassesAxiom(DF.getOWLClass(iri), c));
        m.addAxiom(o, DF.getOWLSubObjectPropertyOfAxiom(op, op));
        m.addAxiom(o, DF.getOWLSubPropertyChainOfAxiom(
                listowlobjectpropertyexpression, op));
        m.addAxiom(o, DF.getOWLEquivalentObjectPropertiesAxiom(setop));
        m.addAxiom(o, DF.getOWLDisjointObjectPropertiesAxiom(setop));
        m.addAxiom(o, DF.getOWLInverseObjectPropertiesAxiom(op, op));
        m.addAxiom(o, DF.getOWLObjectPropertyDomainAxiom(op, c));
        m.addAxiom(o, DF.getOWLObjectPropertyRangeAxiom(op, c));
        m.addAxiom(o, DF.getOWLFunctionalObjectPropertyAxiom(op));
        m.addAxiom(o,
                DF.getOWLAnnotationAssertionAxiom(ap, as, owlannotationvalue));
        m.applyChange(new AddImport(o, DF.getOWLImportsDeclaration(iri)));
        m.addAxiom(o, DF.getOWLAnnotationPropertyDomainAxiom(ap, iri));
        m.addAxiom(o, DF.getOWLAnnotationPropertyRangeAxiom(ap, iri));
        m.addAxiom(o, DF.getOWLSubAnnotationPropertyOfAxiom(ap, ap));
        m.addAxiom(o, DF.getOWLInverseFunctionalObjectPropertyAxiom(op));
        m.addAxiom(o, DF.getOWLReflexiveObjectPropertyAxiom(op));
        m.addAxiom(o, DF.getOWLIrreflexiveObjectPropertyAxiom(op));
        m.addAxiom(o, DF.getOWLSymmetricObjectPropertyAxiom(op));
        m.addAxiom(o, DF.getOWLAsymmetricObjectPropertyAxiom(op));
        m.addAxiom(o, DF.getOWLTransitiveObjectPropertyAxiom(op));
        m.addAxiom(o, DF.getOWLSubDataPropertyOfAxiom(dp, dp));
        m.addAxiom(o, DF.getOWLEquivalentDataPropertiesAxiom(setdp));
        m.addAxiom(o, DF.getOWLDisjointDataPropertiesAxiom(setdp));
        m.addAxiom(o, DF.getOWLDataPropertyDomainAxiom(dp, c));
        m.addAxiom(o, DF.getOWLDataPropertyRangeAxiom(dp, dr));
        m.addAxiom(o, DF.getOWLFunctionalDataPropertyAxiom(dp));
        m.addAxiom(o, DF.getOWLHasKeyAxiom(c, setowlpropertyexpression));
        m.addAxiom(o, DF.getOWLDatatypeDefinitionAxiom(owldatatype, dr));
        m.addAxiom(o, DF.getOWLSameIndividualAxiom(setowlindividual));
        m.addAxiom(o, DF.getOWLDifferentIndividualsAxiom(setowlindividual));
        m.addAxiom(o, DF.getOWLClassAssertionAxiom(c, ai));
        m.addAxiom(o, DF.getOWLObjectPropertyAssertionAxiom(op, ai, ai));
        m.addAxiom(o, DF.getOWLNegativeObjectPropertyAssertionAxiom(op, ai, ai));
        m.addAxiom(o, DF.getOWLDataPropertyAssertionAxiom(dp, ai, owlliteral));
        m.addAxiom(o,
                DF.getOWLNegativeDataPropertyAssertionAxiom(dp, ai, owlliteral));
        m.addAxiom(
                o,
                DF.getOWLInverseObjectPropertiesAxiom(op,
                        DF.getOWLObjectInverseOf(op)));
        m.addAxiom(
                o,
                DF.getOWLSubClassOfAxiom(c,
                        DF.getOWLDataExactCardinality(1, dp)));
        m.addAxiom(o,
                DF.getOWLSubClassOfAxiom(c, DF.getOWLDataMaxCardinality(1, dp)));
        m.addAxiom(o,
                DF.getOWLSubClassOfAxiom(c, DF.getOWLDataMinCardinality(1, dp)));
        m.addAxiom(
                o,
                DF.getOWLSubClassOfAxiom(c,
                        DF.getOWLObjectExactCardinality(1, op)));
        m.addAxiom(
                o,
                DF.getOWLSubClassOfAxiom(c,
                        DF.getOWLObjectMaxCardinality(1, op)));
        m.addAxiom(
                o,
                DF.getOWLSubClassOfAxiom(c,
                        DF.getOWLObjectMinCardinality(1, op)));
        m.addAxiom(
                o,
                DF.getOWLDataPropertyRangeAxiom(dp,
                        DF.getOWLDatatype(string, prefixmanager)));
        m.addAxiom(
                o,
                DF.getOWLDataPropertyAssertionAxiom(dp, ai,
                        DF.getOWLLiteral(string, owldatatype)));
        m.addAxiom(
                o,
                DF.getOWLDataPropertyRangeAxiom(dp,
                        DF.getOWLDataOneOf(owlliteral)));
        m.addAxiom(o,
                DF.getOWLDataPropertyRangeAxiom(dp, DF.getOWLDataUnionOf(dr)));
        m.addAxiom(
                o,
                DF.getOWLDataPropertyRangeAxiom(dp,
                        DF.getOWLDataIntersectionOf(dr)));
        m.addAxiom(o,
                DF.getOWLDataPropertyRangeAxiom(dp, DF
                        .getOWLDatatypeRestriction(owldatatype, owlfacet,
                                owlliteral)));
        m.addAxiom(
                o,
                DF.getOWLDataPropertyRangeAxiom(
                        dp,
                        DF.getOWLDatatypeRestriction(owldatatype,
                                DF.getOWLFacetRestriction(owlfacet, 1))));
        m.addAxiom(
                o,
                DF.getOWLSubClassOfAxiom(
                        c,
                        DF.getOWLObjectIntersectionOf(c,
                                DF.getOWLClass(string, prefixmanager))));
        m.addAxiom(o, DF.getOWLSubClassOfAxiom(c,
                DF.getOWLDataSomeValuesFrom(dp, dr)));
        m.addAxiom(o,
                DF.getOWLSubClassOfAxiom(c, DF.getOWLDataAllValuesFrom(dp, dr)));
        m.addAxiom(
                o,
                DF.getOWLSubClassOfAxiom(c,
                        DF.getOWLDataHasValue(dp, owlliteral)));
        m.addAxiom(
                o,
                DF.getOWLSubClassOfAxiom(c,
                        DF.getOWLObjectComplementOf(DF.getOWLClass(iri))));
        m.addAxiom(
                o,
                DF.getOWLSubClassOfAxiom(c,
                        DF.getOWLObjectOneOf(DF.getOWLNamedIndividual(iri))));
        m.addAxiom(o, DF.getOWLSubClassOfAxiom(c,
                DF.getOWLObjectAllValuesFrom(op, c)));
        m.addAxiom(
                o,
                DF.getOWLSubClassOfAxiom(c,
                        DF.getOWLObjectSomeValuesFrom(op, c)));
        m.addAxiom(o,
                DF.getOWLSubClassOfAxiom(c, DF.getOWLObjectHasValue(op, ai)));
        m.addAxiom(
                o,
                DF.getOWLSubClassOfAxiom(c,
                        DF.getOWLObjectUnionOf(DF.getOWLClass(iri))));
        m.addAxiom(
                o,
                DF.getOWLAnnotationAssertionAxiom(iri,
                        DF.getOWLAnnotation(ap, owlannotationvalue)));
        m.addAxiom(o, DF.getOWLAnnotationAssertionAxiom(DF
                .getOWLNamedIndividual(iri).getIRI(), DF.getOWLAnnotation(ap,
                owlannotationvalue)));
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ObjectOutputStream stream = new ObjectOutputStream(out);
        stream.writeObject(m);
        stream.flush();
        // System.out.println(out.toString());
        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        ObjectInputStream inStream = new ObjectInputStream(in);
        OWLOntologyManager copy = (OWLOntologyManager) inStream.readObject();
        for (OWLOntology onto : copy.getOntologies()) {
            OWLOntology original = m.getOntology(onto.getOntologyID()
                    .getOntologyIRI().get());
            assertEquals("Troubles with ontology " + onto.getOntologyID(),
                    original.getAxioms(), onto.getAxioms());
        }
View Full Code Here

Examples of org.semanticweb.owlapi.model.OWLOntologyManager

        }
    }

    @Test
    public void testSaveOntology() throws Exception {
        OWLOntologyManager m = create();
        OWLOntology o = loadPizzaOntology(m);
        assertNotNull(o);
        File output = temporaryFolder.newFile("saved_pizza.owl");
        // Output will be deleted on exit; to keep temporary file replace
        // previous line with the following
        // File output = File.createTempFile("saved_pizza", ".owl");
        IRI documentIRI2 = IRI.create(output);
        // save in OWL/XML format
        m.saveOntology(o, new OWLXMLDocumentFormat(), documentIRI2);
        // save in RDF/XML
        m.saveOntology(o, documentIRI2);
        // print out the ontology
        StringDocumentTarget target = new StringDocumentTarget();
        m.saveOntology(o, target);
        // Remove the ontology from the manager
        m.removeOntology(o);
    }
View Full Code Here

Examples of org.semanticweb.owlapi.model.OWLOntologyManager

        m.removeOntology(o);
    }

    @Test
    public void testIRIMapper() throws Exception {
        OWLOntologyManager m = OWLManager.createOWLOntologyManager();
        // map the ontology IRI to a physical IRI (files for example)
        // Create the document IRI for our ontology
        File output = temporaryFolder.newFile("saved_pizza.owl");
        // Output will be deleted on exit; to keep temporary file replace
        // previous line with the following
        // File output = File.createTempFile("saved_pizza", ".owl");
        IRI documentIRI = IRI.create(output);
        // Set up a mapping, which maps the ontology to the document IRI
        SimpleIRIMapper mapper = new SimpleIRIMapper(EXAMPLE_SAVE_IRI,
                documentIRI);
        m.getIRIMappers().add(mapper);
        // set up a mapper to read local copies of ontologies
        File localFolder = new File("materializedOntologies");
        // the manager will look up an ontology IRI by checking
        // localFolder first for a local copy, checking its subfolders as well
        m.getIRIMappers().add(new AutoIRIMapper(localFolder, true));
        // Create the ontology - we use the ontology IRI (not the physical URI)
        OWLOntology o = m.createOntology(EXAMPLE_SAVE_IRI);
        // save the ontology to its physical location - documentIRI
        m.saveOntology(o);
        assertNotNull(o);
    }
View Full Code Here

Examples of org.semanticweb.owlapi.model.OWLOntologyManager

        assertNotNull(o);
    }

    @Test
    public void testAddAxioms() throws OWLException {
        OWLOntologyManager m = create();
        OWLOntology o = m.createOntology(KOALA_IRI);
        // class A and class B
        OWLClass clsA = df.getOWLClass(IRI.create(KOALA_IRI + "#A"));
        OWLClass clsB = df.getOWLClass(IRI.create(KOALA_IRI + "#B"));
        // Now create the axiom
        OWLAxiom axiom = df.getOWLSubClassOfAxiom(clsA, clsB);
        // add the axiom to the ontology.
        AddAxiom addAxiom = new AddAxiom(o, axiom);
        // We now use the manager to apply the change
        m.applyChange(addAxiom);
        // remove the axiom from the ontology
        RemoveAxiom removeAxiom = new RemoveAxiom(o, axiom);
        m.applyChange(removeAxiom);
    }
View Full Code Here

Examples of org.semanticweb.owlapi.model.OWLOntologyManager

        m.applyChange(removeAxiom);
    }

    @Test
    public void testAssertedSuperclasses() throws OWLException {
        OWLOntologyManager m = create();
        OWLOntology o = loadPizzaOntology(m);
        OWLClass quokkaCls = df.getOWLClass(IRI.create(KOALA_IRI + "#Quokka"));
        Collection<OWLSubClassOfAxiom> classes = o
                .getSubClassAxiomsForSubClass(quokkaCls);
        // for each superclass there will be a corresponding axiom
View Full Code Here

Examples of org.semanticweb.owlapi.model.OWLOntologyManager

        assertEquals(2, classes.size());
    }

    @Test
    public void testSWRL() throws OWLException {
        OWLOntologyManager m = create();
        OWLOntology o = m.createOntology(EXAMPLE_IRI);
        // Get hold of references to class A and class B.
        OWLClass clsA = df.getOWLClass(IRI.create(EXAMPLE_IRI + "#A"));
        OWLClass clsB = df.getOWLClass(IRI.create(EXAMPLE_IRI + "#B"));
        SWRLVariable var = df.getSWRLVariable(IRI.create(EXAMPLE_IRI + "#x"));
        Set<SWRLClassAtom> body = Collections.singleton(df.getSWRLClassAtom(
                clsA, var));
        Set<SWRLClassAtom> head = Collections.singleton(df.getSWRLClassAtom(
                clsB, var));
        SWRLRule rule = df.getSWRLRule(body, head);
        m.applyChange(new AddAxiom(o, rule));
        OWLObjectProperty prop = df.getOWLObjectProperty(IRI.create(EXAMPLE_IRI
                + "#propA"));
        OWLObjectProperty propB = df.getOWLObjectProperty(IRI
                .create(EXAMPLE_IRI + "#propB"));
        SWRLObjectPropertyAtom propAtom = df.getSWRLObjectPropertyAtom(prop,
                var, var);
        SWRLObjectPropertyAtom propAtom2 = df.getSWRLObjectPropertyAtom(propB,
                var, var);
        Set<SWRLAtom> antecedent = new HashSet<>();
        antecedent.add(propAtom);
        antecedent.add(propAtom2);
        SWRLRule rule2 = df.getSWRLRule(antecedent,
                Collections.singleton(propAtom));
        m.applyChange(new AddAxiom(o, rule2));
    }
View Full Code Here

Examples of org.semanticweb.owlapi.model.OWLOntologyManager

        m.applyChange(new AddAxiom(o, rule2));
    }

    @Test
    public void testIndividualAssertions() throws OWLException {
        OWLOntologyManager m = create();
        OWLOntology o = m.createOntology(EXAMPLE_IRI);
        // We want to state that matthew has a father who is peter.
        OWLIndividual matthew = df.getOWLNamedIndividual(IRI.create(EXAMPLE_IRI
                + "#matthew"));
        OWLIndividual peter = df.getOWLNamedIndividual(IRI.create(EXAMPLE_IRI
                + "#peter"));
        // We need the hasFather property
        OWLObjectProperty hasFather = df.getOWLObjectProperty(IRI
                .create(EXAMPLE_IRI + "#hasFather"));
        // matthew --> hasFather --> peter
        OWLObjectPropertyAssertionAxiom assertion = df
                .getOWLObjectPropertyAssertionAxiom(hasFather, matthew, peter);
        // Finally, add the axiom to our ontology and save
        AddAxiom addAxiomChange = new AddAxiom(o, assertion);
        m.applyChange(addAxiomChange);
        // matthew is an instance of Person
        OWLClass personClass = df.getOWLClass(IRI.create(EXAMPLE_IRI
                + "#Person"));
        OWLClassAssertionAxiom ax = df.getOWLClassAssertionAxiom(personClass,
                matthew);
        // Add this axiom to our ontology - with a convenience method
        m.addAxiom(o, ax);
    }
View Full Code Here

Examples of org.semanticweb.owlapi.model.OWLOntologyManager

    }

    @Test
    public void testDelete() throws OWLException {
        // Delete individuals representing countries
        OWLOntologyManager m = create();
        OWLOntology o = loadPizzaOntology(m);
        // Ontologies don't directly contain entities but axioms
        // OWLEntityRemover will remove an entity (class, property or
        // individual)
        // from a set of ontologies by removing all referencing axioms
        OWLEntityRemover remover = new OWLEntityRemover(
                Collections.singleton(o));
        int previousNumberOfIndividuals = o.getIndividualsInSignature().size();
        // Visit all individuals with the remover
        // Changes needed for removal will be prepared
        for (OWLNamedIndividual ind : o.getIndividualsInSignature()) {
            ind.accept(remover);
        }
        // Now apply the changes
        m.applyChanges(remover.getChanges());
        int size = o.getIndividualsInSignature().size();
        assertTrue(previousNumberOfIndividuals + " supposed to be larger than "
                + size, previousNumberOfIndividuals > size);
    }
View Full Code Here

Examples of org.semanticweb.owlapi.model.OWLOntologyManager

                + size, previousNumberOfIndividuals > size);
    }

    @Test
    public void testAddSomeRestriction() throws OWLException {
        OWLOntologyManager m = create();
        OWLOntology o = m.createOntology(EXAMPLE_IRI);
        // all Heads have parts that are noses (at least one)
        // We do this by creating an existential (some) restriction
        OWLObjectProperty hasPart = df.getOWLObjectProperty(IRI
                .create(EXAMPLE_IRI + "#hasPart"));
        OWLClass nose = df.getOWLClass(IRI.create(EXAMPLE_IRI + "#Nose"));
        // Now let's describe the class of individuals that have at
        // least one part that is a kind of nose
        OWLClassExpression hasPartSomeNose = df.getOWLObjectSomeValuesFrom(
                hasPart, nose);
        OWLClass head = df.getOWLClass(IRI.create(EXAMPLE_IRI + "#Head"));
        // Head subclass of our restriction
        OWLSubClassOfAxiom ax = df.getOWLSubClassOfAxiom(head, hasPartSomeNose);
        // Add the axiom to our ontology
        AddAxiom addAx = new AddAxiom(o, ax);
        m.applyChange(addAx);
    }
View Full Code Here

Examples of org.semanticweb.owlapi.model.OWLOntologyManager

        m.applyChange(addAx);
    }

    @Test
    public void testDatatypeRestriction() throws OWLException {
        OWLOntologyManager m = create();
        OWLOntology o = m.createOntology(EXAMPLE_IRI);
        // Adults have an age greater than 18.
        OWLDataProperty hasAge = df.getOWLDataProperty(IRI.create(EXAMPLE_IRI
                + "hasAge"));
        // Create the restricted data range by applying the facet restriction
        // with a value of 18 to int
        OWLDataRange greaterThan18 = df.getOWLDatatypeRestriction(
                df.getIntegerOWLDatatype(), OWLFacet.MIN_INCLUSIVE,
                df.getOWLLiteral(18));
        // Now we can use this in our datatype restriction on hasAge
        OWLClassExpression adultDefinition = df.getOWLDataSomeValuesFrom(
                hasAge, greaterThan18);
        OWLClass adult = df.getOWLClass(IRI.create(EXAMPLE_IRI + "#Adult"));
        OWLSubClassOfAxiom ax = df
                .getOWLSubClassOfAxiom(adult, adultDefinition);
        m.applyChange(new AddAxiom(o, ax));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.