3 Replies Latest reply on May 19, 2009 1:21 PM by alwu-Oracle

    listOntClasses direct=false

    696067
      According to the Jena docs, the definition of listOntClasses is as follows:

      -----
      listOntClasses
      ExtendedIterator listOntClasses(boolean direct)
      Answer an iterator over the ontology classes to which this individual belongs. The members of the iterator will be OntClass objects.
      Parameters:
      direct - If true, only answer those resources that are direct types of this individual, not the super-classes of the class etc.
      Returns:
      An iterator over the set of this individual's classes. Each member of the iteration will be an OntClass.
      -----

      Yet when I create a InMemOwlModel and an individual like so:
      -----
      Oracle oracle = new Oracle(url, user, password);
      OntModel model = OntologyUtils.createInMemOwlModel(oracle, "owltst_model");

      OntClass serviceEntityClass = model.createClass(NS+"Service_Entity");
      serviceEntityClass.addLabel("ServiceEntity", "en");
      serviceEntityClass.addSuperClass(entityClass);

      OntClass indexerClass = model.createClass(NS+"Indexer");
      indexerClass.addLabel("Indexer", "en");
      indexerClass.addSuperClass(serviceEntityClass);

      Individual indexerInstance = model.createIndividual(NS+indexerName, indexerClass);
      -----

      And then ask for all of the subclasses of indexerInstance like so:
      -----
      ExtendedIterator t = ((Individual)statement.getSubject().as(Individual.class)).listOntClasses(false);
      ArrayList<String> ret = new ArrayList<String>();
      while(t.hasNext()){
           ret.add(t.next().toString());
      }
      return ret.toString();
      -----

      the response is this:
      \[http://search.owl#Indexer\]

      It seems that something in wrong with the InMemOwlModel, since I specified 'false' for the 'direct' parameter, I should get all of indexerInstance's superclasses. The response should be this:
      \[ http://search.owl#Indexer, http://search.owl#Service_Entity \]
        • 1. Re: listOntClasses direct=false
          alwu-Oracle
          This is expected behavior.

          The reason is that OntologyUtils.createInMemOwlModel creates an empty ontology model first and then add
          the contents of ModelOracleSem to the ontology model created. The empty ontology model is created using
          OntModelSpec.OWL_MEM which does not provide additional entailment reasoning (per Jena's documentation).

          To get what you want, try something like this.

          Model modelOracle = ModelOracleSem.createOracleSemModel(
          oracle, "owltst_model");

          OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF,
          null);
          model.add(modelOracle);
          modelOracle.close();

          OntClass entityClass = model.createClass(NS+"Entity");
          entityClass.addLabel("entity", "en");

          OntClass serviceEntityClass = model.createClass(NS+"Service_Entity");
          serviceEntityClass.addLabel("ServiceEntity", "en");
          serviceEntityClass.addSuperClass(entityClass);

          OntClass indexerClass = model.createClass(NS+"Indexer");
          ...

          ExtendedIterator t = ((Individual)statement.getSubject().as(Individual.class)).listOntClasses(false);
          ...



          Finally, what I got is as follows. Note that owl:Thing is there too.

          [http://www.oracle.com/abc#Indexer, http://www.w3.org/2002/07/owl#Thing, http://www.oracle.com/abc#Service_Entity, http://www.oracle.com/abc#Entity]


          If I change that false to true, then I got
          [http://www.oracle.com/abc#Indexer]

          Cheers,

          Zhe Wu
          • 2. Re: listOntClasses direct=false
            696067
            Ah, so basicaly this command:
            OntologyUtils.createInMemOwlModel(...);

            Does this?
            OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
            model.add(modelOracle);
            modelOracle.close();
            • 3. Re: listOntClasses direct=false
              alwu-Oracle
              You are right. Basically, it loads an Oracle semantic model into in memory Jena OntModel.

              Cheers,

              Zhe Wu
              1 person found this helpful