Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.paniblakas.mowl;
- import java.util.Collections;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.Set;
- import org.semanticweb.owlapi.apibinding.OWLManager;
- import org.semanticweb.owlapi.model.IRI;
- import org.semanticweb.owlapi.model.OWLAxiom;
- import org.semanticweb.owlapi.model.OWLDataFactory;
- import org.semanticweb.owlapi.model.OWLDifferentIndividualsAxiom;
- import org.semanticweb.owlapi.model.OWLIndividual;
- import org.semanticweb.owlapi.model.OWLNamedIndividual;
- import org.semanticweb.owlapi.model.OWLOntology;
- import org.semanticweb.owlapi.model.OWLOntologyManager;
- import org.semanticweb.owlapi.model.RemoveAxiom;
- import org.semanticweb.owlapi.util.OWLEntityRemover;
- public class TestDifferentIndividuals
- {
- public static final String DOCUMENT_IRI = "http://www.co-ode.org/ontologies/pizza/pizza.owl";
- public static void getDifferentIndividualsAll(OWLOntologyManager manager, OWLOntology ontology, OWLDataFactory factory)
- {
- for(OWLNamedIndividual i : ontology.getIndividualsInSignature())
- {
- System.out.println(i);
- for(OWLIndividual j: i.getDifferentIndividuals(ontology))
- {
- System.out.println(" " + j);
- }
- }
- }
- public static Set<OWLIndividual> getDifferentIndividuals(OWLOntology ontology, OWLIndividual indiv)
- {
- return indiv.getDifferentIndividuals(ontology);
- }
- public static void setDifferentIndividuals(OWLOntologyManager manager, OWLOntology ontology, OWLDataFactory factory, Set<OWLIndividual> diffIndividuals)
- {
- manager.addAxiom(ontology, factory.getOWLDifferentIndividualsAxiom(diffIndividuals));
- }
- public static void deleteDifferentIndividuals(OWLOntologyManager manager, OWLOntology ontology, OWLDataFactory factory, Set<OWLIndividual> diffIndividuals)
- {
- OWLDifferentIndividualsAxiom change = factory.getOWLDifferentIndividualsAxiom(diffIndividuals);
- System.out.println(diffIndividuals);
- RemoveAxiom moveAxiom = new RemoveAxiom(ontology, change);
- manager.applyChange(moveAxiom);
- manager.removeAxiom(ontology, change);
- }
- public static void print(Set<?> indiv)
- {
- for(Object i : indiv)
- {
- System.out.println(i);
- }
- }
- public static void main(String[] args)
- {
- try
- {
- OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
- OWLOntology ontology = manager.loadOntology(IRI.create(DOCUMENT_IRI));
- OWLDataFactory factory = manager.getOWLDataFactory();
- OWLIndividual pizzagermany = factory.getOWLNamedIndividual(IRI.create("http://www.co-ode.org/ontologies/pizza/pizza.owl#Germany"));
- //System.out.println("Start test all Different Individual");
- //getDifferentIndividualsAll(manager, ontology, factory);
- //System.out.println("..done");
- //System.out.println("");
- //System.out.println("Start test Different Individual from : " + pizzagermany);
- //print(getDifferentIndividuals(ontology, pizzagermany));
- //System.out.println(".. done");
- //System.out.println("");
- //System.out.println("Start test adding Different Individual");
- OWLIndividual pizzaafrica = factory.getOWLNamedIndividual(IRI.create("http://www.co-ode.org/ontologies/pizza/pizza.owl#Afrika"));
- OWLIndividual pizzaswaziland = factory.getOWLNamedIndividual(IRI.create("http://www.co-ode.org/ontologies/pizza/pizza.owl#Swaziland"));
- OWLIndividual pizzagreek = factory.getOWLNamedIndividual(IRI.create("http://www.co-ode.org/ontologies/pizza/pizza.owl#Greek"));
- Set<OWLIndividual> diffIndividuals = new HashSet<OWLIndividual>();
- //System.out.println(" add " + pizzaafrica);
- diffIndividuals.add(pizzaafrica);
- //System.out.println(" add " + pizzaswaziland);
- diffIndividuals.add(pizzaswaziland);
- //System.out.println(" add " + pizzagreek);
- diffIndividuals.add(pizzagreek);
- setDifferentIndividuals(manager, ontology, factory, diffIndividuals);
- //System.out.println("Print Individuals : " + pizzagreek);
- //print(getDifferentIndividuals(ontology, pizzagreek));
- //System.out.println(".. done");
- //System.out.println("");
- //System.out.println("Start test adding Different Individual" + pizzagreek);
- diffIndividuals.addAll(ontology.getIndividualsInSignature());
- //print(diffIndividuals);
- setDifferentIndividuals(manager, ontology, factory, diffIndividuals);
- //print(getDifferentIndividuals(ontology, pizzagreek));
- //System.out.println(".. done");
- //System.out.println("");
- System.out.println("Start test deleting Different Individual");
- Set<OWLIndividual> del1 = new HashSet<OWLIndividual>();
- del1.add(factory.getOWLNamedIndividual(IRI.create("http://www.co-ode.org/ontologies/pizza/pizza.owl#Afrika")));
- del1.add(factory.getOWLNamedIndividual(IRI.create("http://www.co-ode.org/ontologies/pizza/pizza.owl#America")));
- del1.add(factory.getOWLNamedIndividual(IRI.create("http://www.co-ode.org/ontologies/pizza/pizza.owl#England")));
- del1.add(factory.getOWLNamedIndividual(IRI.create("http://www.co-ode.org/ontologies/pizza/pizza.owl#Greek")));
- System.out.println("Deleting...: ");
- System.out.println("now whe delete");
- deleteDifferentIndividuals(manager, ontology, factory, del1);
- getDifferentIndividualsAll(manager, ontology, factory);
- System.out.println(".. done");
- }
- catch(Exception e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement