Exemplo n.º 1
0
  private void renderObjectProperty(OWLOntology ontology, OWLObjectProperty prop)
      throws OWLException {
    //	String key = "defprimrole";

    if (!definedURIs.contains(prop.getURI())) {
      pw.println(" (defprimrole " + shortForm(prop) + ")");
      definedURIs.add(prop.getURI());
    }

    // 	if ( prop.isTransitive( ontology ) ) {
    // 	    pw.print(" :transitive T");
    // 	}

    /* ?? */
    if (prop.isInverseFunctional(ontology)) {
      pw.print(" (functional");
      pw.print(" (inv " + shortForm(prop) + ")");
      pw.println(" )");
    }

    if (!prop.getSuperProperties(ontology).isEmpty()) {
      //	    pw.print(" :supers ( ");
      for (Iterator it = prop.getSuperProperties(ontology).iterator(); it.hasNext(); ) {
        OWLObjectProperty sup = (OWLObjectProperty) it.next();
        //		pw.print(" ;; Super");

        pw.print(" (implies_r ");
        pw.print(shortForm(prop));
        pw.print(" ");
        pw.print(shortForm(sup));
        pw.println(")");
      }
      //	    pw.print(")");
    }

    //	pw.println(")");

    if (prop.isFunctional(ontology)) {
      pw.print(" (functional");
      pw.print(" " + shortForm(prop));
      pw.println(" )");
    }

    if (prop.isTransitive(ontology)) {
      pw.print(" (transitive");
      pw.print(" " + shortForm(prop));
      pw.println(" )");
    }

    for (Iterator it = prop.getDomains(ontology).iterator(); it.hasNext(); ) {
      pw.println(" ;; Domain " + shortForm(prop));
      pw.print(" (domain " + shortForm(prop) + " ");
      OWLDescription dom = (OWLDescription) it.next();
      visitor.reset();
      dom.accept(visitor);
      pw.println(visitor.result() + " )");
    }
    for (Iterator it = prop.getRanges(ontology).iterator(); it.hasNext(); ) {
      pw.println(" ;; Range " + shortForm(prop));
      pw.print(" (range " + shortForm(prop) + " ");
      OWLDescription dom = (OWLDescription) it.next();
      visitor.reset();
      dom.accept(visitor);
      pw.println(visitor.result() + " )");
    }

    if (prop.isSymmetric(ontology)) {
      pw.println(" ;; Symmetry ");
      pw.println(" (equal_r " + " " + shortForm(prop) + " " + "(inv " + shortForm(prop) + " ))");
    }

    for (Iterator it = prop.getInverses(ontology).iterator(); it.hasNext(); ) {
      pw.println(" ;;Inverse " + shortForm(prop));

      pw.print(" (equal_r " + " " + shortForm(prop) + " " + "(inv ");
      OWLObjectProperty inv = (OWLObjectProperty) it.next();
      visitor.reset();
      inv.accept(visitor);
      pw.println(visitor.result() + " ))");
    }
    pw.println();
  }
Exemplo n.º 2
0
  private void checkExpressivity() throws OWLException {
    try {
      /*
       * Here, we need to look at all the expressions used anywhere within
       * the ontology and check their level.
       */

      /* For each ontology, we need to check everything within it */
      expressivityLevel = LITE;
      SwoopExpressionValidatorVisitor evv =
          new SwoopExpressionValidatorVisitor(this, objectRenderer);

      for (Iterator it = allOntologies.iterator(); it.hasNext(); ) {
        OWLOntology onto = (OWLOntology) it.next();
        for (Iterator cit = onto.getClasses().iterator(); cit.hasNext(); ) {
          OWLClass clazz = (OWLClass) cit.next();
          if (!clazz.getEnumerations(onto).isEmpty()) {
            /* We're in DL. */
            expressivityLevel = expressivityLevel | DL;
            URI uri = clazz.getURI();
            explain(
                DL,
                ONEOF,
                "Enumeration used: " + encodeHLink(uri.toString(), myModel.shortForm(uri)));
          }
          for (Iterator superit = clazz.getSuperClasses(onto).iterator(); superit.hasNext(); ) {
            /* Check the expressivity of any superclasses */

            /*
             * Tricky bit here -- if there's an intersection used at
             * the top level, we're still ok for LITE. This is *not*
             * currently catered for, so we will get some stuff
             * wrong.
             */
            OWLDescription description = (OWLDescription) superit.next();
            evv.reset();
            evv.setTopLevelDescription(true);
            try {
              description.accept(evv);
              expressivityLevel = expressivityLevel | evv.getLevel();
            } catch (OWLException ex) {
              explain(OTHER, UNKNOWN, ex.getMessage());
              expressivityLevel = OTHER;
            }
          }
          for (Iterator superit = clazz.getEquivalentClasses(onto).iterator();
              superit.hasNext(); ) {
            /* Check the expressivity of any equivalences */
            /*
             * This is tricky, as these expressions *can* be
             * intersections, as long as they're intersections of
             * Lite constructs. This is the only place that it can
             * happen in Lite.
             */
            OWLDescription description = (OWLDescription) superit.next();
            evv.reset();
            evv.setTopLevelDescription(true);
            try {
              description.accept(evv);
              expressivityLevel = expressivityLevel | evv.getLevel();
            } catch (OWLException ex) {
              explain(OTHER, UNKNOWN, ex.getMessage());
              expressivityLevel = OTHER;
            }
          }
        }
        for (Iterator iit = onto.getObjectProperties().iterator(); iit.hasNext(); ) {
          OWLObjectProperty op = (OWLObjectProperty) iit.next();

          for (Iterator dit = op.getDomains(onto).iterator(); dit.hasNext(); ) {
            /* Check the expressivity of any equivalences */
            OWLDescription description = (OWLDescription) dit.next();
            evv.reset();
            try {
              description.accept(evv);
              expressivityLevel = expressivityLevel | evv.getLevel();
            } catch (OWLException ex) {
              explain(OTHER, UNKNOWN, ex.getMessage());
              expressivityLevel = OTHER;
            }
          }
          for (Iterator dit = op.getRanges(onto).iterator(); dit.hasNext(); ) {
            /* Check the expressivity of any equivalences */
            OWLDescription description = (OWLDescription) dit.next();
            evv.reset();
            try {
              description.accept(evv);
              expressivityLevel = expressivityLevel | evv.getLevel();
            } catch (OWLException ex) {
              explain(OTHER, UNKNOWN, ex.getMessage());
              expressivityLevel = OTHER;
            }
          }
        }

        for (Iterator iit = onto.getDataProperties().iterator(); iit.hasNext(); ) {
          OWLDataProperty dp = (OWLDataProperty) iit.next();

          for (Iterator dit = dp.getDomains(onto).iterator(); dit.hasNext(); ) {
            /* Check the expressivity of any equivalences */
            OWLDescription description = (OWLDescription) dit.next();
            evv.reset();
            try {
              description.accept(evv);
              expressivityLevel = expressivityLevel | evv.getLevel();
            } catch (OWLException ex) {
              explain(OTHER, UNKNOWN, ex.getMessage());
              expressivityLevel = OTHER;
            }
          }
          for (Iterator dit = dp.getRanges(onto).iterator(); dit.hasNext(); ) {
            /* Check the expressivity of any equivalences */
            OWLDataRange description = (OWLDataRange) dit.next();
            evv.reset();
            try {
              description.accept(evv);
              expressivityLevel = expressivityLevel | evv.getLevel();
            } catch (OWLException ex) {
              explain(OTHER, UNKNOWN, ex.getMessage());
              expressivityLevel = OTHER;
            }
          }
        }

        for (Iterator iit = onto.getIndividuals().iterator(); iit.hasNext(); ) {
          OWLIndividual ind = (OWLIndividual) iit.next();

          for (Iterator typeit = ind.getTypes(onto).iterator(); typeit.hasNext(); ) {
            /* Check the expressivity of any equivalences */
            OWLDescription description = (OWLDescription) typeit.next();

            evv.reset();
            try {
              description.accept(evv);
              expressivityLevel = expressivityLevel | evv.getLevel();
            } catch (OWLException ex) {
              explain(OTHER, UNKNOWN, ex.getMessage());
              expressivityLevel = OTHER;
            }
          }
        }
      }

      Set complexProperties = evv.getComplexProperties();
      /*
       * Gather all the properties that are known to be functional or
       * inverse functional
       */
      for (Iterator it = allOntologies.iterator(); it.hasNext(); ) {
        OWLOntology onto = (OWLOntology) it.next();
        for (Iterator pit = onto.getObjectProperties().iterator(); pit.hasNext(); ) {
          OWLObjectProperty prop = (OWLObjectProperty) pit.next();
          if (prop.isFunctional(onto) || prop.isInverseFunctional(onto)) {
            complexProperties.add(prop);
          }
        }
      }

      /*
       * We aren't doing everything yet as we still need to grab those
       * that have complex superproperties.
       */

      /*
       * Now check to see if they've been said to be transitive, in which
       * case we're in FULL.
       */
      for (Iterator pit = complexProperties.iterator(); pit.hasNext(); ) {
        OWLObjectProperty prop = (OWLObjectProperty) pit.next();
        for (Iterator it = allOntologies.iterator(); it.hasNext(); ) {
          OWLOntology onto = (OWLOntology) it.next();
          if (prop.isTransitive(onto)) {
            expressivityLevel = FULL;
            URI uri = prop.getURI();
            explain(
                FULL,
                COMPLEXTRANSITIVE,
                "Complex property "
                    + encodeHLink(uri.toString(), myModel.shortForm(uri))
                    + " asserted to be transitive.");
          }
        }
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      throw new OWLException(ex.getMessage());
    }
  }