コード例 #1
0
ファイル: Renderer.java プロジェクト: adrianomelo/tg
  public static void main(String[] args) {
    try {
      BasicConfigurator.configure();

      URI uri = new URI(args[0]);

      OWLOntology onto = OntologyHelper.getOntology(uri);
      Renderer renderer = new Renderer();
      Writer writer = new StringWriter();
      renderer.renderOntology(onto, writer);
      System.out.println(writer.toString());
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
コード例 #2
0
  /**
   * Set the ontology that the validator will work with. Note that this performs some
   * initialisation. This particular implementation does not track ontology changes, so if the
   * ontology is changed before validation takes place, the results may not be as expected.
   *
   * @param ontology an <code>OWLOntology</code> value
   * @param checkImport if true, grab the imports closure and check the species of any imported
   *     ontologies. If false, just look here. Allows us to catch situations where an ontology is
   *     imported that has a higher expressivity, but the classes involved in that aren't explicitly
   *     used in the importer.
   */
  private int species(OWLOntology ontology, boolean checkImport) {
    int result = LITE;

    try {
      this.ontology = ontology;

      // logger.info( "Validating: "
      // + (checkImport?"[imports] ":"")
      // + ontology.getURI() );

      if (reporter != null) {
        reporter.ontology(ontology);
      }

      /* Find the import closure */
      this.allOntologies = OntologyHelper.importClosure(ontology);
      /* Do some initial processing */

      gatherURIs();

      /* Set up all the variables */
      this.namespacesSeparated = true;
      this.correctOWLUsage = true;
      this.correctOWLNamespaceUsage = true;
      this.individualsTyped = true;
      this.classAxiomLevel = FULL;
      this.propertyAxiomLevel = FULL;
      this.expressivityLevel = FULL;

      /* A helper used when reporting stuff. */
      objectRenderer = new ObjectRenderer(ontology);

      /* Now do all the relevant checks */
      checkNamespaceSeparation();
      checkCorrectOWLUsage();
      checkCorrectOWLNamespaceUsage();
      /* This should be done during parsing */
      // checkIndividualTyping();
      checkClassAxioms();
      checkPropertyAxioms();
      checkExpressivity();

      if (!correctOWLNamespaceUsage) {
        /*
         * If there are things in the OWL namespace, we're in OTHER. See
         * http://lists.w3.org/Archives/Public/www-webont-wg/2003Feb/0157.html
         */
        /*
         * This doesn't seem right though. I think it's actually the
         * case that any RDF document is an OWL FULL document. See
         * Section 1.3 of the Overview.
         */
        // result = OTHER;
        result = FULL;
      } else if (!namespacesSeparated || !correctOWLUsage || !individualsTyped) {
        /*
         * If namespaces aren't separated, or redefinitions have
         * occurred, or individuals aren't all explicitly typed, we're
         * in Full
         */

        result = FULL;
      } else {
        /*
         * Otherwise, it's the highest level that's used for classes,
         * properties and expressivity
         */
        result = (classAxiomLevel | propertyAxiomLevel | expressivityLevel);
      }

      if (reporter != null) {
        reporter.done(level(result));
      }

    } catch (OWLException e) {
      result = FULL;
      reporter.explain(FULL, UNKNOWN, "Exception occurred: " + e.getMessage());
    }

    return result;
  }
コード例 #3
0
ファイル: Renderer.java プロジェクト: adrianomelo/tg
  public void renderOntology(OWLOntology ontology, Writer writer) throws RendererException {
    try {
      this.pw = new PrintWriter(writer);
      this.allURIs = OntologyHelper.allURIs(ontology);
      this.allOntologies = OntologyHelper.importClosure(ontology);
      this.visitor = new RenderingVisitor(this);
      this.definedURIs = new HashSet();
      generateShortNames();
      writeShortNames();
      sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
      gmt = java.util.TimeZone.getTimeZone("GMT");
      sdf.setTimeZone(gmt);

      doneThing = false;

      random = new Random();
      anonymousIndividuals = new HashMap();
      for (Iterator ontoIt = allOntologies.iterator(); ontoIt.hasNext(); ) {
        OWLOntology onto = (OWLOntology) ontoIt.next();

        pw.println(" ;; Ontology: " + onto.getURI());

        pw.println();
        pw.println(" ;; Classes ");
        pw.println();
        for (Iterator it = orderedEntities(onto.getClasses()).iterator(); it.hasNext(); ) {
          renderClass(onto, (OWLClass) it.next());
        }
        pw.println(" ;; Object Properties ");

        for (Iterator it = orderedEntities(onto.getObjectProperties()).iterator(); it.hasNext(); ) {
          renderObjectProperty(onto, (OWLObjectProperty) it.next());
        }
        pw.println(" ;; Data Properties ");

        for (Iterator it = orderedEntities(onto.getDataProperties()).iterator(); it.hasNext(); ) {
          renderDataProperty(onto, (OWLDataProperty) it.next());
        }
        pw.println(" ;; Individuals ");

        for (Iterator it = orderedEntities(onto.getIndividuals()).iterator(); it.hasNext(); ) {
          renderIndividual(onto, (OWLIndividual) it.next());
        }
        pw.println(" ;; Class Axioms ");

        for (Iterator it = orderedEntities(onto.getDatatypes()).iterator(); it.hasNext(); ) {
          renderDataType(onto, (OWLDataType) it.next());
        }
        pw.println(" ;;_Datatypes ");

        for (Iterator it = orderedEntities(onto.getClassAxioms()).iterator(); it.hasNext(); ) {
          renderClassAxiom((OWLClassAxiom) it.next());
        }
        pw.println(" ;; Property Axioms ");

        for (Iterator it = orderedEntities(onto.getPropertyAxioms()).iterator(); it.hasNext(); ) {
          renderPropertyAxiom((OWLPropertyAxiom) it.next());
        }

        pw.println(" ;; Individual Axioms ");
        for (Iterator it = orderedEntities(onto.getIndividualAxioms()).iterator(); it.hasNext(); ) {
          renderIndividualAxiom((OWLIndividualAxiom) it.next());
        }
      }

    } catch (OWLException ex) {
      throw new RendererException(ex.getMessage());
    }
  }
コード例 #4
0
ファイル: SimpleOWLReasoner.java プロジェクト: adrianomelo/tg
  public static void main(String[] args) {
    try {
      org.apache.log4j.BasicConfigurator.configure();

      java.net.URI uri = new java.net.URI(args[1]);

      /* Get hold of a reasoner */

      Reasoner digReasoner = new uk.ac.man.cs.img.dig.reasoner.impl.HTTPReasoner(args[0]);

      SimpleOWLReasoner reasoner = new SimpleOWLReasoner(digReasoner);

      OWLOntology onto = OntologyHelper.getOntology(uri);

      reasoner.setOntology(onto);

      try {
        if (!reasoner.isConsistent()) {
          System.out.println("!!! Inconsistent Ontology !!!");
        }
      } catch (Exception ex) {
        // System.out.println( ex.getMessage() );
        ex.printStackTrace();
      }
      for (Iterator it = onto.getClasses().iterator(); it.hasNext(); ) {
        OWLClass clazz = (OWLClass) it.next();

        if (!reasoner.isConsistent(clazz)) {
          System.out.println("Unsatisfiable Class: " + clazz.getURI());
          //		System.out.println( (reasoner.isConsistent( clazz )?"GOOD: ":"BAD:  ") +
          // clazz.getURI() ) ;
        }
        System.out.println(clazz.getURI());
        Set subs = reasoner.subClassesOf(clazz);
        for (Iterator sit = subs.iterator(); sit.hasNext(); ) {
          for (Iterator innerIt = ((Set) sit.next()).iterator(); innerIt.hasNext(); ) {
            OWLClass cl = (OWLClass) innerIt.next();
            System.out.println("> " + cl.getURI());
            System.out.println(reasoner.isSubClassOf(cl, clazz));
          }
        }
        Set supers = reasoner.superClassesOf(clazz);
        for (Iterator sit = supers.iterator(); sit.hasNext(); ) {
          for (Iterator innerIt = ((Set) sit.next()).iterator(); innerIt.hasNext(); ) {
            OWLClass cl = (OWLClass) innerIt.next();
            System.out.println("< " + cl.getURI());
            System.out.println(reasoner.isSubClassOf(clazz, cl));
          }
        }
        Set equivs = reasoner.equivalentClassesOf(clazz);
        for (Iterator eit = equivs.iterator(); eit.hasNext(); ) {
          for (Iterator innerIt = ((Set) eit.next()).iterator(); innerIt.hasNext(); ) {
            OWLClass cl = (OWLClass) innerIt.next();
            System.out.println("= " + cl.getURI());
            System.out.println(reasoner.isEquivalentClass(clazz, cl));
          }
        }
      }
    } catch (ExpressivenessOutOfScopeException ex) {
      System.out.println(ex.getMessage());
    } catch (Exception ex) {
      // System.out.println( ex.getMessage() );
      ex.printStackTrace();
    }
  }