5 Replies Latest reply on May 12, 2008 1:57 PM by alwu-Oracle

    Custom Rules in ORACLE 10g

    617912
      Hi,

      I have an Ontology containing some sample triples.
      for eg:
       
              v1:Item v1:hasCost "100"
              v1:Item v1:hasWarrantyForYears "3"


      There are some instances of Item in the Ontology, with hasColor=100 and some with hasWarrantyForYears=3.

      Now when ever an user asks for items with cost=100 then he should also get Items with warranty of 3 years.Is there any way that one can write a "User Defined Rule' in 10g so that this 'cost=100 or warranty=3' need not be mentioned in the SPARQL and can be implicitly reasoned using the Rule.


      I have tried with this kind of a rule:

      insert into mdsys.rdfr_ECORuleBase1 values( 'Rule1' ,
            
                '(?instance1 rdf:type v1:Item) (?instance1 v1:hasColor "RED")
                '(?instance2 rdf:type v1:Item) (?instance2 v1:hasWarrantyForYears "3")
           
                null ,

                '(?instance1 rdf:type ?instance2) ',

                 sdo_rdf_aliases(
                                         sdo_rdf_alias('v1','http://localhost:8989#') ,
                                         sdo_rdf_alias('v2','http://localhost:8989#')
                                        )

      );



      But this did not work. Please suggest me a good rule for this....


      Thanks,
      Rajesh.
        • 1. Re: Custom Rules in ORACLE 10g
          alwu-Oracle
          Let me try to better understand your question by proposing a simple solution.

          Could you write two separate rules like

          ?x v1:hasCost "100"
          ==> ?x rdf:type http://test.org/InterestingItems

          and

          ?x v1:hasWarrantyForYears "3"
          ==> ?x rdf:type http://test.org/InterestingItems

          Then after inference, a query on (?x rdf:type <http://test.org/InterestingItems>)
          can return you those items either have cost 100 or 3 year warranty.
          • 2. Re: Custom Rules in ORACLE 10g
            617912
            Thanks for the reply.

            Sorry for the confusion in the query. The example I have given might not make a lot of sense from a user's prespective. But i was asked to execute such an use case where, if user asks for items with cost=100 he should also get the items with warranty three, which may be then displayed in a seperate list or some thing.

            I cant query for 'interestingthings' as u said. My query should only ask for items with cost=100.

            Excuse me if i am still unclear...


            Thanks,
            Rajesh.
            • 3. Re: Custom Rules in ORACLE 10g
              alwu-Oracle
              Let me try again, basically you were saying that when you submit a query as follows

              ?x v1:hasCost "100"

              you want to get all x that matches ?x v1:hasWarrantyForYears "3" as well as
              all x matches ?x v1:hasCost "100".

              And you want to rely on inference to generate this.

              I am not sure why you want to do that. But if that is the case, how about adding a simple rule

              ?x v1:hasWarrantyForYears "3"
              ==>
              ?x v1:hasCost "100"
              • 4. Re: Custom Rules in ORACLE 10g
                bjg-Oracle
                Hi!

                I am also trying on a rule much similar to what is being discussed here.

                insert into mdsys.rdfr_RuleBase1 values
                ( 'Rule1' ,
                '( ?instance rdf:type :ClassA)
                (?instance :has_PropertyA ?a) (?a :hasValue ?c)',

                'REGEXP_like(c, ''Open'')' ,

                '(?instance :has_PropertyB ?b) (?b :hasValue "HIGH")' ,

                sdo_rdf_aliases(...)
                )
                );

                The purpose behind this rule is something like:
                If I query for all instaces for ClassA that have the value of the property has_PropertyA as Open, then it should also give me all the instances that have a value for the property has_PropertyB as HIGH.

                But when I query using this rule I donot get the required results.
                The query is:

                select j ID, c propertyA, d propertyB from table

                ( sdo_rdf_match ( '( ?instance rdf:type :ClassA)
                (?instance :has_PropertyA ?a) (?a v2:hasValue ?c)
                (?instance :has_ID ?i) (?i :hasValue ?j)
                (?instance :has_PropertyB ?b) (?b :hasValue ?d)',

                sdo_rdf_models( 'Model1' ) ,

                sdo_rdf_rulebases(‘RuleBase1’) ,

                sdo_rdf_aliases(…),

                'c=''Open'''
                )
                );


                But, I do not get all the extra instances that have propertyB = HIGH. I only get some extra instances wherein propertyA = Open and propertyB = HIGH. The query result leaves many instances where propertyB=HIGH, but the propertyA has many other values.

                So, I am really stuck. I think there is something really wrong with the rule (that I have written). Maybe it needs to be modified to get what is expected. Please help.

                Thanks
                Bhaskar