Beispiel #1
0
 /**
  * filters the result of e.g. getSubclasses which is Set<Set<OWLClass>> To Set<OWLClass>
  *
  * @param original
  * @return
  * @throws OWLReasonerException
  */
 protected Set<OWLClass> filterClasses(Set<Set<OWLClass>> original) throws OWLReasonerException {
   Set<OWLClass> result = new HashSet<OWLClass>();
   for (Set<OWLClass> set : original) {
     for (Iterator<OWLClass> it = set.iterator(); it.hasNext(); ) {
       OWLClass cls = it.next();
       if (cls.getURI().equals(OWLRDFVocabulary.OWL_NOTHING)) {
         it.remove();
       } else {
         result.add(cls);
       }
     }
   }
   return result;
 }
Beispiel #2
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;
  }