Advertisement
Master_User

Untitled

Jun 28th, 2011
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.28 KB | None | 0 0
  1. package com.paniblakas.mowl;
  2.  
  3. import java.util.Collections;
  4. import java.util.HashMap;
  5. import java.util.HashSet;
  6. import java.util.Set;
  7.  
  8. import org.semanticweb.owlapi.apibinding.OWLManager;
  9. import org.semanticweb.owlapi.model.IRI;
  10. import org.semanticweb.owlapi.model.OWLAxiom;
  11. import org.semanticweb.owlapi.model.OWLDataFactory;
  12. import org.semanticweb.owlapi.model.OWLDifferentIndividualsAxiom;
  13. import org.semanticweb.owlapi.model.OWLIndividual;
  14. import org.semanticweb.owlapi.model.OWLNamedIndividual;
  15. import org.semanticweb.owlapi.model.OWLOntology;
  16. import org.semanticweb.owlapi.model.OWLOntologyManager;
  17. import org.semanticweb.owlapi.model.RemoveAxiom;
  18. import org.semanticweb.owlapi.util.OWLEntityRemover;
  19.  
  20. public class TestDifferentIndividuals
  21. {
  22. public static final String DOCUMENT_IRI = "http://www.co-ode.org/ontologies/pizza/pizza.owl";
  23.  
  24. public static void getDifferentIndividualsAll(OWLOntologyManager manager, OWLOntology ontology, OWLDataFactory factory)
  25. {
  26. for(OWLNamedIndividual i : ontology.getIndividualsInSignature())
  27. {
  28. System.out.println(i);
  29. for(OWLIndividual j: i.getDifferentIndividuals(ontology))
  30. {
  31. System.out.println(" " + j);
  32. }
  33. }
  34. }
  35.  
  36. public static Set<OWLIndividual> getDifferentIndividuals(OWLOntology ontology, OWLIndividual indiv)
  37. {
  38. return indiv.getDifferentIndividuals(ontology);
  39. }
  40.  
  41. public static void setDifferentIndividuals(OWLOntologyManager manager, OWLOntology ontology, OWLDataFactory factory, Set<OWLIndividual> diffIndividuals)
  42. {
  43. manager.addAxiom(ontology, factory.getOWLDifferentIndividualsAxiom(diffIndividuals));
  44. }
  45.  
  46. public static void deleteDifferentIndividuals(OWLOntologyManager manager, OWLOntology ontology, OWLDataFactory factory, Set<OWLIndividual> diffIndividuals)
  47. {
  48. OWLDifferentIndividualsAxiom change = factory.getOWLDifferentIndividualsAxiom(diffIndividuals);
  49. System.out.println(diffIndividuals);
  50. RemoveAxiom moveAxiom = new RemoveAxiom(ontology, change);
  51. manager.applyChange(moveAxiom);
  52. manager.removeAxiom(ontology, change);
  53. }
  54.  
  55. public static void print(Set<?> indiv)
  56. {
  57. for(Object i : indiv)
  58. {
  59. System.out.println(i);
  60. }
  61. }
  62.  
  63. public static void main(String[] args)
  64. {
  65. try
  66. {
  67. OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
  68. OWLOntology ontology = manager.loadOntology(IRI.create(DOCUMENT_IRI));
  69. OWLDataFactory factory = manager.getOWLDataFactory();
  70. OWLIndividual pizzagermany = factory.getOWLNamedIndividual(IRI.create("http://www.co-ode.org/ontologies/pizza/pizza.owl#Germany"));
  71.  
  72. //System.out.println("Start test all Different Individual");
  73. //getDifferentIndividualsAll(manager, ontology, factory);
  74. //System.out.println("..done");
  75. //System.out.println("");
  76.  
  77. //System.out.println("Start test Different Individual from : " + pizzagermany);
  78. //print(getDifferentIndividuals(ontology, pizzagermany));
  79. //System.out.println(".. done");
  80. //System.out.println("");
  81.  
  82. //System.out.println("Start test adding Different Individual");
  83. OWLIndividual pizzaafrica = factory.getOWLNamedIndividual(IRI.create("http://www.co-ode.org/ontologies/pizza/pizza.owl#Afrika"));
  84. OWLIndividual pizzaswaziland = factory.getOWLNamedIndividual(IRI.create("http://www.co-ode.org/ontologies/pizza/pizza.owl#Swaziland"));
  85. OWLIndividual pizzagreek = factory.getOWLNamedIndividual(IRI.create("http://www.co-ode.org/ontologies/pizza/pizza.owl#Greek"));
  86. Set<OWLIndividual> diffIndividuals = new HashSet<OWLIndividual>();
  87. //System.out.println(" add " + pizzaafrica);
  88. diffIndividuals.add(pizzaafrica);
  89. //System.out.println(" add " + pizzaswaziland);
  90. diffIndividuals.add(pizzaswaziland);
  91. //System.out.println(" add " + pizzagreek);
  92. diffIndividuals.add(pizzagreek);
  93.  
  94. setDifferentIndividuals(manager, ontology, factory, diffIndividuals);
  95. //System.out.println("Print Individuals : " + pizzagreek);
  96. //print(getDifferentIndividuals(ontology, pizzagreek));
  97. //System.out.println(".. done");
  98. //System.out.println("");
  99.  
  100. //System.out.println("Start test adding Different Individual" + pizzagreek);
  101. diffIndividuals.addAll(ontology.getIndividualsInSignature());
  102. //print(diffIndividuals);
  103. setDifferentIndividuals(manager, ontology, factory, diffIndividuals);
  104. //print(getDifferentIndividuals(ontology, pizzagreek));
  105. //System.out.println(".. done");
  106. //System.out.println("");
  107.  
  108. System.out.println("Start test deleting Different Individual");
  109. Set<OWLIndividual> del1 = new HashSet<OWLIndividual>();
  110. del1.add(factory.getOWLNamedIndividual(IRI.create("http://www.co-ode.org/ontologies/pizza/pizza.owl#Afrika")));
  111. del1.add(factory.getOWLNamedIndividual(IRI.create("http://www.co-ode.org/ontologies/pizza/pizza.owl#America")));
  112. del1.add(factory.getOWLNamedIndividual(IRI.create("http://www.co-ode.org/ontologies/pizza/pizza.owl#England")));
  113. del1.add(factory.getOWLNamedIndividual(IRI.create("http://www.co-ode.org/ontologies/pizza/pizza.owl#Greek")));
  114. System.out.println("Deleting...: ");
  115. System.out.println("now whe delete");
  116. deleteDifferentIndividuals(manager, ontology, factory, del1);
  117. getDifferentIndividualsAll(manager, ontology, factory);
  118. System.out.println(".. done");
  119. }
  120. catch(Exception e)
  121. {
  122.  
  123. }
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement