Examples of OWLDataFactory


Examples of org.semanticweb.owl.model.OWLDataFactory

  private static boolean populate(URI uri, int instances, URI outputFile){
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLOntology ontology = loadOntology(manager, uri);
    if (ontology != null){
      try {
        OWLDataFactory factory = manager.getOWLDataFactory();
        VocabularyManager vManager = new VocabularyManager(ontology);
        List<OWLClass> classes = new Vector<OWLClass>(vManager.getConceptSet());
       
        List<OWLAxiomChange> toAdd = new Vector<OWLAxiomChange>();
        for (int i = 0; i < instances; i++) {
          int rnd = m_random.nextInt(classes.size());
          OWLClassAssertionAxiom newAxiom = factory.getOWLClassAssertionAxiom(newIndividual(factory), classes.get(rnd));
          toAdd.add(new AddAxiom(ontology,newAxiom))
          System.out.println((i+1)+"- new axiom: "+newAxiom.toString());
        }       
        manager.applyChanges(toAdd);
        OutputStreamWriter sw = new FileWriter(new File(outputFile));
View Full Code Here

Examples of org.semanticweb.owlapi.model.OWLDataFactory

            @Nonnull OWLOntology ontology,
            @Nullable AnnotationCardinalityReporter reporter,
            @Nullable AnnotationCardinalityConfictHandler handler)
            throws AnnotationCardinalityException {
        OWLOntologyManager manager = ontology.getOWLOntologyManager();
        OWLDataFactory factory = manager.getOWLDataFactory();
        Set<OWLAnnotationProperty> headerProperties = getProperties(factory,
                OboFormatTag.TAG_ONTOLOGY, OboFormatTag.TAG_FORMAT_VERSION,
                OboFormatTag.TAG_DATE, OboFormatTag.TAG_DEFAULT_NAMESPACE,
                OboFormatTag.TAG_SAVED_BY, OboFormatTag.TAG_AUTO_GENERATED_BY);
        checkOntologyAnnotations(headerProperties, ontology, reporter, handler,
View Full Code Here

Examples of org.semanticweb.owlapi.model.OWLDataFactory

        OBODoc oboDocSource = parseOBOFile("roundtrip_cardinality.obo");
        // convert to OWL and retrieve def
        OWLAPIObo2Owl bridge = new OWLAPIObo2Owl(
                OWLManager.createOWLOntologyManager());
        OWLOntology owlOntology = bridge.convert(oboDocSource);
        OWLDataFactory factory = owlOntology.getOWLOntologyManager()
                .getOWLDataFactory();
        OWLClass c = factory.getOWLClass(bridge.oboIdToIRI("PR:000027136"));
        // Relations
        boolean foundRel1 = false;
        boolean foundRel2 = false;
        Set<OWLSubClassOfAxiom> axioms = owlOntology
                .getSubClassAxiomsForSubClass(c);
View Full Code Here

Examples of org.semanticweb.owlapi.model.OWLDataFactory

        oboDocSource.addTermFrame(sourceFrame);
        // convert to OWL and retrieve def
        OWLAPIObo2Owl bridge = new OWLAPIObo2Owl(
                OWLManager.createOWLOntologyManager());
        OWLOntology owlOntology = bridge.convert(oboDocSource);
        OWLDataFactory factory = owlOntology.getOWLOntologyManager()
                .getOWLDataFactory();
        // IRI
        IRI iri = bridge.oboIdToIRI("CARO:0000049");
        OWLClass c = factory.getOWLClass(iri);
        // Def
        OWLAnnotationProperty defProperty = factory
                .getOWLAnnotationProperty(Obo2OWLVocabulary.IRI_IAO_0000115
                        .getIRI());
        int counter = 0;
        for (OWLAnnotationAssertionAxiom ax : owlOntology
                .getAnnotationAssertionAxioms(c.getIRI())) {
View Full Code Here

Examples of org.semanticweb.owlapi.model.OWLDataFactory

        // ontology), we can add a ClassAssertion to the ontology. For example,
        // suppose we wanted to specify that :Mary is an instance of the class
        // :Person. First we need to obtain the individual :Mary and the class
        // :Person Create an ontology manager to work with
        OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
        OWLDataFactory dataFactory = manager.getOWLDataFactory();
        // The IRIs used here are taken from the OWL 2 Primer
        String base = "http://example.com/owl/families/";
        PrefixManager pm = new DefaultPrefixManager(null, null, base);
        // Get the reference to the :Person class (the full IRI will be
        // <http://example.com/owl/families/Person>)
        OWLClass person = dataFactory.getOWLClass(":Person", pm);
        // Get the reference to the :Mary class (the full IRI will be
        // <http://example.com/owl/families/Mary>)
        OWLNamedIndividual mary = dataFactory
                .getOWLNamedIndividual(":Mary", pm);
        // Now create a ClassAssertion to specify that :Mary is an instance of
        // :Person
        OWLClassAssertionAxiom classAssertion = dataFactory
                .getOWLClassAssertionAxiom(person, mary);
        // We need to add the class assertion to the ontology that we want
        // specify that :Mary is a :Person
        OWLOntology ontology = manager.createOntology(IRI.create(base));
        // Add the class assertion
View Full Code Here

Examples of org.semanticweb.owlapi.model.OWLDataFactory

        SimpleIRIMapper mapper = new SimpleIRIMapper(ontologyIRI, documentIRI);
        manager.getIRIMappers().add(mapper);
        // Now create the ontology - we use the ontology IRI (not the physical
        // IRI)
        OWLOntology ontology = manager.createOntology(ontologyIRI);
        OWLDataFactory factory = manager.getOWLDataFactory();
        // Get hold of references to class A and class B. Note that the ontology
        // does not contain class A or classB, we simply get references to
        // objects from a data factory that represent class A and class B
        OWLClass clsA = factory.getOWLClass(IRI.create(ontologyIRI + "#A"));
        OWLClass clsB = factory.getOWLClass(IRI.create(ontologyIRI + "#B"));
        SWRLVariable var = factory.getSWRLVariable(IRI.create(ontologyIRI
                + "#x"));
        SWRLRule rule = factory.getSWRLRule(
                singleton(factory.getSWRLClassAtom(clsA, var)),
                singleton(factory.getSWRLClassAtom(clsB, var)));
        manager.applyChange(new AddAxiom(ontology, rule));
        OWLObjectProperty prop = factory.getOWLObjectProperty(IRI
                .create(ontologyIRI + "#propA"));
        OWLObjectProperty propB = factory.getOWLObjectProperty(IRI
                .create(ontologyIRI + "#propB"));
        SWRLObjectPropertyAtom propAtom = factory.getSWRLObjectPropertyAtom(
                prop, var, var);
        SWRLObjectPropertyAtom propAtom2 = factory.getSWRLObjectPropertyAtom(
                propB, var, var);
        Set<SWRLAtom> antecedent = new HashSet<SWRLAtom>();
        antecedent.add(propAtom);
        antecedent.add(propAtom2);
        SWRLRule rule2 = factory.getSWRLRule(antecedent,
                Collections.singleton(propAtom));
        manager.applyChange(new AddAxiom(ontology, rule2));
        // Now save the ontology. The ontology will be saved to the location
        // where we loaded it from, in the default ontology format
        manager.saveOntology(ontology);
View Full Code Here

Examples of org.semanticweb.owlapi.model.OWLDataFactory

    @Test
    public void shouldAddObjectPropertyAssertions() throws Exception {
        OWLOntologyManager man = OWLManager.createOWLOntologyManager();
        String base = "http://www.semanticweb.org/ontologies/individualsexample";
        OWLOntology ont = man.createOntology(IRI.create(base));
        OWLDataFactory dataFactory = man.getOWLDataFactory();
        // In this case, we would like to state that matthew has a father who is
        // peter. We need a subject and object - matthew is the subject and
        // peter is the object. We use the data factory to obtain references to
        // these individuals
        OWLIndividual matthew = dataFactory.getOWLNamedIndividual(IRI
                .create(base + "#matthew"));
        OWLIndividual peter = dataFactory.getOWLNamedIndividual(IRI.create(base
                + "#peter"));
        // We want to link the subject and object with the hasFather property,
        // so use the data factory to obtain a reference to this object
        // property.
        OWLObjectProperty hasFather = dataFactory.getOWLObjectProperty(IRI
                .create(base + "#hasFather"));
        // Now create the actual assertion (triple), as an object property
        // assertion axiom matthew --> hasFather --> peter
        OWLObjectPropertyAssertionAxiom assertion = dataFactory
                .getOWLObjectPropertyAssertionAxiom(hasFather, matthew, peter);
        // Finally, add the axiom to our ontology and save
        AddAxiom addAxiomChange = new AddAxiom(ont, assertion);
        man.applyChange(addAxiomChange);
        // We can also specify that matthew is an instance of Person. To do this
        // we use a ClassAssertion axiom. First we need a reference to the
        // person class
        OWLClass personClass = dataFactory.getOWLClass(IRI.create(base
                + "#Person"));
        // Now we will create out Class Assertion to specify that matthew is an
        // instance of Person (or rather that Person has matthew as an instance)
        OWLClassAssertionAxiom ax = dataFactory.getOWLClassAssertionAxiom(
                personClass, matthew);
        // Add this axiom to our ontology. We can use a short cut method -
        // instead of creating the AddAxiom change ourselves, it will be created
        // automatically and the change applied
        man.addAxiom(ont, ax);
View Full Code Here

Examples of org.semanticweb.owlapi.model.OWLDataFactory

        // a nose (hasPart some Nose), and then we use this restriction in a
        // subclass axiom to state that Head is a subclass of things that have
        // parts that are Noses SubClassOf(Head, hasPart some Nose) -- in other
        // words, Heads have parts that are noses! First we need to obtain
        // references to our hasPart property and our Nose class
        OWLDataFactory factory = man.getOWLDataFactory();
        OWLObjectProperty hasPart = factory.getOWLObjectProperty(IRI
                .create(base + "#hasPart"));
        OWLClass nose = factory.getOWLClass(IRI.create(base + "#Nose"));
        // Now create a restriction to describe the class of individuals that
        // have at least one part that is a kind of nose
        OWLClassExpression hasPartSomeNose = factory
                .getOWLObjectSomeValuesFrom(hasPart, nose);
        // Obtain a reference to the Head class so that we can specify that
        // Heads have noses
        OWLClass head = factory.getOWLClass(IRI.create(base + "#Head"));
        // We now want to state that Head is a subclass of hasPart some Nose, to
        // do this we create a subclass axiom, with head as the subclass and
        // "hasPart some Nose" as the superclass (remember, restrictions are
        // also classes - they describe classes of individuals -- they are
        // anonymous classes).
        OWLSubClassOfAxiom ax = factory.getOWLSubClassOfAxiom(head,
                hasPartSomeNose);
        // Add the axiom to our ontology
        AddAxiom addAx = new AddAxiom(ont, ax);
        man.applyChange(addAx);
    }
View Full Code Here

Examples of org.semanticweb.owlapi.model.OWLDataFactory

            // System.out.println("There are no unsatisfiable classes");
        }
        // Now we want to query the reasoner for all descendants of vegetarian.
        // Vegetarians are defined in the ontology to be animals that don't eat
        // animals or parts of animals.
        OWLDataFactory fac = manager.getOWLDataFactory();
        // Get a reference to the vegetarian class so that we can as the
        // reasoner about it. The full IRI of this class happens to be:
        // <http://owl.man.ac.uk/2005/07/sssw/people#vegetarian>
        OWLClass vegPizza = fac.getOWLClass(IRI
                .create("http://owl.man.ac.uk/2005/07/sssw/people#vegetarian"));
        // Now use the reasoner to obtain the subclasses of vegetarian. We can
        // ask for the direct subclasses of vegetarian or all of the (proper)
        // subclasses of vegetarian. In this case we just want the direct ones
        // (which we specify by the "true" flag).
        NodeSet<OWLClass> subClses = reasoner.getSubClasses(vegPizza, true);
        // The reasoner returns a NodeSet, which represents a set of Nodes. Each
        // node in the set represents a subclass of vegetarian pizza. A node of
        // classes contains classes, where each class in the node is equivalent.
        // For example, if we asked for the subclasses of some class A and got
        // back a NodeSet containing two nodes {B, C} and {D}, then A would have
        // two proper subclasses. One of these subclasses would be equivalent to
        // the class D, and the other would be the class that is equivalent to
        // class B and class C. In this case, we don't particularly care about
        // the equivalences, so we will flatten this set of sets and print the
        // result
        Set<OWLClass> clses = subClses.getFlattened();
        // System.out.println("Subclasses of vegetarian: ");
        // for (OWLClass cls : clses) {
        // System.out.println("    " + cls);
        // }
        // In this case, we should find that the classes, cow, sheep and giraffe
        // are vegetarian. Note that in this ontology only the class cow had
        // been stated to be a subclass of vegetarian. The fact that sheep and
        // giraffe are subclasses of vegetarian was implicit in the ontology
        // (through other things we had said) and this illustrates why it is
        // important to use a reasoner for querying an ontology. We can easily
        // retrieve the instances of a class. In this example we'll obtain the
        // instances of the class pet. This class has a full IRI of
        // <http://owl.man.ac.uk/2005/07/sssw/people#pet> We need to obtain a
        // reference to this class so that we can ask the reasoner about it.
        OWLClass country = fac.getOWLClass(IRI
                .create("http://owl.man.ac.uk/2005/07/sssw/people#pet"));
        // Ask the reasoner for the instances of pet
        NodeSet<OWLNamedIndividual> individualsNodeSet = reasoner.getInstances(
                country, true);
        // The reasoner returns a NodeSet again. This time the NodeSet contains
        // individuals. Again, we just want the individuals, so get a flattened
        // set.
        Set<OWLNamedIndividual> individuals = individualsNodeSet.getFlattened();
        // System.out.println("Instances of pet: ");
        // for (OWLNamedIndividual ind : individuals) {
        // System.out.println("    " + ind);
        // }
        // Again, it's worth noting that not all of the individuals that are
        // returned were explicitly stated to be pets. Finally, we can ask for
        // the property values (property assertions in OWL speak) for a given
        // individual and property. Let's get the property values for the
        // individual Mick, the full IRI of which is
        // <http://owl.man.ac.uk/2005/07/sssw/people#Mick> Get a reference to
        // the individual Mick
        OWLNamedIndividual mick = fac.getOWLNamedIndividual(IRI
                .create("http://owl.man.ac.uk/2005/07/sssw/people#Mick"));
        // Let's get the pets of Mick Get hold of the has_pet property which has
        // a full IRI of <http://owl.man.ac.uk/2005/07/sssw/people#has_pet>
        OWLObjectProperty hasPet = fac.getOWLObjectProperty(IRI
                .create("http://owl.man.ac.uk/2005/07/sssw/people#has_pet"));
        // Now ask the reasoner for the has_pet property values for Mick
        NodeSet<OWLNamedIndividual> petValuesNodeSet = reasoner
                .getObjectPropertyValues(mick, hasPet);
        Set<OWLNamedIndividual> values = petValuesNodeSet.getFlattened();
View Full Code Here

Examples of org.semanticweb.owlapi.model.OWLDataFactory

        // create a some values from restriction and then ask for the
        // satisfiability of the class interesected with the complement of this
        // some values from restriction. If the intersection is satisfiable then
        // the instances of the class don't have to have the property,
        // otherwise, they do.
        OWLDataFactory dataFactory = man.getOWLDataFactory();
        OWLClassExpression restriction = dataFactory
                .getOWLObjectSomeValuesFrom(prop, dataFactory.getOWLThing());
        // Now we see if the intersection of the class and the complement of
        // this restriction is satisfiable
        OWLClassExpression complement = dataFactory
                .getOWLObjectComplementOf(restriction);
        OWLClassExpression intersection = dataFactory
                .getOWLObjectIntersectionOf(cls, complement);
        return !reasoner.isSatisfiable(intersection);
    }
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.