示例#1
0
 public Set<OWLObjectProperty> getObjectPropertiesByDomainAndRange(
     OWLClass domain, OWLClass range) {
   Set<OWLObjectProperty> propSet = new HashSet<OWLObjectProperty>();
   for (OWLObjectProperty prop : _ontology.getObjectPropertiesInSignature()) {
     for (OWLClass owlClass : _reasoner.getObjectPropertyDomains(prop, true).getFlattened()) {
       if (owlClass.equals(domain)) {
         for (OWLClass owlClass2 : _reasoner.getObjectPropertyRanges(prop, true).getFlattened()) {
           if (owlClass2.equals(range)) {
             propSet.add(prop);
           }
         }
       }
     }
   }
   return propSet;
 }
示例#2
0
 public Set<OWLDataProperty> getDataPropertiesByDomain(OWLClass domain) {
   Set<OWLDataProperty> propSet = new HashSet<OWLDataProperty>();
   Set<OWLDataProperty> objProps = _ontology.getDataPropertiesInSignature();
   for (OWLDataProperty prop : objProps) {
     for (OWLClass owlClass : _reasoner.getDataPropertyDomains(prop, true).getFlattened()) {
       if (owlClass.equals(domain)) {
         propSet.add(prop);
       }
     }
   }
   return propSet;
 }
  public Set<OWLClass> getRootUnsatisfiableClasses() {
    //	    StructureBasedRootClassFinder srd = new StructureBasedRootClassFinder(this.baseReasoner);
    StructuralRootDerivedReasoner srd =
        new StructuralRootDerivedReasoner(this.manager, this.baseReasoner, this.reasonerFactory);
    Set<OWLClass> estimatedRoots = srd.getRootUnsatisfiableClasses();
    this.cls2JustificationMap = new HashMap<OWLClass, Set<Explanation>>();
    Set<OWLAxiom> allAxioms = new HashSet<OWLAxiom>();

    for (OWLOntology ont : this.baseReasoner.getRootOntology().getImportsClosure()) {
      allAxioms.addAll(ont.getLogicalAxioms());
    }

    for (OWLClass cls : estimatedRoots) {
      this.cls2JustificationMap.put(cls, new HashSet<Explanation>());
      System.out.println("POTENTIAL ROOT: " + cls);
    }
    System.out.println("Finding real roots from " + estimatedRoots.size() + " estimated roots");

    int done = 0;
    this.roots.addAll(estimatedRoots);
    for (OWLClass estimatedRoot : estimatedRoots) {
      try {
        PelletExplanationGenerator gen =
            new PelletExplanationGenerator(manager.createOntology(allAxioms));
        OWLDataFactory df = this.manager.getOWLDataFactory();
        Set<Explanation> expls =
            gen.getExplanations(df.getOWLSubClassOfAxiom(estimatedRoot, df.getOWLNothing()));
        cls2JustificationMap.get(estimatedRoot).addAll(expls);
        ++done;
        System.out.println("Done " + done);
      } catch (OWLOntologyCreationException e) {
        e.printStackTrace();
      }
    }
    for (OWLClass clsA : estimatedRoots) {
      for (OWLClass clsB : estimatedRoots)
        if (!clsA.equals(clsB)) {
          Set<Explanation> clsAExpls = cls2JustificationMap.get(clsA);
          Set<Explanation> clsBExpls = cls2JustificationMap.get(clsB);
          boolean clsARootForClsB = false;
          boolean clsBRootForClsA = false;

          for (Explanation clsAExpl : clsAExpls) {
            for (Explanation clsBExpl : clsBExpls)
              if (isRootFor(clsAExpl, clsBExpl)) {
                clsARootForClsB = true;
              } else if (isRootFor(clsBExpl, clsAExpl)) {
                clsBRootForClsA = true;
              }
          }

          Explanation clsAExpl;
          if ((!clsARootForClsB) || (!clsBRootForClsA))
            if (clsARootForClsB) {
              this.roots.remove(clsB);
            } else if (clsBRootForClsA) this.roots.remove(clsA);
        }
    }

    OWLClass clsA;
    return this.roots;
  }
 public boolean isRestrictedInstantiator(OWLClass c) {
   return c == null
       || c.isTopEntity()
       || m_ontologyOperator.getFlatteningTransformer().isIntermediary(c)
       || c.equals(m_referenceClass);
 }
  public static void main(String[] args) throws Exception {
    if (args.length == 0) {
      //			args = new String[] { "/home/yzhou/backup/20141212/univ-bench-dl-queries.owl"};
      args = new String[] {PagodaTester.onto_dir + "fly/fly-all-in-one_rolledUp.owl"};
      //			args = new String[] { PagodaTester.onto_dir +
      // "dbpedia/integratedOntology-all-in-one-minus-datatype.owl" };
      //			args = new String[] { PagodaTester.onto_dir + "npd/npd-all-minus-datatype.owl" };
      //			args = new String[] { PagodaTester.onto_dir + "bio2rdf/chembl/cco-noDPR.ttl" };
      //			args = new String[] { PagodaTester.onto_dir +
      // "bio2rdf/reactome/biopax-level3-processed.owl" };
      //			args = new String[] { PagodaTester.onto_dir + "bio2rdf/uniprot/core-processed-noDis.owl"
      // };
    }

    //		OWLOntology ontology = OWLHelper.getMergedOntology(args[0], null);
    //		OWLHelper.correctDataTypeRangeAxioms(ontology);
    OWLOntology ontology = OWLHelper.loadOntology(args[0]);

    OWLOntologyManager manager = ontology.getOWLOntologyManager();
    OWLDataFactory factory = manager.getOWLDataFactory();
    //		manager.saveOntology(ontology, new FileOutputStream(args[0].replace(".owl",
    // "_owlapi.owl")));

    if (outputFile != null) Utility.redirectCurrentOut(outputFile);

    int queryID = 0;
    for (OWLClass cls : ontology.getClassesInSignature(true)) {
      if (cls.equals(factory.getOWLThing()) || cls.equals(factory.getOWLNothing())) continue;
      if (!cls.toStringID().contains("Query")) continue;
      System.out.println("^[Query" + ++queryID + "]");
      System.out.println(template.replace("@CLASS", cls.toStringID()));
      System.out.println();
    }

    for (OWLOntology onto : ontology.getImportsClosure())
      for (OWLObjectProperty prop : onto.getObjectPropertiesInSignature()) {
        //				if (!prop.toStringID().contains("Query")) continue;
        System.out.println("^[Query" + ++queryID + "]");
        System.out.println("SELECT ?X ?Y");
        System.out.println("WHERE {");
        System.out.println("?X <" + prop.toStringID() + "> ?Y .");
        System.out.println("}");
        System.out.println();
      }

    String[] answerVars = new String[] {"?X", "?Y"};

    for (OWLOntology onto : ontology.getImportsClosure())
      for (OWLObjectProperty prop : onto.getObjectPropertiesInSignature()) {
        //				if (!prop.toStringID().contains("Query")) continue;
        for (int i = 0; i < answerVars.length; ++i) {
          System.out.println("^[Query" + ++queryID + "]");
          System.out.println("SELECT " + answerVars[i]);
          System.out.println("WHERE {");
          System.out.println("?X <" + prop.toStringID() + "> ?Y .");
          System.out.println("}");
          System.out.println();
        }
      }

    if (outputFile != null) Utility.closeCurrentOut();
  }