Package org.semanticweb.owlapi.model

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


        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

        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

        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

        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

        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

    }

    @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

                + 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

        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

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

    @Test
    public void testUnsatisfiableClasses() throws OWLException {
        OWLOntologyManager m = create();
        OWLOntology o = loadPizzaOntology(m);
        // Create a console progress monitor. This will print the reasoner
        // progress out to the console.
        ReasonerProgressMonitor progressMonitor = new LoggingReasonerProgressMonitor(
                LOG, "testUnsatisfiableClasses");
View Full Code Here

TOP

Related Classes of org.semanticweb.owlapi.model.OWLOntologyManager

Copyright © 2018 www.massapicom. 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.