Exemplo n.º 1
0
  protected void loadOntology() {
    try {

      manager = OWLManager.createOWLOntologyManager();

      URI physicalURI = URI.create(PREFERENCES.getOntologyURL());

      // Now do the loading
      ontology = manager.loadOntologyFromPhysicalURI(physicalURI);

      manager.setPhysicalURIForOntology(ontology, physicalURI);

    } catch (final Exception e) {
      Runnable runnable =
          new Runnable() {
            public void run() {
              JOptionPane.showMessageDialog(
                  null,
                  "Could not create the ontology.  (This probably happened\n"
                      + "because the ontology could not be accessed due to network\n"
                      + "problems.)\n"
                      + "["
                      + e.getMessage()
                      + "]",
                  "Error",
                  JOptionPane.ERROR_MESSAGE);
              System.exit(1);
            }
          };
      SwingUtilities.invokeLater(runnable);
    }
  }
Exemplo n.º 2
0
  private OWLDescription createIncludeCoffeeDescription(Set<OWLClass> includeExtras) {
    OWLObjectProperty prop =
        this.getNamedObjectProperty(PREFERENCES.getExtrasPropertyName()); // has_extras

    Set<OWLDescription> classes = new HashSet<OWLDescription>();
    classes.add(getCoffeeClass()); // get OWL class for Coffee

    for (OWLClass extra : includeExtras) {
      classes.add(manager.getOWLDataFactory().getOWLObjectSomeRestriction(prop, extra));
    }

    return manager.getOWLDataFactory().getOWLObjectIntersectionOf(classes);
  }
Exemplo n.º 3
0
  private OWLDescription createExcludeCoffeeDescription(Set<OWLClass> excludeExtras) {
    OWLObjectProperty prop =
        this.getNamedObjectProperty(PREFERENCES.getExtrasPropertyName()); // has_extras

    Set<OWLDescription> classes = new HashSet<OWLDescription>();
    // Everything must be a coffee

    for (OWLClass extra : excludeExtras) {
      classes.add(manager.getOWLDataFactory().getOWLObjectSomeRestriction(prop, extra));
    }

    // are looking for.
    return manager.getOWLDataFactory().getOWLObjectUnionOf(classes);
  }
Exemplo n.º 4
0
  /** setup fact++ reasoner */
  protected void setupReasoner() {
    // run reasoner

    try {
      reasoner = new Reasoner(manager);
    } catch (Exception e) {
      e.printStackTrace(); // To change body of catch statement use File | Settings | File
      // Templates.
    }
    try {
      if (reasoner != null) {
        reasoner.loadOntologies(manager.getOntologies());
        reasoner.classify();
      }
    } catch (final OWLReasonerException e) {
      Runnable runnable =
          new Runnable() {
            public void run() {
              JOptionPane.showMessageDialog(
                  null,
                  "A reasoner error has ocurred.\n" + "[" + e.getMessage() + "]",
                  "Reasoner Error",
                  JOptionPane.ERROR_MESSAGE);
            }
          };
    }
    ;
  }
Exemplo n.º 5
0
 /**
  * @param entity
  * @return
  */
 public String render(OWLEntity entity) {
   for (OWLOntology ont : manager.getOntologies()) {
     for (OWLAnnotation annot : entity.getAnnotations(ont)) {
       if (annot.getAnnotationURI().equals(OWLRDFVocabulary.RDFS_LABEL.getURI())) {
         if (annot instanceof OWLConstantAnnotation) {
           return ((OWLConstantAnnotation) annot).getAnnotationValue().getLiteral();
         }
       }
     }
   }
   return entity.getURI().getFragment();
 }
Exemplo n.º 6
0
  /**
   * Creates OWLDescription (query) by given included extras and excluded extras
   *
   * @param includeExtras
   * @param excludeExtras
   * @return
   */
  private OWLDescription createCoffeeDescription(
      Set<OWLClass> includeExtras, Set<OWLClass> excludeExtras) {

    // Include means existential restrictions
    // Exclude means negated existential restrictions
    OWLObjectProperty prop =
        this.getNamedObjectProperty(PREFERENCES.getExtrasPropertyName()); // has_extras

    // Create a hash set to store the components (existential restrictions)
    // of our description
    Set<OWLDescription> classes = new HashSet<OWLDescription>();
    // Everything must be a coffee
    classes.add(getCoffeeClass()); // get OWL class for Coffee

    // Create the existential restrictions that represent the extras
    // that we want to include.
    for (OWLClass extra : includeExtras) {
      // e.g. hasExtras some ex_A , hasExtras some ex_B
      classes.add(manager.getOWLDataFactory().getOWLObjectSomeRestriction(prop, extra));
    }

    // Create the negated existential restrictions of the extras that we
    // want to exclude
    for (OWLClass excludeExtra : excludeExtras) {
      // has_topping some topping_A
      OWLDescription restriction =
          manager.getOWLDataFactory().getOWLObjectSomeRestriction(prop, excludeExtra);
      // not (has_topping some topping_A)
      OWLObjectComplementOf neg = manager.getOWLDataFactory().getOWLObjectComplementOf(restriction);
      classes.add(neg);
    }

    // Bind the whole thing up in an intersection class
    // to create a concept description of the coffee we
    // are looking for.
    return manager.getOWLDataFactory().getOWLObjectIntersectionOf(classes);
  }
Exemplo n.º 7
0
  /**
   * Gets the property by given name, e.g. has_topping
   *
   * @param propName
   * @return
   */
  public OWLObjectProperty getNamedObjectProperty(String propName) {

    if (objPropNameCache == null) {
      objPropNameCache = new HashMap<String, URI>();
      for (OWLOntology ont : reasoner.getLoadedOntologies()) {
        for (OWLObjectProperty prop : ont.getReferencedObjectProperties()) {
          objPropNameCache.put(prop.toString(), prop.getURI());
        }
      }
    }

    // search the HashMap
    OWLObjectProperty namedProp = null;
    URI uri = objPropNameCache.get(propName);
    if (uri != null) {
      namedProp = manager.getOWLDataFactory().getOWLObjectProperty(uri);
    } else {
      System.err.println("Cannot find object property: " + propName + " in loaded ontologies");
    }
    return namedProp;
  }
Exemplo n.º 8
0
  /**
   * Gets OWL class by given name
   *
   * @param className
   * @return
   * @throws OWLReasonerException
   */
  public OWLClass getNamedClass(String className) {

    if (classnameCache == null) {
      classnameCache = new HashMap<String, URI>();
      for (OWLOntology ont : reasoner.getLoadedOntologies()) {
        for (OWLClass cls : ont.getReferencedClasses()) {
          classnameCache.put(cls.toString(), cls.getURI());
        }
      }
    }

    OWLClass namedCls = null;
    URI uri = classnameCache.get(className);
    if (uri != null) {
      namedCls = manager.getOWLDataFactory().getOWLClass(uri);
    } else {
      System.err.println("Cannot find class: " + className + " in loaded ontologies");
    }

    return namedCls;
  }