コード例 #1
0
 public Set<OWLNamedIndividual> getEntities() {
   Set<OWLNamedIndividual> entities = new HashSet<OWLNamedIndividual>();
   for (OWLOntology ont : ontologies) {
     entities.addAll(ont.getIndividualsInSignature());
   }
   return entities;
 }
コード例 #2
0
 /**
  * Finds all individuals where more than one type is asserted, which is disallowed by Cirm team
  * convention. Except: Protected is allowed as second class, but will still be returned from this
  * method.
  *
  * @return
  */
 public List<Pair<OWLNamedIndividual, Set<OWLClassExpression>>>
     getIndividualsWithMoreThanOneTypeAsserted() {
   List<Pair<OWLNamedIndividual, Set<OWLClassExpression>>> errors =
       new LinkedList<Pair<OWLNamedIndividual, Set<OWLClassExpression>>>();
   if (DBG)
     System.out.println("Start CirmOntologyValidator::getIndividualsWithMoreThanOneTypeAsserted");
   Set<OWLOntology> owlOntologies = OWL.ontologies();
   for (OWLOntology owlOntology : owlOntologies) {
     if (DBG) System.out.println("Getting individuals in signature of Ontology " + owlOntology);
     Set<OWLNamedIndividual> s = owlOntology.getIndividualsInSignature(false);
     if (DBG) System.out.println("...done.");
     for (OWLNamedIndividual owlNamedIndividual : s) {
       Set<OWLClassExpression> types = owlNamedIndividual.getTypes(owlOntologies);
       if (types.size() > 1) {
         Pair<OWLNamedIndividual, Set<OWLClassExpression>> error =
             new Pair<OWLNamedIndividual, Set<OWLClassExpression>>(owlNamedIndividual, types);
         errors.add(error);
         if (DBG) {
           System.out.println("Found " + types.size() + " types for " + owlNamedIndividual);
           for (OWLClassExpression owlClassExpression : types) {
             System.out.println(owlClassExpression);
           }
         }
       }
     } // for (OWLNamedIndividual
   } // for (OWLOntology
   if (DBG) System.out.println("Total Individuals not passing validation: " + errors.size());
   return errors;
 }
コード例 #3
0
ファイル: ModelContainer.java プロジェクト: DoctorBud/minerva
 @SuppressWarnings({"unchecked", "rawtypes"})
 private OWLReasoner createModuleReasoner() throws OWLOntologyCreationException {
   LOG.info("Creating module reasoner for module: " + modelId);
   ModuleType mtype = ModuleType.BOT;
   OWLOntologyManager m =
       OWLManager.createOWLOntologyManager(
           aboxOntology.getOWLOntologyManager().getOWLDataFactory());
   SyntacticLocalityModuleExtractor sme =
       new SyntacticLocalityModuleExtractor(m, aboxOntology, mtype);
   Set<OWLEntity> seeds = (Set) aboxOntology.getIndividualsInSignature();
   OWLOntology module = sme.extractAsOntology(seeds, IRI.generateDocumentIRI());
   OWLReasoner reasoner = reasonerFactory.createReasoner(module);
   LOG.info("Done creating module reasoner module: " + modelId);
   return reasoner;
 }
コード例 #4
0
  public void writeOntology() throws OWLRendererException {
    if (ontologies.size() != 1) {
      throw new OWLRuntimeException("Can only render one ontology");
    }
    OWLOntology ontology = getOntologies().iterator().next();
    writePrefixMap();
    writeNewLine();
    writeOntologyHeader(ontology);

    for (OWLAnnotationProperty prop : ontology.getAnnotationPropertiesInSignature()) {
      write(prop);
    }
    for (OWLDatatype datatype : ontology.getDatatypesInSignature()) {
      write(datatype);
    }
    for (OWLObjectProperty prop : ontology.getObjectPropertiesInSignature()) {
      write(prop);
      OWLObjectPropertyExpression invProp = prop.getInverseProperty();
      if (!ontology.getAxioms(invProp).isEmpty()) {
        write(invProp);
      }
    }
    for (OWLDataProperty prop : ontology.getDataPropertiesInSignature()) {
      write(prop);
    }
    for (OWLClass cls : ontology.getClassesInSignature()) {
      write(cls);
    }
    for (OWLNamedIndividual ind : ontology.getIndividualsInSignature()) {
      write(ind);
    }
    for (OWLAnonymousIndividual ind : ontology.getReferencedAnonymousIndividuals()) {
      write(ind);
    }
    // Nary disjoint classes axioms
    event = new RendererEvent(this, ontology);
    for (OWLDisjointClassesAxiom ax : ontology.getAxioms(AxiomType.DISJOINT_CLASSES)) {
      if (ax.getClassExpressions().size() > 2) {
        SectionMap map = new SectionMap();
        map.add(ax.getClassExpressions(), ax);
        writeSection(DISJOINT_CLASSES, map, ",", false, ontology);
      }
    }
    // Nary equivalent classes axioms
    for (OWLEquivalentClassesAxiom ax : ontology.getAxioms(AxiomType.EQUIVALENT_CLASSES)) {
      if (ax.getClassExpressions().size() > 2) {
        SectionMap map = new SectionMap();
        map.add(ax.getClassExpressions(), ax);
        writeSection(EQUIVALENT_CLASSES, map, ",", false, ontology);
      }
    }
    // Nary disjoint properties
    for (OWLDisjointObjectPropertiesAxiom ax :
        ontology.getAxioms(AxiomType.DISJOINT_OBJECT_PROPERTIES)) {
      if (ax.getProperties().size() > 2) {
        SectionMap map = new SectionMap();
        map.add(ax.getProperties(), ax);
        writeSection(DISJOINT_PROPERTIES, map, ",", false, ontology);
      }
    }
    // Nary equivlant properties
    for (OWLEquivalentObjectPropertiesAxiom ax :
        ontology.getAxioms(AxiomType.EQUIVALENT_OBJECT_PROPERTIES)) {
      if (ax.getProperties().size() > 2) {
        SectionMap map = new SectionMap();
        map.add(ax.getProperties(), ax);
        writeSection(EQUIVALENT_PROPERTIES, map, ",", false, ontology);
      }
    }
    // Nary disjoint properties
    for (OWLDisjointDataPropertiesAxiom ax :
        ontology.getAxioms(AxiomType.DISJOINT_DATA_PROPERTIES)) {
      if (ax.getProperties().size() > 2) {
        SectionMap map = new SectionMap();
        map.add(ax.getProperties(), ax);
        writeSection(DISJOINT_PROPERTIES, map, ",", false, ontology);
      }
    }
    // Nary equivalent properties
    for (OWLEquivalentDataPropertiesAxiom ax :
        ontology.getAxioms(AxiomType.EQUIVALENT_DATA_PROPERTIES)) {
      if (ax.getProperties().size() > 2) {
        SectionMap map = new SectionMap();
        map.add(ax.getProperties(), ax);
        writeSection(EQUIVALENT_PROPERTIES, map, ",", false, ontology);
      }
    }
    // Nary different individuals
    for (OWLDifferentIndividualsAxiom ax : ontology.getAxioms(AxiomType.DIFFERENT_INDIVIDUALS)) {
      if (ax.getIndividuals().size() > 2) {
        SectionMap map = new SectionMap();
        map.add(ax.getIndividuals(), ax);
        writeSection(DIFFERENT_INDIVIDUALS, map, ",", false, ontology);
      }
    }
    for (SWRLRule rule : ontology.getAxioms(AxiomType.SWRL_RULE)) {
      writeSection(RULE, Collections.singleton(rule), ", ", false);
    }
    flush();
  }
コード例 #5
0
ファイル: LodeServlet.java プロジェクト: zednis/LODE
  private OWLOntology parseWithReasoner(OWLOntologyManager manager, OWLOntology ontology) {
    try {
      PelletOptions.load(new URL("http://" + cssLocation + "pellet.properties"));
      PelletReasoner reasoner = PelletReasonerFactory.getInstance().createReasoner(ontology);
      reasoner.getKB().prepare();
      List<InferredAxiomGenerator<? extends OWLAxiom>> generators =
          new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
      generators.add(new InferredSubClassAxiomGenerator());
      generators.add(new InferredClassAssertionAxiomGenerator());
      generators.add(new InferredDisjointClassesAxiomGenerator());
      generators.add(new InferredEquivalentClassAxiomGenerator());
      generators.add(new InferredEquivalentDataPropertiesAxiomGenerator());
      generators.add(new InferredEquivalentObjectPropertyAxiomGenerator());
      generators.add(new InferredInverseObjectPropertiesAxiomGenerator());
      generators.add(new InferredPropertyAssertionGenerator());
      generators.add(new InferredSubDataPropertyAxiomGenerator());
      generators.add(new InferredSubObjectPropertyAxiomGenerator());

      InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, generators);

      OWLOntologyID id = ontology.getOntologyID();
      Set<OWLImportsDeclaration> declarations = ontology.getImportsDeclarations();
      Set<OWLAnnotation> annotations = ontology.getAnnotations();

      Map<OWLEntity, Set<OWLAnnotationAssertionAxiom>> entityAnnotations =
          new HashMap<OWLEntity, Set<OWLAnnotationAssertionAxiom>>();
      for (OWLClass aEntity : ontology.getClassesInSignature()) {
        entityAnnotations.put(aEntity, aEntity.getAnnotationAssertionAxioms(ontology));
      }
      for (OWLObjectProperty aEntity : ontology.getObjectPropertiesInSignature()) {
        entityAnnotations.put(aEntity, aEntity.getAnnotationAssertionAxioms(ontology));
      }
      for (OWLDataProperty aEntity : ontology.getDataPropertiesInSignature()) {
        entityAnnotations.put(aEntity, aEntity.getAnnotationAssertionAxioms(ontology));
      }
      for (OWLNamedIndividual aEntity : ontology.getIndividualsInSignature()) {
        entityAnnotations.put(aEntity, aEntity.getAnnotationAssertionAxioms(ontology));
      }
      for (OWLAnnotationProperty aEntity : ontology.getAnnotationPropertiesInSignature()) {
        entityAnnotations.put(aEntity, aEntity.getAnnotationAssertionAxioms(ontology));
      }
      for (OWLDatatype aEntity : ontology.getDatatypesInSignature()) {
        entityAnnotations.put(aEntity, aEntity.getAnnotationAssertionAxioms(ontology));
      }

      manager.removeOntology(ontology);
      OWLOntology inferred = manager.createOntology(id);
      iog.fillOntology(manager, inferred);

      for (OWLImportsDeclaration decl : declarations) {
        manager.applyChange(new AddImport(inferred, decl));
      }
      for (OWLAnnotation ann : annotations) {
        manager.applyChange(new AddOntologyAnnotation(inferred, ann));
      }
      for (OWLClass aEntity : inferred.getClassesInSignature()) {
        applyAnnotations(aEntity, entityAnnotations, manager, inferred);
      }
      for (OWLObjectProperty aEntity : inferred.getObjectPropertiesInSignature()) {
        applyAnnotations(aEntity, entityAnnotations, manager, inferred);
      }
      for (OWLDataProperty aEntity : inferred.getDataPropertiesInSignature()) {
        applyAnnotations(aEntity, entityAnnotations, manager, inferred);
      }
      for (OWLNamedIndividual aEntity : inferred.getIndividualsInSignature()) {
        applyAnnotations(aEntity, entityAnnotations, manager, inferred);
      }
      for (OWLAnnotationProperty aEntity : inferred.getAnnotationPropertiesInSignature()) {
        applyAnnotations(aEntity, entityAnnotations, manager, inferred);
      }
      for (OWLDatatype aEntity : inferred.getDatatypesInSignature()) {
        applyAnnotations(aEntity, entityAnnotations, manager, inferred);
      }

      return inferred;
    } catch (FileNotFoundException e1) {
      return ontology;
    } catch (MalformedURLException e1) {
      return ontology;
    } catch (IOException e1) {
      return ontology;
    } catch (OWLOntologyCreationException e) {
      return ontology;
    }
  }
コード例 #6
0
ファイル: ELClassifierTest.java プロジェクト: raghavam/DistEL
  private void rearrangeAndCompareResults(
      OWLOntology ontology,
      OWLReasoner reasoner,
      Jedis resultStore,
      Jedis resultStore2,
      Jedis idReader)
      throws Exception {
    new ResultRearranger().initializeAndRearrange();
    Set<OWLClass> classes = ontology.getClassesInSignature();
    // rearranged results are in DB-1
    resultStore.select(1);
    double classCount = 0;
    int multiplier = 1;
    int missCount = 0;
    String bottomID = Util.getPackedID(Constants.BOTTOM_ID, EntityType.CLASS);
    System.out.println("Comparing Classes... " + classes.size());
    OWLClass owlThing = ontology.getOWLOntologyManager().getOWLDataFactory().getOWLThing();
    for (OWLClass cl : classes) {
      String classID = conceptToID(cl.toString(), idReader);
      // REL/Pellet doesn't consider individuals i.e. {a} \sqsubseteq \bottom
      // so skipping checking bottom
      if (classID.equals(bottomID)) continue;

      classCount++;
      Set<OWLClass> reasonerSuperClasses = reasoner.getSuperClasses(cl, false).getFlattened();
      // add cl itself to S(X) computed by reasoner. That is missing
      // in its result.
      reasonerSuperClasses.add(cl);
      reasonerSuperClasses.add(owlThing);
      // adding equivalent classes -- they are not considered if asked for superclasses
      Iterator<OWLClass> iterator = reasoner.getEquivalentClasses(cl).iterator();
      while (iterator.hasNext()) reasonerSuperClasses.add(iterator.next());
      Set<String> superClasses = resultStore.smembers(classID);
      if (superClasses.size() == reasonerSuperClasses.size()) {
        compareAndPrintEqualSizedClasses(cl, reasonerSuperClasses, superClasses, idReader);
      } else {
        System.out.println(
            "\n"
                + cl.toString()
                + " -- "
                + superClasses.size()
                + ", "
                + reasonerSuperClasses.size());
        for (OWLClass scl : reasonerSuperClasses) {
          String sclID = conceptToID(scl.toString(), idReader);
          if (!superClasses.contains(sclID)) {
            System.out.print(cl.toString() + " -ne- " + scl.toString());
            System.out.print("  ,  ");
          }
          superClasses.remove(sclID);
        }
        for (String s : superClasses)
          System.out.println("\t -- " + Util.idToConcept(s, idReader) + "(" + s + ")");
        System.out.println();
        missCount++;
      }
    }
    System.out.println("No of classes not equal: " + missCount);

    Set<OWLNamedIndividual> individuals = ontology.getIndividualsInSignature();
    System.out.println("Rearranging individuals...");
    System.out.println("Individuals: " + individuals.size());
    System.out.println("Not checking for individuals...");
    /*
    		rearrangeIndividuals(individuals, resultStore, resultStore2, idReader);
    		int cnt = 0;
    		for(OWLClass cl : classes) {
    			Set<OWLNamedIndividual> instances =
    				reasoner.getInstances(cl, false).getFlattened();
    			Set<String> computedInstances = resultStore2.smembers(
    					conceptToID(cl.toString(), idReader));
    			if(computedInstances.size() == instances.size()) {
    				compareAndPrintEqualSizedIndividuals(cl, instances, computedInstances, idReader);
    			}
    			else {
    				System.out.println(cl.toString() + " -- " +
    						computedInstances.size() + " , " + instances.size());
    				compareAndPrintUnEqualSizedIndividuals(cl, instances, computedInstances, idReader);
    				cnt++;
    			}
    		}
    		System.out.println("No of classes for which individuals didn't match: " + cnt);
    */
    resultStore.select(0);
  }
コード例 #7
0
 @Override
 protected Set<OWLNamedIndividual> getEntities(OWLOntology ont) {
   return ont.getIndividualsInSignature();
 }