This discussion is archived
7 Replies Latest reply: Dec 1, 2011 10:40 AM by JorgeB-Oracle RSS

Inference Sparql

880207 Newbie
Currently Being Moderated
Hi ,

I have below requirement -
MyData:-
<http://mywebsite/Vicks> <http://mywebsite/BrotherOf> <http://mywebsite/Dips>
<http://mywebsite/Vicks> <http://mywebsite/hasFather> <http://mywebsite/Joe>

I want to infer from above data that <http://mywebsite/Dips> <http://mywebsite/hasFather> <http://mywebsite/Joe> .
What property i should add to MyData inorder to infer above result. I am looking for a SPARQL Query.

Thanks,
Manish H
  • 1. Re: Inference Sparql
    JorgeB-Oracle Journeyer
    Currently Being Moderated
    Hi Manish,

    In order to infer that

    <http://mywebsite/Dips> <http://mywebsite/hasFather> <http://mywebsite/Joe> .

    From:

    <http://mywebsite/Vicks> <http://mywebsite/BrotherOf> <http://mywebsite/Dips>
    <http://mywebsite/Vicks> <http://mywebsite/hasFather> <http://mywebsite/Joe>

    You need a user rule like this:

    If ( ?x hasFather ?y ) ( ?x BrotherOf ?z)
    Then (?z hasFather ?y)

    Regards!
    Jorge
  • 2. Re: Inference Sparql
    alwu Pro
    Currently Being Moderated
    Hi,

    In addition to the user defined rule approach Jorge mentioned, one can also use OWL 2 property chain.
    An example can be found in Section 3.2.2 of the following document. Note that you also need to
    declare brotherOf as an inverse of hasBrother.

    http://docs.oracle.com/cd/E11882_01/appdev.112/e11828/skos.htm#BACDHJBI

    Thanks,

    Zhe Wu

    Edited by: alwu on Dec 1, 2011 8:12 AM
  • 3. Re: Inference Sparql
    880207 Newbie
    Currently Being Moderated
    Hi Jorge,

    I don't know how to add user defined rules. Is it similar to adding triples ?
    I have in my DB below 2 data rows :-

    <http://mywebsite/Vicks> <http://mywebsite/BrotherOf> <http://mywebsite/Dips>
    <http://mywebsite/Vicks> <http://mywebsite/hasFather> <http://mywebsite/Joe>

    What more should I add to get below infered data :
    <http://mywebsite/Dips> <http://mywebsite/hasFather> <http://mywebsite/Joe>

    Thanks,
    Manish H
  • 4. Re: Inference Sparql
    880207 Newbie
    Currently Being Moderated
    Hi Zhe,

    I went through the document link you shared, but i am not sure how to add property chain to below data:

    <http://mywebsite/Vicks> <http://mywebsite/BrotherOf> <http://mywebsite/Dips>
    <http://mywebsite/Vicks> <http://mywebsite/hasFather> <http://mywebsite/Joe>

    Also, if in future the data becomes something like below:

    <http://mywebsite/Vicks> <http://mywebsite/BrotherOf> <http://mywebsite/Dips>
    <http://mywebsite/Vicks> <http://mywebsite/BrotherOf> <http://mywebsite/Mike>
    <http://mywebsite/Vicks> <http://mywebsite/hasFather> <http://mywebsite/Joe>

    Do we need to update the property chain? Not sure how to write it. Any help on this would be of great help. Also would like to know more on user defined rules addition.


    Thanks,
    Manish H
  • 5. Re: Inference Sparql
    JorgeB-Oracle Journeyer
    Currently Being Moderated
    Hi Manish,

    Using the user rulebase

    execute SEM_APIS.drop_sem_model('family');
    drop table family_rdf_data;

    CREATE TABLE family_rdf_data (id NUMBER, triple SDO_RDF_TRIPLE_S);
    -- Create the model.
    execute SEM_APIS.create_sem_model('family', 'family_rdf_data', 'triple');


    INSERT INTO family_rdf_data VALUES (1,
    SDO_RDF_TRIPLE_S('family',
    '<http://mywebsite/Vicks>',
    '<http://mywebsite/BrotherOf>',
    '<http://mywebsite/Dips>'));

    INSERT INTO family_rdf_data VALUES (2,
    SDO_RDF_TRIPLE_S('family',
    '<http://mywebsite/Vicks>',
    '<http://mywebsite/hasFather>',
    '<http://mywebsite/Joe>'));

    commit;

    set pagesize 900
    column s format a24
    column p format a30
    column o format a24
    SELECT s,p,o
    FROM TABLE(SEM_MATCH(
    '(?s ?p ?o)',
    SEM_Models('family'),
    null,
    SEM_ALIASES(SEM_ALIAS('','http://mywebsite/')),
    null));

    S P O

    http://mywebsite/Vicks http://mywebsite/BrotherOf http://mywebsite/Dips
    http://mywebsite/Vicks http://mywebsite/hasFather http://mywebsite/Joe

    -- Create user rulebase
    /*
    If ( ?x hasFather ?y ) ( ?x BrotherOf ?z)
    Then (?z hasFather ?y)
    */

    EXECUTE SEM_APIS.CREATE_RULEBASE('family_rb');

    INSERT INTO mdsys.semr_family_rb VALUES(
    'father_rule',
    '(?x :hasFather ?y) (?x :BrotherOf ?z)',
    NULL,
    '(?z :hasFather ?y)',
    SEM_ALIASES(SEM_ALIAS('','http://mywebsite/')));

    COMMIT;

    BEGIN
    SEM_APIS.CREATE_ENTAILMENT(
    'rdfs_rix_family',
    SEM_Models('family'),
    SEM_Rulebases('family_rb'),
    SEM_APIS.REACH_CLOSURE, null, 'USER_RULES=T');
    END;
    /

    SELECT s,p,o
    FROM TABLE(SEM_MATCH(
    '(?s ?p ?o)',
    SEM_Models('family'),
    SEM_Rulebases('family_rb'),
    SEM_ALIASES(SEM_ALIAS('','http://mywebsite/')),
    null));

    S P O

    http://mywebsite/Vicks http://mywebsite/BrotherOf http://mywebsite/Dips
    http://mywebsite/Vicks http://mywebsite/hasFather http://mywebsite/Joe
    http://mywebsite/Dips http://mywebsite/hasFather http://mywebsite/Joe

    Regards!
    Jorge

    Edited by: jbarba on Dec 1, 2011 1:04 PM
  • 6. Re: Inference Sparql
    880207 Newbie
    Currently Being Moderated
    Thanks Jorge. The code you shared solved my query.
    Regards,
    Manish H
  • 7. Re: Inference Sparql
    JorgeB-Oracle Journeyer
    Currently Being Moderated
    Hi Manish,

    The OWL2RL with the inverse of hasBrother is another alternative separate from the User Rulebase

    The advantage of this alternative is that you can have incremental inference which you cannot have with User rulebases.

    Using what Zhe described OWL2RL chain property with the inverse of BrotherOf, this is what you should do:

    EXECUTE SEM_APIS.DROP_ENTAILMENT('rdfs_rix_family');
    EXECUTE SEM_APIS.DROP_RULEBASE('family_rb');
    execute SEM_APIS.drop_sem_model('family');
    drop table family_rdf_data;


    CREATE TABLE family_rdf_data (triple SDO_RDF_TRIPLE_S);
    -- Create the model.
    execute SEM_APIS.create_sem_model('family', 'family_rdf_data', 'triple');


    INSERT INTO family_rdf_data VALUES (
    SDO_RDF_TRIPLE_S('family',
    '<http://mywebsite/Vicks>',
    '<http://mywebsite/BrotherOf>',
    '<http://mywebsite/Dips>'));

    INSERT INTO family_rdf_data VALUES (
    SDO_RDF_TRIPLE_S('family',
    '<http://mywebsite/Vicks>',
    '<http://mywebsite/hasFather>',
    '<http://mywebsite/Joe>'));

    commit;

    set pagesize 900
    column s format a24
    column p format a30
    column o format a24
    SELECT s,p,o
    FROM TABLE(SEM_MATCH(
    '(?s ?p ?o)',
    SEM_Models('family'),
    null,
    SEM_ALIASES(SEM_ALIAS('','http://mywebsite/')),
    null));

    S P O
    ------------------------ ------------------------------ ------------------------
    http://mywebsite/Vicks http://mywebsite/BrotherOf http://mywebsite/Dips
    http://mywebsite/Vicks http://mywebsite/hasFather http://mywebsite/Joe


    -- Define BrotherOf as inverse of hasBrother

    INSERT INTO family_rdf_data VALUES(sdo_rdf_triple_s('family','<http://mywebsite/hasBrother>','<http://www.w3.org/2002/07/owl#inverseOf>','<http://mywebsite/BrotherOf>'));

    -- Define the chain:

    INSERT INTO family_rdf_data VALUES(sdo_rdf_triple_s('family','<http://mywebsite/hasFather>', '<http://www.w3.org/2002/07/owl#propertyChainAxiom>', '_:jA1'));
    INSERT INTO family_rdf_data VALUES(sdo_rdf_triple_s('family','_:jA1', '<http://www.w3.org/1999/02/22-rdf-syntax-ns#first>', '<http://mywebsite/hasBrother>'));
    INSERT INTO family_rdf_data VALUES(sdo_rdf_triple_s('family','_:jA1', '<http://www.w3.org/1999/02/22-rdf-syntax-ns#rest>', '_:jA2'));
    INSERT INTO family_rdf_data VALUES(sdo_rdf_triple_s('family','_:jA2', '<http://www.w3.org/1999/02/22-rdf-syntax-ns#first>', '<http://mywebsite/hasFather>'));
    INSERT INTO family_rdf_data VALUES(sdo_rdf_triple_s('family','_:jA2', '<http://www.w3.org/1999/02/22-rdf-syntax-ns#rest>', '<http://www.w3.org/1999/02/22-rdf-syntax-ns#nil>'));
    commit;

    BEGIN
    SEM_APIS.CREATE_ENTAILMENT(
    'owl2rl_family',
    SEM_Models('family'),
    SEM_Rulebases('OWL2RL'));
    END;
    /

    clear column
    SELECT s,p,o
    FROM TABLE(SEM_MATCH(
    '(?s ?p ?o)',
    SEM_Models('family'),
    SEM_Rulebases('OWL2RL'),
    SEM_ALIASES(SEM_ALIAS('','http://mywebsite/')),
    null));

    http://mywebsite/Vicks
    http://mywebsite/BrotherOf
    http://mywebsite/Dips

    http://mywebsite/Vicks
    http://mywebsite/hasFather
    http://mywebsite/Joe

    http://mywebsite/hasBrother
    http://www.w3.org/2002/07/owl#inverseOf
    http://mywebsite/BrotherOf

    http://mywebsite/hasFather
    http://www.w3.org/2002/07/owl#propertyChainAxiom
    _:m33mjA1

    _:m33mjA1
    http://www.w3.org/1999/02/22-rdf-syntax-ns#first
    http://mywebsite/hasBrother

    _:m33mjA1
    http://www.w3.org/1999/02/22-rdf-syntax-ns#rest
    _:m33mjA2

    _:m33mjA2
    http://www.w3.org/1999/02/22-rdf-syntax-ns#first
    http://mywebsite/hasFather

    _:m33mjA2
    http://www.w3.org/1999/02/22-rdf-syntax-ns#rest
    http://www.w3.org/1999/02/22-rdf-syntax-ns#nil

    http://mywebsite/BrotherOf
    http://www.w3.org/2002/07/owl#inverseOf
    http://mywebsite/hasBrother

    http://mywebsite/Dips
    http://mywebsite/hasBrother
    http://mywebsite/Vicks

    http://mywebsite/Dips
    http://mywebsite/hasFather
    http://mywebsite/Joe


    11 rows selected.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points