1 2 Previous Next 16 Replies Latest reply on Oct 16, 2008 6:43 PM by alwu-Oracle

    OWLPrime and Jena

    652134
      Hello,

      System Specs:
      Oracle 11g
      Oracle Jena Adapter 2.0
      Jena 2.5.6

      I am trying to leverage the transitive, inverse, etc. properties of an ontology I downloaded. The ontology I am using references the Relationship Ontology (RO) from the OBO Foundry. The Relationship Ontology contains several transitive properties including the has_part property. I have a SPARQL query that I execute using Jena. My ontology contains some information in the form: A has_part B, A has_part C, B has_part D. Without creating any entailments, I was able to correctly query my ontology and get 2 results when I ran the query "SELECT * WHERE A has_part ?parts".

      Now I want to take the next step and return the transitive cases where A has_part D (via the fact that B has_part D). To accomplish this, I loaded the "main ontology" along with the Relationship Ontology into an Oracle semantic model. Next, I ran the following through SQL*Plus to create the entailments: exec sem_apis.create_entailment(‘ontology_model_idx’,sem_models(‘ontology’), sem_rulebases(‘owlprime’));. The procedure ran fine without any errors. However, I still only get the same 2 results when I run "SELECT * WHERE A has_part ?parts". I am not returning the transitive cases. What else do I need to do? Do I need to add Pellet to my Jena code? If so, why? Aren't the inferences already in the Oracle table?
      Thanks,
      Chuck
        • 1. Re: OWLPrime and Jena
          alwu-Oracle
          Are you using Attachment?

          I assume when you say you run "SELECT * WHERE A has_part ?parts"
          you actually mean that you run that SPARQL from Jena Adaptor.

          Here is a snippet that illustrates how.
          Please first drop that entailment 'ontology_model_idx' you did in sqlplus. This
          is because Jena Adaptor by default assumes certain naming convention
          for the entailment.

          Attachment attachment = Attachment.createInstance(
          Attachment.NO_ADDITIONAL_MODELS, "OWLPRIME",
          InferenceMaintenanceMode.NO_UPDATE,
          QueryOptions.DEFAULT);
          GraphOracleSem graph = new GraphOracleSem(oracle, modelName, attachment);
          ModelOracleSem model = new ModelOracleSem(graph);

          ... add triples (if the data is already loaded, then do nothing) ...

          graph.performInference();

          graph.analyzeInferredGraph();

          ... run SPARQL query against model ...
          • 2. Re: OWLPrime and Jena
            652134
            Hi Alan,
            I wasn't using Attachment. I followed your instructions and it worked!
            Thanks.
            • 3. Re: OWLPrime and Jena
              652134
              I have a few more follow up questions.

              1. If I call create_entailment on my model, does that result in faster execution of the query? Does the attachment code create the OWLPrime entailment on the fly? I would prefer to build the entailment in the database rather than doing it on the fly.

              2. Where is the documentation for the Attachment class?

              3. Can I use Attachment with my own set of rules? If so, can you provide some pseudo-code for loading a rule set from a file?

              Thank you.
              • 4. Re: OWLPrime and Jena
                alwu-Oracle
                create_entailment will run inference inside the DB and materialize the new triples. It is not meant for speeding up queries but rather to perform logical inference and discover new/hidden information. It is certainly faster compared to running inference on the fly in order to answer queries.

                Attachment class is documented in the Javadoc.

                You can certainly use user-defined rules from Jena Adaptor (2.0). I will post
                sample code snippet code later. I am on a business trip right now.
                • 5. Re: OWLPrime and Jena
                  alwu-Oracle
                  Sorry for the delay. You can follow the following example.



                  OracleUserRuleBase userrb = OracleUserRuleBase.createInstance(oracle, rbName);
                  // userrb.quitelyRemoveRule("uncle");

                  ...

                  Triple[] body = new Triple[2];
                  body[0] = Triple.create(Node.createVariable("x"),
                  Node.createURI("http://example.com/parentOf"),
                  Node.createVariable("y"));
                  body[1] = Triple.create(Node.createVariable("z"),
                  Node.createURI("http://example.com/brother"),
                  Node.createVariable("x"));
                  Triple head = Triple.create(Node.createVariable("z"),
                  Node.createURI("http://example.com/uncleOf"),
                  Node.createVariable("y"));

                  OracleUserRule our = OracleUserRule.createInstance("uncle", body, head);
                  try {
                  userrb.addRule(our);

                  }
                  catch (RuleAlreadyExistsException raee) {
                  // ignore for now.
                  }


                  oracle.commitTransaction();

                  // ... Now to use the above rule base, ...

                  Attachment attachment = Attachment.createInstance(
                  Attachment.NO_ADDITIONAL_MODELS, rbName,
                  InferenceMaintenanceMode.UPDATE_WHEN_COMMIT,
                  QueryOptions.DEFAULT);
                  graph = new GraphOracleSem(oracle, modelName, attachment);
                  graph.performInference();

                  ExtendedIterator it = graph.find(Triple.ANY);
                  ....

                  // you may also want to analyze graph, analyze rules index.
                  • 6. Re: OWLPrime and Jena
                    alwu-Oracle
                    Sorry for the indentation. Leading spaces are truncated by this Forum software for some reason.
                    • 7. Re: OWLPrime and Jena
                      652134
                      thanks Alan. I'll give it a try.
                      • 8. Re: OWLPrime and Jena
                        652134
                        Hi Alan,
                        I'm having a bit of trouble using my rule. First, I created my rule by executing the following commands from SQL*PLUS:

                        execute sem_apis.create_rulebase('user_rulebase');

                        INSERT INTO mdsys.semr_user_rulebase VALUES ('obo_has_part',
                        '(?whole <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?sub) (?sub <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Restriction>) (?sub <http://www.w3.org/2002/07/owl#onProperty> <http://www.obofoundry.org/ro/ro.owl#has_part>) (?sub <http://www.w3.org/2002/07/owl#someValuesFrom> ?part)', NULL, '(?whole <http://www.obofoundry.org/ro/ro.owl#has_part> ?part)', null);

                        Now I am trying to use the following code to execute my new rule along with the OWLPRIME rules from Java:

                        ...
                        String[] rulelist = new String[2];
                        rulelist[0] = new String("OWLPRIME");
                        rulelist[1] = new String("USER_RULEBASE");

                        Attachment attachment = Attachment.createInstance(
                        Attachment.NO_ADDITIONAL_MODELS, rulelist,
                        InferenceMaintenanceMode.NO_UPDATE,
                        QueryOptions.DEFAULT);
                        ...
                        graph.performInference();
                        graph.analyzeInferredGraph();


                        I am seeing the following output and errors:

                        INFO [main] (SimpleLog.java:49) - performInference: has valid entailment already
                        INFO [main] (SimpleLog.java:49) - Final clause = SELECT part$RDFVTYP, part$RDFLTYP, part$RDFLANG, part$RDFCLOB, decode(part$RDFVTYP, 'BLN', ('_:'||substr(part,instr(part,'m',4)+1)), part) part, whole$RDFVTYP, decode(whole$RDFVTYP, 'BLN', ('_:'||substr(whole,instr(whole,'m',4)+1)), whole) whole FROM table(sdo_rdf_match('(?whole <http://www.obofoundry.org/ro/ro.owl#has_part> ?part) ', sdo_rdf_models('NEURON_ONTOLOGY'), sdo_rdf_rulebases('OWLPRIME','USER_RULEBASE'), null, null, null))
                        Error: rethrew: java.sql.SQLException: ORA-20000: We do not have a rules index for this Model-Rulebase combination
                        ORA-06512: at "MDSYS.RDF_MATCH_IMPL_T", line 176
                        ORA-06512: at line 1

                        Do I need to run sem_apis.create_entailment?

                        Thanks,
                        Chuck
                        • 9. Re: OWLPrime and Jena
                          alwu-Oracle
                          The trace tells me that somehow+ you already have a valid inference (entailment). That is why that performInference did not do anything.

                          Could you please try to remove that entailment from SQLPLUS?

                          The entailment name should be, by default, <model_name>_RI

                          Just issue the following command

                          SQL> exec sem_apis.drop_entailment('<entailment_name_here>');

                          I am assuming you are using 11gR1.
                          • 10. Re: OWLPrime and Jena
                            alwu-Oracle
                            Alternatively, if you want to do it in your Java code,
                            you can use the following before performInference

                            try {
                            graph.deleteInference();
                            }
                            catch(SQLException sqle) {
                            // ... your exception handling logic here ...
                            }
                            • 11. Re: OWLPrime and Jena
                              652134
                              Hi Alan,
                              I call graph.deleteInference and that eliminates the "performInference: has valid entailment already" from my output. However, my rules do not appear to be firing. I dropped my old rule base using the drop_rulebase API call. I then create a new rule base called 'obo_rules' using the create_rulebase API call. I created a simpler rule called obo_test using the following SQL:

                              INSERT INTO mdsys.semr_obo_rules VALUES ('obo_test',
                              '(?whole <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?sub)', NULL, '(?whole <http://sw.brainstage.com/has_subclass> ?sub)', null);

                              Obviously this isn't a very useful rule. All I'm doing is replacing the rdfs:subClassOf with my own property. However, it simplifies my testing.

                              Using SPARQL and Jena, I can return several records if I select "?whole <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?sub". However, I never return any records if I select "?whole <http://sw.brainstage.com/has_subclass> ?sub". I can select the information on my rule from the mdsys.semr_obo_rules table. The antecedents and consequents look fine.

                              You asked if I was using 11gR1. How do I check? According to "select * from v$version", I am running 11.1.0.6.0.

                              Thanks,
                              Chuck
                              • 12. Re: OWLPrime and Jena
                                alwu-Oracle
                                Hi,

                                I am listing my action and code snippets below. I don't see any problem.

                                SQL> exec sem_apis.create_rulebase('obo_rules');

                                PL/SQL procedure successfully completed.

                                SQL> INSERT INTO mdsys.semr_obo_rules VALUES ('obo_test',
                                '(?whole <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?sub)', NULL, '(?whole <http://sw.brainstage.com/has_subclass> ?sub)' 2 , null);
                                commit;

                                1 row created.

                                SQL>
                                Commit complete.


                                -------------------------
                                Then on the java side

                                String[] rbs = {"OWLPRIME", "OBO_RULES"};

                                Attachment attachment = Attachment.createInstance(
                                Attachment.NO_ADDITIONAL_MODELS, rbs,
                                InferenceMaintenanceMode.NO_UPDATE,
                                QueryOptions.DEFAULT);

                                g = new GraphOracleSem(oracle, modelName, attachment);
                                ModelOracleSem m = new ModelOracleSem(g);

                                g.performInference();

                                String queryString =
                                " SELECT ?s ?p ?o " +
                                "WHERE { ?s ?p ?o } ";

                                QueryExecution qexec = QueryExecutionFactory.create(
                                QueryFactory.create(queryString), m);

                                ResultSet qrs = qexec.execSelect();
                                while (qrs.hasNext()) {
                                QuerySolution soln = qrs.nextSolution();
                                psOut.println("soln " + soln);
                                }


                                -------
                                Finally, this is the output
                                soln ( ?s = <urn:s> ) ( ?p = rdfs:subClassOf ) ( ?o = <urn:o> )
                                soln ( ?s = <urn:s> ) ( ?p = <http://sw.brainstage.com/has_subclass> ) ( ?o = <urn:o> )
                                • 13. Re: OWLPrime and Jena
                                  652134
                                  Hi Alan,
                                  I ran your code and made the following modification:

                                  String queryString =
                                  " SELECT ?s ?o " +
                                  "WHERE { ?s <http://sw.brainstage.com/has_subclass> ?o } ";

                                  No results were returned. If it works for you then obviously it is something on my end. The OWLPRIME rules appear to work correctly. The graph returns transitive relationships according to the OWLPRIME rules. However, it does not recognize my rules. I must be missing an update or a patch. Is there an update that affects the user defined rules? Is there something to check to make sure I am fully up to date? I tried creating the rules using Jena. When I make this call:

                                  OracleUserRuleBase userrb = OracleUserRuleBase.createInstance(oracle, rbName);

                                  I get this error:

                                  java.lang.NoClassDefFoundError: oracle/spatial/rdf/server/ParseException

                                  This makes me think I am not up to date.

                                  Thanks,
                                  Chuck
                                  • 14. Re: OWLPrime and Jena
                                    alwu-Oracle
                                    First, you need to have sdordf.jar in your classpath. Please refer to README for details.

                                    Second, please create GraphOracleSem and ModelOracleSem after creating Attachment object, similar to what I used in the snippet.
                                    Note that ModelOracleSem is created after GraphOracleSem. The order is important.

                                    If it still does not work for you , please post the snippet starting from GraphOracleSem, ModelOracleSem, and Attachment creation.

                                    Cheers,
                                    1 2 Previous Next