120 likes | 372 Views
Figure 1–3 Family Tree for RDF Example (see Monday October, 10 link - Oracle Semantic Tutorial examples on 1-28 and 1-29 ). select Person from person where BrotherOf = ‘Cathy’ . select x from rts where ?x BrotherOf ‘Cathy’ . Figure 1–3 Family Tree for RDF Sample
E N D
Figure 1–3 Family Tree for RDF Example (see Monday October, 10 link - Oracle Semantic Tutorial examples on 1-28 and 1-29)
select Person from person where BrotherOf = ‘Cathy’ select x from rts where ?x BrotherOf ‘Cathy’
Figure 1–3 Family Tree for RDF Sample (see Monday October, 10 link - Family Tree RDF Examplefor Full Details) -- 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_cs345_XXX', 'family_rdf_data', 'triple'); -- John is the father of Suzie. INSERT INTO family_rdf_data VALUES (1, SDO_RDF_TRIPLE_S('family_cs345_XXX', 'http://www.example.org/family/John', 'http://www.example.org/family/fatherOf', 'http://www.example.org/family/Suzie')); . . . INSERT INTO family_rdf_data VALUES (14, SDO_RDF_TRIPLE_S('family_cs345_XXX', 'http://www.example.org/family/Jack', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'http://www.example.org/family/Male'));
-- Person is a class. INSERT INTO family_rdf_data VALUES (17, SDO_RDF_TRIPLE_S('family_cs345_XXX', 'http://www.example.org/family/Person', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'http://www.w3.org/2000/01/rdf-schema#Class')); -- Male is a subclass of Person. INSERT INTO family_rdf_data VALUES (18, SDO_RDF_TRIPLE_S('family_cs345_XXX', 'http://www.example.org/family/Male', 'http://www.w3.org/2000/01/rdf-schema#subClassOf', 'http://www.example.org/family/Person')); -- Female is a subclass of Person. INSERT INTO family_rdf_data VALUES (19, SDO_RDF_TRIPLE_S('family_cs345_XXX', 'http://www.example.org/family/Female', 'http://www.w3.org/2000/01/rdf-schema#subClassOf', 'http://www.example.org/family/Person')); -- siblingOf is a property. INSERT INTO family_rdf_data VALUES (20, SDO_RDF_TRIPLE_S('family_cs345_XXX', 'http://www.example.org/family/siblingOf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#Property')); -- parentOf is a property. INSERT INTO family_rdf_data VALUES (21, SDO_RDF_TRIPLE_S('family_cs345_XXX', 'http://www.example.org/family/parentOf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#Property')); -- brotherOf is a subproperty of siblingOf. INSERT INTO family_rdf_data VALUES (22, SDO_RDF_TRIPLE_S('family_cs345_XXX', 'http://www.example.org/family/brotherOf', 'http://www.w3.org/2000/01/rdf-schema#subPropertyOf', 'http://www.example.org/family/siblingOf')); -- sisterOf is a subproperty of siblingOf. INSERT INTO family_rdf_data VALUES (23, SDO_RDF_TRIPLE_S('family_cs345_XXX', 'http://www.example.org/family/sisterOf', 'http://www.w3.org/2000/01/rdf-schema#subPropertyOf', 'http://www.example.org/family/siblingOf')); -- A brother is male. INSERT INTO family_rdf_data VALUES (24, SDO_RDF_TRIPLE_S('family_cs345_XXX', 'http://www.example.org/family/brotherOf', 'http://www.w3.org/2000/01/rdf-schema#domain', 'http://www.example.org/family/Male')); -- A sister is female. INSERT INTO family_rdf_data VALUES (25, SDO_RDF_TRIPLE_S('family_cs345_XXX', 'http://www.example.org/family/sisterOf', 'http://www.w3.org/2000/01/rdf-schema#domain', 'http://www.example.org/family/Female')); -- fatherOf is a subproperty of parentOf. INSERT INTO family_rdf_data VALUES (26, SDO_RDF_TRIPLE_S('family_cs345_XXX', 'http://www.example.org/family/fatherOf', 'http://www.w3.org/2000/01/rdf-schema#subPropertyOf', 'http://www.example.org/family/parentOf')); -- motherOf is a subproperty of parentOf. INSERT INTO family_rdf_data VALUES (27, SDO_RDF_TRIPLE_S('family_cs345_XXX', 'http://www.example.org/family/motherOf', 'http://www.w3.org/2000/01/rdf-schema#subPropertyOf', 'http://www.example.org/family/parentOf')); -- A father is male. INSERT INTO family_rdf_data VALUES (28, SDO_RDF_TRIPLE_S('family_cs345_XXX', 'http://www.example.org/family/fatherOf', 'http://www.w3.org/2000/01/rdf-schema#domain', 'http://www.example.org/family/Male')); -- A mother is female. INSERT INTO family_rdf_data VALUES (29, SDO_RDF_TRIPLE_S('family_cs345_XXX', 'http://www.example.org/family/motherOf', 'http://www.w3.org/2000/01/rdf-schema#domain', 'http://www.example.org/family/Female'));
RDF Inferencing -- RDFS inferencing in the family model BEGIN SEM_APIS.CREATE_RULES_INDEX( 'rdfs_rix_family_cs345_XXX', SEM_Models('family_cs345_XXX'), 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_cs345_XXX'), 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_cs345_XXX'), SDO_RDF_Rulebases('RDFS'), SEM_ALIASES(SEM_ALIAS('','http://www.example.org/family/')), null));
RDF Inferencing -- General inferencing in the family model EXECUTE SEM_APIS.CREATE_RULEBASE('family_rb_cs345_XXX'); INSERT INTO mdsys.semr_family_rb_cs345_XXX VALUES( 'grandparent_rule', '(?x :parentOf ?y) (?y :parentOf ?z)', NULL, '(?x :grandParentOf ?z)', SEM_ALIASES(SEM_ALIAS('','http://www.example.org/family/'))); COMMIT; -- 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_cs345_XXX'), 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_cs345_XXX'), SEM_Rulebases('RDFS','family_rb_cs345_XXX'), SEM_ALIASES(SEM_ALIAS('','http://www.example.org/family/')), null))
Get an Oracle Account (One per Project Group, You Can Share It) import java.sql.Connection; import java.sql.Statement; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.*; public class MainClass { public static Connection getConnection() throws ClassNotFoundException, SQLException { String driver = "oracle.jdbc.driver.OracleDriver"; String url = "jdbc:oracle:thin:@rising-sun.microlab.cs.utexas.edu:1521:orcl"; String username = "________________________"; String password = "________________________"; Class.forName(driver); Connection conn = DriverManager.getConnection(url, username, password); return conn; } public static void main(String args[]) { Connection conn = null; Statement stmt = null; CallableStatement callStmt = null; try { conn = getConnection(); stmt = conn.createStatement(); // Uncomment the following line if the family_rdf_data table already exists AND IF you want to drop the table and start over. // stmt.executeUpdate("DROP TABLE family_rdf_data"); stmt.executeUpdate("CREATE TABLE family_rdf_data (id NUMBER, triple SDO_RDF_TRIPLE_S)"); System.out.println("Created RDF Table"); // The following commented out lines don't appear to be necessary even though they are in the tutorial. // callStmt = conn.prepareCall(" begin SEM_APIS.drop_rdf_model('family'); end;"); // callStmt.execute(); // callStmt = conn.prepareCall(" begin SEM_APIS.create_rdf_model('family', 'family_rdf_data', 'triple'); end;"); // callStmt.execute(); // System.out.println("Create RDF Model"); stmt.executeUpdate("INSERT INTO family_rdf_data VALUES (1,SDO_RDF_TRIPLE_S('family','http://www.example.org/family/John','http://www.example.org/family/fatherOf','http://www.example.org/family/Suzie'))"); System.out.println("Inserted"); } catch (ClassNotFoundException e) { System.out.println("error: failed to load Oracle driver."); e.printStackTrace(); } catch (SQLException e) { System.out.println("error: failed to create a connection object."); e.printStackTrace(); } catch (Exception e) { System.out.println("other error:"); e.printStackTrace(); } finally { try { stmt.close(); conn.close(); } catch (Exception e) { } } } }