9 Replies Latest reply on Nov 2, 2010 9:31 PM by alwu-Oracle

    Oracle RDF Rules Semantics

    548445
      Hi,

      Are the semantics of the rules for Oracle RDF documented anywhere? I'm not exactly sure what I can and cannot say.

      thanks

      John
        • 1. Re: Oracle RDF Rules Semantics
          Mannamal-Oracle
          Oracle 10gR2 supports RDFS, according to the semantics specified in the W3C standard (at http://www.w3.org/TR/rdf-mt/ specifically under section 7.3 'RDFS Entailment Rules'.

          Oracle 10gR2 also supports what we call user-defined rules, where the user can specify semantics through the definition of rules.

          Let me know if this does not answer your question.

          Melli
          • 2. Re: Oracle RDF Rules Semantics
            548445
            Hi Melli,

            Thanks for your reply. I was actually after the semantics of the "user defined" rules. For example are they Horn type rules or something else?

            cheers

            John

            Message was edited by:
            John Goodwin
            • 3. Re: Oracle RDF Rules Semantics
              Mannamal-Oracle
              Hi John,

              They are not horn type rules. A user-defined rule consists of an IF side pattern for the antecedents, and a THEN side pattern for the consequents. The antecedent and consequent patterns are sets of triples, triples within a set are combined with an implicit 'AND'.

              Example: (?a :parentOf ?b)(?b :parentOf ?c) => (?a :grandParentOf ?c).

              (If both (?a :parentOf ?b) AND (?b :parentOf ?c) are true, then the triple (?a :grandParentOf ?c) is inferred.

              A filter condition can be associated with a rule (details are in section 1.2.10 of the RDF documentation in 10gR2): For the above rule a filter condition could be:
              'c = ''Peter'' or c = ''Jack''' This would restrict the triples the rules would apply to.

              The exact syntax of adding a rule can be seen in the documentation.

              Melli
              • 4. Re: Oracle RDF Rules Semantics
                548445
                Hi Melli,

                Thanks for your reply. That's what I was looking for.

                John
                • 5. Re: Oracle RDF Rules Semantics
                  673499
                  I'm trying to create user defined rule function and bind variable in rule syntax, but i dont know how to do that in
                  Oracle Db. I did that successfully when i tried in Jena and using RDF/XML File...
                  For example i have such RDF/XML file like this :

                  <?xml version="1.0"?>
                  <rdf:RDF
                  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
                  xmlns:owl="http://www.w3.org/2002/07/owl#"
                  xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
                  xmlns="http://www.owl-ontologies.com/Ontology1230795417.owl#"
                  xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
                  xml:base="http://www.owl-ontologies.com/Ontology1230795417.owl">
                  <owl:Ontology rdf:about=""/>
                  <owl:Class rdf:ID="Example"/>
                  <owl:FunctionalProperty rdf:ID="has_factorialvalue">
                  <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#int"/>
                  <rdfs:domain rdf:resource="#Example"/>
                  <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
                  </owl:FunctionalProperty>
                  <owl:FunctionalProperty rdf:ID="has_value">
                  <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#int"/>
                  <rdfs:domain rdf:resource="#Example"/>
                  <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
                  </owl:FunctionalProperty>
                  <Example rdf:ID="Example_1">
                  <has_value rdf:datatype="http://www.w3.org/2001/XMLSchema#int" >5</has_value>
                  </Example>
                  <Example rdf:ID="Example_2">
                  <has_value rdf:datatype="http://www.w3.org/2001/XMLSchema#int">3</has_value>
                  </Example>
                  </rdf:RDF>

                  I have one Class "Example" which has 2 datatype properties : has_value and has_factorial_value, So if I have
                  an Example1 as an instance of Example which has_value is 5 then has_factorial_value must be 120.

                  So the Rule is

                  exampletestrule1: (?b rdf:type h:Example) (?b h:has_value ?z) myfactorial(?z,?rs) -> (?b h:has_factorialvalue ?rs)

                  Here for the source code
                  .....

                  Now... The problem is how to implement this user defined rule in Oracle db (create our own builtin function then apply it to oracle semantic rule, in this case, myfactorial
                  • 6. Re: Oracle RDF Rules Semantics
                    801615
                    Hi,

                    I found this old thread and wonder if this question was answered? I'd like to restate it as I have come to the point where I need to work with user defined rules.
                    I'd liked to know what kind of functions/builtins are supported for FILTER clause and is there a way to plugin own implemenations of functions

                    Thanks
                    Jürgen
                    • 7. Re: Oracle RDF Rules Semantics
                      alwu-Oracle
                      Hi Jürgen,

                      It is possible to plug-in one's own functions that can potentially generate triples involving new URIs, literal values, etc.
                      Here is one example.

                      - Say we have the following RDF model about an individual's first name (fn) and last name (ln).

                      create table mytest (triple sdo_rdf_triple_s) compress;
                      exec sem_apis.create_sem_model('mytest','mytest','triple');

                      insert into mytest values(sdo_rdf_triple_s('mytest','<urn:s1>','<urn:fn>','"John"'));
                      insert into mytest values(sdo_rdf_triple_s('mytest','<urn:s1>','<urn:ln>','"Doe"'));

                      - we run OWLPrime inference (or RDFS inference)
                      ... details skipped ...

                      - Say we want to implement a rule that concatenate first names with their corresponding last names.
                      We can implement this rule as a query and insert query results into the model.

                      insert into mytest
                      select sdo_rdf_triple_s('mytest',s, '<urn:fullname>', '"'||fn||' '||ln||'"')
                      from (select s, fn, ln
                      from table(sem_match('{?s <urn:fn> ?fn . ?s <urn:ln> ?ln }',
                      sem_models('mytest'), null, null, null, null)
                      )
                      )
                      ;

                      Note that the above example does not take escaping into consideration for simplicity.

                      - re-run OWLPrime inference if necessary and repeat the insert if necessary.

                      Note that you can check the count on MDSYS.RDFM_MYTEST to detect if there is indeed any "new"
                      triples inserted. You can also add a "where not exisits" to avoid inserting duplicates into the application table.

                      It is obvious that you can plug-in your own functions to the query portion of the above insert statement.

                      To leverage incremental inference, please look into the "delta_in" parameter of SEM_APIS.create_entailment.

                      Thanks,

                      Zhe Wu
                      • 8. Re: Oracle RDF Rules Semantics
                        801615
                        Zhu,

                        Thanks for the reply. This answer raises further questions.

                        1. My initial question was about Oracle user-defined rules, which has the syntax (antecedents)(filter)->(consequents)
                        What kind of filter expressions are allowed and what is the syntax for filters, is there any builtin functions available?
                        From the answer about user-plugins I assume that one can not have them in the user-defined rule, however one can implement them as insert statments of query results.

                        2. This leads to a question about inserting new triples as a result of user-defined rules execution. The example above shows how to do this but it happens outside of Oracle's inference engine, isn't it?
                        So the inserted triples are not part of inference graph and can't be dropped with SEM_APIS.DROP_ENTAILMENT, as it would be case with triples asserted by user-defined rulebase (parameter to SEM_APIS.CREATE_ENTAILMENT).
                        Another issue, seems to me, is that how would I know how many passes of inference and custom inserts do I need to run before the closure is reached? With combined inference/user-defined rules entailment I would rely on SEM_APIS.REACH_CLOSURE flag. If rules are executed outside of inference engine, do I need to run a while loop, which runs until no new triples are added and I'd need to check the count at each step?

                        3. How to control incremental reasoning and delta_in parameter with Jena Adapter? There is no performInference method which allows to specify that?

                        I would actually like to implement my user-defined rules as SPARQL CONSTRUCT statements (SPIN rules) and I will post another thread about the question how to do it with Oracle in best way.

                        Thanks
                        Jürgen

                        Edited by: user8793616 on 2010-nov-02 00:41
                        • 9. Re: Oracle RDF Rules Semantics
                          alwu-Oracle
                          Hi,

                          The following document has some examples on user defined rules.
                          http://download.oracle.com/docs/cd/E11882_01/appdev.112/e11828/owl_concepts.htm

                          You can use complex expression for the filter part of the user defined rules.
                          e.g.

                          insert into mdsys.rdfr_trb (rule_name, ANTECEDENTS,filter, CONSEQUENTS) values('r2','(?z <urn:height> ?h)', '(decode(regexp_replace (ltrim(h,''-''),''\.|[0-9]'',''''), null, to_number(h), 0) >= 6)', '(?z <urn:type> <urn:tall>)');

                          You can also reference your own functions in the filter. However, these expressions/functions are not allowed
                          in the consequent.

                          Regarding 2). Yes. You need a loop until no new triples are added because this whole process is obviously outside the inference
                          engine.

                          Regarding 3). GraphOracleSem has setInferenceOption API. e.g.
                          graphOracleSem.setInferenceOption("INC=T,DOP=4,RAW8=T");

                          delta_in parameter is not supported by Jena Adapter at this moment.

                          Thanks,

                          Zhe Wu