-- Basic steps: -- After you have connected as a privileged user and called -- SEM_APIS.CREATE_SEM_NETWORK to enable RDF support, -- connect as a regular database user and do the following. -- 1. For each desired model, create a table to hold its data. -- 2. For each model, create a model (SEM_APIS.CREATE_RDF_MODEL). -- 3. For each table to hold semantic data, insert data into the table. -- 4. Use various subprograms and constructors. connect rdfuser/rdfuser -- Create the table to hold data for the model. CREATE TABLE family_rdf_data (id NUMBER, triple SDO_RDF_TRIPLE_S); -- Create the model. execute SEM_APIS.create_rdf_model('family', 'family_rdf_data', 'triple'); select * from mdsys.rdf_model$; -- Insert rows into the table. These express the following information: ----------------- -- John and Janice have two children, Suzie and Matt. -- Matt married Martha, and they have two children: -- Tom (male, height 5.75) and Cindy (female, height 06.00). -- Suzie married Sammy, and they have two children: -- Cathy (height 5.8) and Jack (male, height 6). -- Person is a class that has two subslasses: Male and Female. -- parentOf is a property that has two subproperties: fatherOf and motherOf. -- siblingOf is a property that has two subproperties: brotherOf and sisterOf. -- The domain of the fatherOf and brotherOf properties is Male. -- The domain of the motherOf and sisterOf properties is Female. ------------------------ -- John is the father of Suzie. INSERT INTO family_rdf_data VALUES (1, SDO_RDF_TRIPLE_S('family', '', '', '')); commit; -- John is the father of Matt. INSERT INTO family_rdf_data VALUES (2, SDO_RDF_TRIPLE_S('family', '', '', '')); commit; -- Janice is the mother of Suzie. INSERT INTO family_rdf_data VALUES (3, SDO_RDF_TRIPLE_S('family', '', '', '')); -- Janice is the mother of Matt. INSERT INTO family_rdf_data VALUES (4, SDO_RDF_TRIPLE_S('family', '', '', '')); -- Sammy is the father of Cathy. INSERT INTO family_rdf_data VALUES (5, SDO_RDF_TRIPLE_S('family', '', '', '')); -- Sammy is the father of Jack. INSERT INTO family_rdf_data VALUES (6, SDO_RDF_TRIPLE_S('family', '', '', '')); -- Suzie is the mother of Cathy. INSERT INTO family_rdf_data VALUES (7, SDO_RDF_TRIPLE_S('family', '', '', '')); -- Suzie is the mother of Jack. INSERT INTO family_rdf_data VALUES (8, SDO_RDF_TRIPLE_S('family', '', '', '')); -- Matt is the father of Tom. INSERT INTO family_rdf_data VALUES (9, SDO_RDF_TRIPLE_S('family', '', '', '')); -- Matt is the father of Cindy INSERT INTO family_rdf_data VALUES (10, SDO_RDF_TRIPLE_S('family', '', '', '')); -- Martha is the mother of Tom. INSERT INTO family_rdf_data VALUES (11, SDO_RDF_TRIPLE_S('family', '', '', '')); -- Martha is the mother of Cindy. INSERT INTO family_rdf_data VALUES (12, SDO_RDF_TRIPLE_S('family', '', '', '')); -- Cathy is the sister of Jack. INSERT INTO family_rdf_data VALUES (13, SDO_RDF_TRIPLE_S('family', '', '', '')); -- Jack is male. INSERT INTO family_rdf_data VALUES (14, SDO_RDF_TRIPLE_S('family', '', '', '')); -- Tom is male. INSERT INTO family_rdf_data VALUES (15, SDO_RDF_TRIPLE_S('family', '', '', '')); -- Cindy is female. INSERT INTO family_rdf_data VALUES (16, SDO_RDF_TRIPLE_S('family', '', '', '')); commit; -- ===================== schema ================================== -- Person is a class. INSERT INTO family_rdf_data VALUES (17, SDO_RDF_TRIPLE_S('family', '', '', '')); -- Male is a subclass of Person. INSERT INTO family_rdf_data VALUES (18, SDO_RDF_TRIPLE_S('family', '', '', '')); -- Female is a subclass of Person. INSERT INTO family_rdf_data VALUES (19, SDO_RDF_TRIPLE_S('family', '', '', '')); -- siblingOf is a property. INSERT INTO family_rdf_data VALUES (20, SDO_RDF_TRIPLE_S('family', '', '', '')); -- parentOf is a property. INSERT INTO family_rdf_data VALUES (21, SDO_RDF_TRIPLE_S('family', '', '', '')); -- brotherOf is a subproperty of siblingOf. INSERT INTO family_rdf_data VALUES (22, SDO_RDF_TRIPLE_S('family', '', '', '')); -- sisterOf is a subproperty of siblingOf. INSERT INTO family_rdf_data VALUES (23, SDO_RDF_TRIPLE_S('family', '', '', '')); -- A brother is male. INSERT INTO family_rdf_data VALUES (24, SDO_RDF_TRIPLE_S('family', '', '', '')); -- A sister is female. INSERT INTO family_rdf_data VALUES (25, SDO_RDF_TRIPLE_S('family', '', '', '')); -- fatherOf is a subproperty of parentOf. INSERT INTO family_rdf_data VALUES (26, SDO_RDF_TRIPLE_S('family', '', '', '')); -- motherOf is a subproperty of parentOf. INSERT INTO family_rdf_data VALUES (27, SDO_RDF_TRIPLE_S('family', '', '', '')); -- A father is male. INSERT INTO family_rdf_data VALUES (28, SDO_RDF_TRIPLE_S('family', '', '', '')); -- A mother is female. INSERT INTO family_rdf_data VALUES (29, SDO_RDF_TRIPLE_S('family', '', '', '')); commit; -- Use SET ESCAPE OFF to prevent the caret (^) from being -- interpreted as an escape character. Two carets (^^) are -- used to represent typed literals. SET ESCAPE OFF; -- Cathy's height is 5.8 (decimal). INSERT INTO family_rdf_data VALUES (30, SDO_RDF_TRIPLE_S('family', '', '', '"5.8"^^xsd:decimal')); -- Jack's height is 6 (integer). INSERT INTO family_rdf_data VALUES (31, SDO_RDF_TRIPLE_S('family', '', '', '"6"^^xsd:integer')); -- Tom's height is 05.75 (decimal). INSERT INTO family_rdf_data VALUES (32, SDO_RDF_TRIPLE_S('family', '', '', '"05.75"^^xsd:decimal')); -- Cindy's height is 06.00 (decimal). INSERT INTO family_rdf_data VALUES (33, SDO_RDF_TRIPLE_S('family', '', '', '"06.00"^^xsd:decimal')); COMMIT; -- RDFS inferencing in the family model BEGIN SEM_APIS.CREATE_ENTAILMENT( 'rdfs_rix_family', SEM_Models('family'), SEM_Rulebases('RDFS')); END; / -- Select all males from the family model, without inferencing. SELECT m FROM TABLE(SEM_MATCH( '(?m rdf:type :Male)', SEM_Models('family'), null, SEM_ALIASES(SEM_ALIAS('','http://www.example.org/family/')), null)); -- Select all males from the family model, with RDFS inferencing. SELECT m FROM TABLE(SEM_MATCH( '(?m rdf:type :Male)', SEM_Models('family'), SDO_RDF_Rulebases('RDFS'), SEM_ALIASES(SEM_ALIAS('','http://www.example.org/family/')), null)); -- General inferencing in the family model EXECUTE SEM_APIS.CREATE_RULEBASE('family_rb'); INSERT INTO mdsys.semr_family_rb VALUES( 'grandparent_rule', '(?x :parentOf ?y) (?y :parentOf ?z)', NULL, '(?x :grandParentOf ?z)', SEM_ALIASES(SEM_ALIAS('','http://www.example.org/family/'))); COMMIT; -- Because a new rulebase has been created, and it will be used in the -- entailment, drop the preceding entailment and then re-create it. EXECUTE SEM_APIS.DROP_ENTAILMENT ('rdfs_rix_family'); -- Re-create the entailment. BEGIN SEM_APIS.CREATE_ENTAILMENT( 'rdfs_rix_family', SEM_Models('family'), SEM_Rulebases('RDFS','family_rb')); END; / -- Select all grandfathers and their grandchildren from the family model, -- without inferencing. (With no inferencing, no results are returned.) SELECT x grandfather, y grandchild FROM TABLE(SEM_MATCH( '(?x :grandParentOf ?y) (?x rdf:type :Male)', SEM_Models('family'), null, SEM_ALIASES(SEM_ALIAS('','http://www.example.org/family/')), null)); -- Select all grandfathers and their grandchildren from the family model. -- Use inferencing from both the RDFS and family_rb rulebases. SELECT x grandfather, y grandchild FROM TABLE(SEM_MATCH( '(?x :grandParentOf ?y) (?x rdf:type :Male)', SEM_Models('family'), SEM_Rulebases('RDFS','family_rb'), SEM_ALIASES(SEM_ALIAS('','http://www.example.org/family/')), null)); -- Set up to find grandfathers of tall (>= 6) grandchildren -- from the family model, with RDFS inferencing and -- inferencing using the "family_rb" rulebase. UPDATE mdsys.semr_family_rb SET antecedents = '(?x :parentOf ?y) (?y :parentOf ?z) (?z :height ?h)', filter = '(h >= 6)', aliases = SEM_ALIASES(SEM_ALIAS('','http://www.example.org/family/')) WHERE rule_name = 'GRANDPARENT_RULE'; -- Because the rulebase has been updated, drop the preceding entailment, -- and then re-create it. EXECUTE SEM_APIS.DROP_ENTAILMENT ('rdfs_rix_family'); -- Re-create the entailment. BEGIN SEM_APIS.CREATE_ENTAILMENT( 'rdfs_rix_family', SEM_Models('family'), SEM_Rulebases('RDFS','family_rb')); END; / -- Find the entailment that was just created (that is, the -- one based on the specified model and rulebases). SELECT SEM_APIS.LOOKUP_ENTAILMENT(SEM_MODELS('family'), SEM_RULEBASES('RDFS','family_rb')) AS lookup_entailment FROM DUAL; -- Select grandfathers of tall (>= 6) grandchildren, and their -- tall grandchildren. SELECT x grandfather, y grandchild FROM TABLE(SEM_MATCH( '(?x :grandParentOf ?y) (?x rdf:type :Male)', SEM_Models('family'), SEM_RuleBases('RDFS','family_rb'), SEM_ALIASES(SEM_ALIAS('','http://www.example.org/family/')), null)); -- -- add some OWL property restrictions -- -- potato is a Vegetable INSERT INTO family_rdf_data VALUES (101, SDO_RDF_TRIPLE_S('family', '', 'rdf:type', '')); -- restriction onProperty eat: allValuesFrom Vegetable INSERT INTO family_rdf_data VALUES (102, SDO_RDF_TRIPLE_S('family', '_:avfRestriction', 'rdf:type', 'owl:Restriction')); INSERT INTO family_rdf_data VALUES (103, SDO_RDF_TRIPLE_S('family', '_:avfRestriction', 'owl:onProperty', '')); INSERT INTO family_rdf_data VALUES (104, SDO_RDF_TRIPLE_S('family', '_:avfRestriction', 'owl:allValuesFrom', '')); INSERT INTO family_rdf_data VALUES (105, SDO_RDF_TRIPLE_S('family', '', 'rdfs:subClassOf', '_:avfRestriction')); -- add data showing John eats Vegetable INSERT INTO family_rdf_data VALUES (51, SDO_RDF_TRIPLE_S('family', '', '', '')); commit; -- -- RDFS inference: re-create the entailment, but only with RDFS and some exclusions (see Sec. 2.2.6) -- EXECUTE SEM_APIS.DROP_ENTAILMENT ('rdfs_rix_family'); BEGIN SEM_APIS.CREATE_ENTAILMENT( 'rdfs_rix_family', SEM_Models('family'), SEM_Rulebases('RDFS') ,0,'RDFS4A-, RDFS4B-, RDFS6-, RDFS8-,RDFS10-, RDFS13-','ENTAIL_ANYWAY=T, DISTANCE=T, USER_RULES=F'); END; / -- OWLPrime inference BEGIN SEM_APIS.CREATE_ENTAILMENT( 'owlprime_rix_family', SEM_Models('family'), SEM_Rulebases('owlprime')); END; / -- Owl2rl inference BEGIN SEM_APIS.CREATE_ENTAILMENT( 'owl2rl_rix_family', SEM_Models('family'), SEM_Rulebases('owl2rl')); END; / -- query to see how :John has been classified SELECT y FROM TABLE(SEM_MATCH( '(:John rdf:type ?y)', SEM_Models('family'), SEM_RuleBases('rdfs'), SEM_ALIASES(SEM_ALIAS('','http://www.example.org/family/')), null)); SELECT y FROM TABLE(SEM_MATCH( '(:John rdf:type ?y)', SEM_Models('family'), SEM_RuleBases('owlprime'), SEM_ALIASES(SEM_ALIAS('','http://www.example.org/family/')), null)); SELECT y FROM TABLE(SEM_MATCH( '(:John rdf:type ?y)', SEM_Models('family'), SEM_RuleBases('owl2rl'), SEM_ALIASES(SEM_ALIAS('','http://www.example.org/family/')), null)); -- explicitly identify :John as :Vegetarian and then add a food item that :John eats INSERT INTO family_rdf_data VALUES (51, SDO_RDF_TRIPLE_S('family', '', 'rdf:type', '')); -- add data showing John eats some unknown category food INSERT INTO family_rdf_data VALUES (52, SDO_RDF_TRIPLE_S('family', '', '', '')); -- do entailments -- -- RDFS inference: re-create the entailment, but only with RDFS and some exclusions (see Sec. 2.2.6) -- BEGIN SEM_APIS.CREATE_ENTAILMENT( 'rdfs_rix_family', SEM_Models('family'), SEM_Rulebases('RDFS') ,0,'RDFS4A-, RDFS4B-, RDFS6-, RDFS8-,RDFS10-, RDFS13-','ENTAIL_ANYWAY=T, DISTANCE=T, USER_RULES=F'); END; / -- OWLPrime inference BEGIN SEM_APIS.CREATE_ENTAILMENT( 'owlprime_rix_family', SEM_Models('family'), SEM_Rulebases('owlprime') ,options => 'ENTAIL_ANYWAY=T'); END; / -- Owl2rl inference BEGIN SEM_APIS.CREATE_ENTAILMENT( 'owl2rl_rix_family', SEM_Models('family'), SEM_Rulebases('owl2rl') ,options => 'ENTAIL_ANYWAY=T'); END; / -- query to see how :bean has been classified SELECT y FROM TABLE(SEM_MATCH( '(:bean rdf:type ?y)', SEM_Models('family'), SEM_RuleBases('rdfs'), SEM_ALIASES(SEM_ALIAS('','http://www.example.org/food/item/')), null)); SELECT y FROM TABLE(SEM_MATCH( '(:bean rdf:type ?y)', SEM_Models('family'), SEM_RuleBases('owlprime'), SEM_ALIASES(SEM_ALIAS('','http://www.example.org/food/item/')), null)); SELECT y FROM TABLE(SEM_MATCH( '(:bean rdf:type ?y)', SEM_Models('family'), SEM_RuleBases('owl2rl'), SEM_ALIASES(SEM_ALIAS('','http://www.example.org/food/item/')), null)); -- -- cleanup the model (and entailment) and the application table -- exec sem_apis.drop_sem_model('family'); drop table family_rdf_data; exec sem_apis.drop_rulebase('family_rb');