示例#1
0
 public void classifyOntology(OWLOntology ontology, OWLReasonerFactory factory) {
   ToStringRenderer.getInstance().setRenderer(new ManchesterOWLSyntaxOWLObjectRendererImpl());
   OWLReasoner reasoner = factory.createNonBufferingReasoner(ontology);
   // reasoner.precomputeInferences(InferenceType.values());
   long time = System.currentTimeMillis();
   boolean isConsistent = reasoner.isConsistent();
   int numOfUnsatClasses = reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom().size();
   time = System.currentTimeMillis() - time;
   DLExpressivityChecker checker = new DLExpressivityChecker(Collections.singleton(ontology));
   String e = checker.getDescriptionLogicName();
   String name = ontology.getOntologyID().getOntologyIRI().getFragment();
   logger.info(
       "ontology: "
           + name
           + ", reasoner: "
           + factory.getReasonerName()
           + ", expressivity: "
           + e
           + ", consistent: "
           + isConsistent
           + ", unsat classes: "
           + numOfUnsatClasses
           + ", time: "
           + time);
 }
  public static void main(String[] args) {
    try {
      SimpleRenderer renderer = new SimpleRenderer();
      renderer.setShortFormProvider(
          new DefaultPrefixManager("http://www.mindswap.org/ontologies/tambis-full.owl#"));
      ToStringRenderer.getInstance().setRenderer(renderer);
      OWLOntologyManager man = OWLManager.createOWLOntologyManager();
      OWLOntology ont =
          man.loadOntology(
              IRI.create(
                  "http://owl.cs.manchester.ac.uk/repository/download?ontology=http://www.cs.manchester.ac.uk/owl/ontologies/tambis-patched.owl"));

      System.out.println("Loaded!");
      OWLReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance();
      OWLReasoner reasoner = reasonerFactory.createNonBufferingReasoner(ont);
      reasoner.getUnsatisfiableClasses();
      ExplanationBasedRootClassFinder rdr =
          new ExplanationBasedRootClassFinder(man, reasoner, reasonerFactory);
      for (OWLClass cls : rdr.getRootUnsatisfiableClasses()) System.out.println("ROOT! " + cls);
    } catch (TimeOutException e) {
      e.printStackTrace();
    } catch (ReasonerInterruptedException e) {
      e.printStackTrace();
    } catch (OWLOntologyCreationException e) {
      e.printStackTrace();
    }
  }
示例#3
0
  public Set<NamingIssue> detectNonMatchingChildIssues(OWLOntology ontology, boolean directChild) {
    long start = System.currentTimeMillis();

    // get SubClass - SuperClass pairs
    Set<NamingIssue> nonMatchingChildren = new HashSet<NamingIssue>();
    if (directChild) {
      Set<OWLSubClassOfAxiom> axioms = ontology.getAxioms(AxiomType.SUBCLASS_OF);
      for (OWLSubClassOfAxiom ax : axioms) {

        OWLClassExpression subClass = ax.getSubClass();
        OWLClassExpression superClass = ax.getSuperClass();

        if (!subClass.isAnonymous() && !superClass.isAnonymous()) {
          String subClassURI = subClass.asOWLClass().toStringID();
          String superClassURI = superClass.asOWLClass().toStringID();

          if (ignoreSingleTokenSubClasses && !singleToken(subClassURI)) {
            String subClassHead = getHeadNoun(subClassURI);
            String superClassHead = getHeadNoun(superClassURI);

            boolean matching =
                subClassHead.equals(superClassHead) || isHypernymOf(superClassHead, subClassHead);

            if (!matching) {
              String newClassURI = buildNewURI(subClassURI, superClassHead);
              nonMatchingChildren.add(
                  new NamingIssue(
                      subClassURI,
                      superClassURI,
                      new RenamingInstruction(subClassURI, newClassURI)));
            }
          }
        }
      }
    } else {
      OWLReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance();
      OWLReasoner reasoner = reasonerFactory.createNonBufferingReasoner(ontology);

      Set<OWLClass> classes = ontology.getClassesInSignature();

      for (OWLClass cls : classes) {
        Set<OWLClass> superClasses = reasoner.getSuperClasses(cls, false).getFlattened();
        superClasses.remove(OWL_THING);
        for (OWLClass superClass : superClasses) {
          String subClassURI = cls.asOWLClass().toStringID();
          String superClassURI = superClass.asOWLClass().toStringID();

          if (ignoreSingleTokenSubClasses && !singleToken(subClassURI)) {
            String subClassHead = getHeadNoun(subClassURI);
            String superClassHead = getHeadNoun(superClassURI);

            boolean matching =
                subClassHead.equals(superClassHead) || isHypernymOf(superClassHead, subClassHead);

            if (!matching) {
              String newClassURI = buildNewURI(subClassURI, superClassHead);
              nonMatchingChildren.add(
                  new NamingIssue(
                      subClassURI,
                      superClassURI,
                      new RenamingInstruction(subClassURI, newClassURI)));
            }
          }
        }
      }
    }

    long end = System.currentTimeMillis();
    logger.info("Operation took " + (end - start) + "ms");

    return nonMatchingChildren;
  }