Mais conteúdo relacionado Semelhante a Build Knowledge Graphs with Oracle RDF to Extract More Value from Your Data (20) Build Knowledge Graphs with Oracle RDF to Extract More Value from Your Data1. Analytics and Data Summit 2019
Build Knowledge Graphs with Oracle RDF to Extract More
Value from Your Data
Souri Das Matthew Perry Melliyal Annamalai
Oracle Spatial and Graph
Spatial and Graph Summit @
2. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Safe Harbor Statement
The following is intended to outline our general product direction. It is intended for
information purposes only, and may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or functionality, and should not be relied upon
in making purchasing decisions. The development, release, timing, and pricing of any
features or functionality described for Oracle’s products may change and remains at the
sole discretion of Oracle Corporation.
Confidential – Oracle Internal/Restricted/Highly Restricted 2
3. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Agenda
3
Definition and Use Cases for Knowledge Graphs
Modeling Knowledge Graphs using W3C RDF
Using Oracle RDF Knowledge Graph
Performing Analytics with RDF Knowledge Graph Data
1
2
3
4
4. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Agenda
4
Definition and Use Cases for Knowledge Graphs
Modeling Knowledge Graphs using W3C RDF
Using Oracle RDF Knowledge Graph
Performing Analytics with RDF Knowledge Graph Data
1
2
3
4
5. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
What is a Knowledge Graph?
• Knowledge graphs are large networks of entities, their semantic types,
properties, and relationships between entities1.
• Key Features:
– Things not strings
• global unique identifiers
– Formal structure/semantics
• machine processable, unambiguous
– Linked descriptions
• resources are described by their connections
1. M. Kroetsch and G. Weikum. Journal of Web Semantics: Special Issue on Knowledge Graphs.
http://www.websemanticsjournal.org/index.php/ps/announcement/view/19 [August, 2016]
Database
Knowledge
Base
Graph
Knowledge
Graph
6. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Knowledge Graph Examples1
1. Heiko Paulheim. Journal of Web Semantics: Special Issue on Knowledge Graph Refinement. Preprint.
“Knowledge Graph Refinement: A Survey of Approaches and Evaluation Methods.” [September, 2016]
7. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Use Case: Linked Data Publishing
• Publishing data in a standard way
so that it can be more easily
consumed
• Popular way for government
agencies to publish public data
• Why RDF?
– URIs
– Flexible data model
– Standard vocabularies
– Standard protocols
Italy
National Institute of Statistics
Japan
National Statistics Center
8. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Use Case: Linked Data Publishing
• Publishing data in a standard way
so that it can be more easily
consumed
• Popular way for government
agencies to publish public data
• Why RDF?
– URIs
– Flexible data model
– Standard vocabularies
– Standard protocols
https://lod-cloud.net/ 1,200+ linked datasets
9. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Business Challenge
• Link database information on genes,
proteins, metabolic pathways, compounds,
ligands, etc. to original sources.
• Increase productivity for accessing, sharing,
searching, navigating, cross-linking,
analyzing internal /external data
Solution
• Semantic integration layer on RDF graph
• Rich domain-specific terminology (biology,
chemistry and medicine) 1.6 M terms
• Terminology Hub: 8 GB of referential data
that cross-references between data
repositories.
Use Case: Semantic Data Integration
Novartis Institutes for BioMedical Research (NIBR)
10. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Use Case: Smart Engineering/Construction
PDF
PDF
PDF
PDF
Build
Order
Engineering
Standards
Government
Regulations
Product
Specifications
Requirements and Specifications
Ontology
Manual assessment by
discipline-specific
engineers
Automated reasoning
and queries
Example: bolt length
error rate 15% 0.5%
11. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Agenda
11
Definition and Use Cases for Knowledge Graphs
Modeling Knowledge Graphs using W3C RDF
Using Oracle RDF Knowledge Graph
Performing Analytics with RDF Knowledge Graph Data
1
2
3
4
12. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 12
W3C Standards for Knowledge Graphs
The World Wide Web
Consortium has defined a suite
of standards to support Linked
Data and Knowledge Graphs.
Fundamental Concepts are:
• URIs
• Links to other resources
• Standard Data Model (RDF)
• Standard Ontology Language
(OWL)
• Standard Query (SPARQL)
13. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
What is Resource Description Framework (RDF)
• An RDF graph is a directed, labeled
graph with some syntactic restrictions
– Vertex labels are URIs or scalar values
– Edge labels are URIs
– Source vertex for an edge must be a URI
• An edge is the atomic unit of an RDF
graph – called an RDF triple
univ:university1
univ:course456
univ:professorXYZ
univ:student123
univ:employedBy
univ:offers
univ:takes
univ:teaches
"John"
univ:name
"Susan"
univ:name
univ:university1 "MIT"
univ:name
Subject Predicate Object
RDF Triple
@prefix univ: <http://univ.org#>
univ:student123 == <http://univ.org#student123>
URI prefix and prefixed name
14. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
What is Resource Description Framework (RDF)
• Resources can belong to types or
Classes
• Distinguish between Classes and
Instances
– Classes:
• univ:Professor, univ:University
– Instances:
• univ:professorXYZ, univ:university1
univ:university1
univ:course456
univ:professorXYZ
univ:student123
univ:employedBy
univ:offers
univ:takes
univ:teaches
"John"
univ:name
"Susan"
univ:name
univ:Professor
univ:University
rdf:type
rdf:type
15. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Example: Creating an RDF Knowledge Graph
16. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Example: Creating an RDF KG for the University Domain
@prefix univ: <http://univ.org#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
# Person
univ:Person rdf:type owl:Class .
# Student
univ:Student
rdf:type owl:Class ;
rdfs:subClassOf univ:Person .
# Graduate Student
univ:GraduateStudent
rdf:type owl:Class ;
rdfs:subClassOf univ:Student .
# Professor
univ:Professor
rdf:type owl:Class ;
rdfs:subClassOf univ:Person .
RDF Serialization (Turtle Format)
Defining Classes (and relationships among classes)
Person
Student Professor
Graduate
Student
17. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Example: Creating an RDF KG for the University Domain
@prefix univ: <http://univ.org#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
# Course
univ:Course rdf:type owl:Class .
# Graduate Course
univ:GraduateCourse
rdf:type owl:Class ;
rdfs:subClassOf unv:Course .
# University
univ:University rdf:type owl:Class .
RDF Serialization (Turtle Format)
Defining Classes (and relationships among classes)
Person
Student Professor
Course
University
Graduate
Course
Graduate
Student
18. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Example: Creating an RDF KG for the University Domain
@prefix univ: <http://univ.org#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
# takes
univ:takes
rdf:type owl:ObjectProperty ;
rdfs:domain univ:Student ;
rdfs:range univ:Course .
# teaches
univ:teaches
rdf:type owl:ObjectProperty ;
rdfs:domain univ:Professor ;
rdfs:range univ:Course .
# offers
univ:offers
rdf:type owl:ObjectProperty ;
rdfs:domain univ:University ;
rdfs:range univ:Course .
RDF Serialization (Turtle Format)
Defining Properties
Person
Student Professor
Course
University
takes teaches
offers
Graduate
Course
Graduate
Student
19. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
@prefix univ: <http://univ.org#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
# Graduate Students are Students who take a Graduate Course
owl:GraduateStudent owl:equivalentClass
[ rdf:type owl:Restriction ;
owl:onProperty univ:takes ;
owl:someValuesFrom univ:GraduateCourse
] .
Example: Creating an RDF KG for the University Domain
RDF Serialization (Turtle Format)
Adding More Semantics
Person
Student Professor
Course
University
takes teaches
offers
Graduate
Course
Graduate
Student
takes
20. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Example: Creating an RDF KG for the University Domain
Person
Student Professor
@prefix univ: <http://univ.org#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
# Student 123 takes Graduate Course 456
univ:student123 univ:takes univ:course456 .
univ:course456 rdf:type univ:GraduateCourse .
# what can we infer?Course
University
takes teaches
offers
Graduate
Course
Graduate
Student
RDF Serialization (Turtle Format)
Creating Edges (at instance-level)
Student123
Course456
takes
21. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Example: Creating an RDF KG for the University Domain
Person
Student Professor
@prefix univ: <http://univ.org#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
# Student 123 takes Graduate Course 456
univ:student123 univ:takes univ:course456 .
univ:course456 rdf:type univ:GraduateCourse .
# what can we infer?
# domain of takes is Student
univ:student123 rdf:type univ:Student .
Course
University
takes teaches
offers
Graduate
Course
Graduate
Student
RDF Serialization (Turtle Format)
Inference (at instance-level)
Student123
Course456
takes
22. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Example: Creating an RDF KG for the University Domain
Person
Student Professor
@prefix univ: <http://univ.org#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
# Student 123 takes Graduate Course 456
univ:student123 univ:takes univ:course456 .
univ:course456 rdf:type univ:GraduateCourse .
# what can we infer?
# domain of takes is Student
univ:student123 rdf:type univ:Student .
# Student is a subclass of Person
univ:student123 rdf:type univ:Person .
Course
University
takes teaches
offers
Graduate
Course
Graduate
Student
RDF Serialization (Turtle Format)
Inference (at instance-level)
Student123
Course456
takes
23. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Example: Creating an RDF KG for the University Domain
Person
Student Professor
@prefix univ: <http://univ.org#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
# Student 123 takes Graduate Course 456
univ:student123 univ:takes univ:course456 .
univ:course456 rdf:type univ:GraduateCourse .
# what can we infer?
# domain of takes is Student
univ:student123 rdf:type univ:Student .
# Student is a subclass of Person
univ:student123 rdf:type univ:Person .
# student123 takes a Graduate Course
univ:student123 rdf:type univ:GraduateStudent .
Course
University
takes teaches
offers
Graduate
Course
Graduate
Student
RDF Serialization (Turtle Format)
Inference (at instance-level)
Student123
Course456
takes
24. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Example: Creating an RDF KG for the University Domain
Person
Student Professor
@prefix univ: <http://univ.org#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
# Student 123 takes Graduate Course 456
univ:student123 univ:takes univ:course456 .
univ:course456 rdf:type univ:GraduateCourse .
# what can we infer?
# domain of takes is Student
univ:student123 rdf:type univ:Student .
# Student is a subclass of Person
univ:student123 rdf:type univ:Person .
# student123 takes a Graduate Course
univ:student123 rdf:type univ:GraduateStudent .
# range of takes is Course and GraduateCourse subclass of Course
univ:course456 rdf:type univ:Course .
Course
University
takes teaches
offers
Graduate
Course
Graduate
Student
RDF Serialization (Turtle Format)
Inference (at instance-level)
Student123
Course456
takes
25. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Graphical Tools like Protégé Make Things Easier
26. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Agenda
26
Definition and Use Cases for Knowledge Graphs
Modeling Knowledge Graphs using W3C RDF
Using Oracle RDF Knowledge Graph
Performing Analytics with RDF Knowledge Graph Data
1
2
3
4
27. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Database Version and Options for
RDF Knowledge Graph
• On-premise
– Oracle Database Enterprise Edition with
Spatial & Graph and Partitioning options
• Oracle Database Cloud Services
– DBCS (OCI)
– Exadata Cloud Service
– ATP-Dedicated (planned)
27
https://blogs.oracle.com/oraclespatial has a 3-part series
on getting started with RDF on DBCS
“Using RDF Knowledge Graphs in the Oracle Public Cloud”
28. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 28
Oracle Spatial and Graph 18c – RDF Knowledge Graph Architecture
Generic Relational Schema
for Storing RDF Data
RDF Views of Relational Data
SPARQL-to-SQL
Query Translator
Forward-chaining
OWL Reasoner
RDF Bulk Loader SPARQL Update
Processor
SQL and PL/SQL API
Support for Apache Jena (Java API)
Protégé Plugin Fuseki Endpoint Cytoscape Plugin
SQL Developer
RDF Support
Enterprise Manager
and Other DB Tools
29. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Loading RDF Data
30. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Source for RDF data
• Formatted File
– RDF formatted files: N-Triple, N-Quad, Turtle, RDF/XML, Trig, JSON-LD, etc.
• SPARQL Update
– Incremental insert, add, copy, etc.
• (External) Tables/Views or SQL Query
– Any tabular rowsource + W3C RDB2RDF mapping
Formatted File or String, Tabular Rowsource
30
31. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
RDF Bulk Loader
31
Staging Table
Client DB Server
RDF Relational Schema
Parallel RDF Bulk Load
• Value Checking
• Canonicalization
• Duplicate Elimination
• Internal ID Generation
• Index Creation
Step 2
N-Triple N-Quad
N-Triple
N-Quad
Turtle
RDF/XML
Trig
JSON-LD
Others
External Table
Oracle
Protégé
Plugin
Jena Adapter
Java API
Step 1
Oracle
SQL*Loader
32. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Relational Data to RDF (W3C RDB2RDF)
• Direct Mapping
– Automatically generates a mapping based on an input relational schema.
– A Direct Mapping of Relational Data to RDF.
W3C Recommendation 27 September 2012
http://www.w3.org/TR/2012/REC-rdb-direct-mapping-20120927/
• R2RML (RDB to RDF Mapping Language)
– An RDF vocabulary for specifying customized relational data to RDF mapping.
– R2RML: RDB to RDF Mapping Language.
W3C Recommendation 27 September 2012.
http://www.w3.org/TR/2012/REC-r2rml-20120927/
Two types of mapping: Direct and R2RML
32
33. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Using Direct Mapping: Overall Flow
Direct Map
Author
RDB2RDF
Processor
SPARQL to SQL
Translator
List of Tables
and Views
R2RML map
& schema
33
RDF
Triplestore
Relational
Tables & Views
Query
Writer
SPARQL
QUERY
34. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Using R2RML: Overall Flow
R2RML Map
Author
RDB2RDF
Processor
SPARQL to SQL
Translator
R2RML
Mapping
R2RML map
& schema
34
RDF
Triplestore
Relational
Tables & Views
Query
Writer
SPARQL
QUERY
35. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
R2RML Schema (Classes and Relations)
Source: Das, Sundara, and Cyganiak.
R2RML: RDB to RDF Mapping Language. W3C Recommendation 27 September 2012.
http://www.w3.org/TR/2012/REC-r2rml-20120927/
36. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Example: Mapping EMP and DEPT Tables to RDF
7782 John DB 10
constraints
EMP
ENO ENAME EXPERTISE DNO
10 Sales NYC
DNO DNAME LOC
DEPT
pkey ref. pkey
x:Department
http://x.com/Dept#{DNO}
class
Subject
Predicate-object pairs
<http://x.com/Dept#10>
rdf:type x:Department ;
<../Dept/Deptno> 10 ;
<../Dept/DeptName> “Sales” ;
<../Dept/Location> “NYC” .
TriplesMap
DEPT
37. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Example: Mapping EMP and DEPT Tables to RDF
7782 John DB 10
constraints
EMP
ENO ENAME EXPERTISE DNO
10 Sales NYC
DNO DNAME LOC
DEPT
pkey ref. pkey
x:Employee
http://x.com/Emp#{ENO}
Predicate-object pairs
Subject
class
<http://x.com/Emp#7782>
rdf:type x:Employee ;
<../Emp/Empno> 7782 ;
<../Emp/EmpName> “John” ;
<../Emp/Expertise> “DB” ;
<../Emp/DeptNum> 10 ;
<../Emp/Department> <http://x.com/Dept#10> .
TriplesMap
EMP
38. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Oracle SQL Developer RDF Support
40
• R2RML Mapping Editor
– Shows a tree view of an
R2RML mapping
– Allows drill down from
Triples Map -> Subject
Map -> Predicate-Object
Map
– You can edit or delete
existing elements or add
new ones
– “Commit Mapping”
refreshes the associated
RDF view
39. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Performing Inference
40. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Core Inference Features in Oracle Database
42
• Oracle provides native inference in the database for
• RDFS, RDFS++
• OWLPRIME, OWL2RL, OWL2EL, SKOSCORE
• User-defined rules
• User-defined inferencing
• Inference done using forward chaining
• Triples inferred and stored ahead of query time
• Removes on-the-fly reasoning and results in fast query times
• Proof generation
• Shows one deduction path
41. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
• Option 1: Add user-defined rules
• Example: sibling rule
• Option 2: Leverage external DL reasoners
• Option 3: User-defined inferencing in Oracle Database Release 12c
Extending Semantics Supported by Native OWL Inference Engine
Antecedents
Consequents
?z :parentOf ?x .
?z :parentOf ?y .
?x owl:differentFrom ?y .
?x :siblingOf ?y
43
42. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Extensible Architecture for External OWL DL Reasoners
External
In-Memory OWL
DL Reasoners
TrOWL/REL
Jena APIs
through
Adapter for
Apache Jena
Oracle’s
Native Inference
Engine for OWL 2
RL, EL & user-
defined rules
Materialized Inference
44
43. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
• SDO_SEM_INFERENCE.
INF_EXT_ACTION_START
• SDO_SEM_INFERENCE.
INF_EXT_ACTION_RUN
• SDO_SEM_INFERENCE.
INF_EXT_ACTION_END
User-Defined Inferencing in Oracle Database Release 12c
45
44. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
SPARQL Query and Update
45. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
What is SPARQL?
• SPARQL Protocol and RDF Query Language
– W3C standard for querying and manipulating RDF content
– Queries/updates and corresponding results are communicated via HTTP with a
SPARQL endpoint
– A SPARQL endpoint implements the SPARQL protocol and serves RDF data from a
RDF triplestore or RDF view
46. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
SPARQL Graph Pattern
Basic unit of SPARQL queries
univ:Student
univ:student123
univ:student456
"John Green"
"1999-06-15"^^xsd:date
"male"
"Susan Blue"
"2000-02-10"^^xsd:date
"female"
rdf:type
rdf:type
foaf:name
vcard:BDAY
foaf:gender
foaf:name
vcard:BDAY
foaf:gender
univ:Student
univ:student123
"John Green"
"1999-06-15"^^xsd:date
"male"
rdf:type
foaf:name
vcard:BDAY
foaf:gender
?t
?p
?n
?b
?g
Result 1: {?t=univ:Student, ?p=univ:student123, ?n="John Green", ?g="male", ?b="1999-06-15"^^xsd:date}
Result 2: {?t=univ:Student, ?p=univ:student456, ?n="Susan Blue", ?g="female", ?b="2000-02-10"^^xsd:date}
47. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
?t
?p
?n
?b
?g
SPARQL Graph Pattern
Basic unit of SPARQL queries
rdf:type
foaf:name
vcard:BDAY
foaf:gender
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>
SELECT ?t ?n ?b ?g
WHERE
{ ?p rdf:type ?t .
?p foaf:name ?n .
?p vcard:BDAY ?b .
?p foaf:gender ?g }
How do we express this with SPARQL?
Basic Graph
Pattern (BGP)
48. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
SPARQL FILTER: Restricting Solutions
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?n ?b ?g
WHERE
{ ?p foaf:name ?n .
?p vcard:BDAY ?b .
?p foaf:gender ?g
FILTER ( ?b < "2000-01-01"^^xsd:date )}
Find all people born before 2000
49. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
SPARQL Subqueries & Aggregates
SELECT DISTINCT ?n ?o ?p ?st ?cnt
WHERE
{ ?s foaf:name ?n .
?s vcard:BDAY ?b .
?s foaf:gender ?g
{ SELECT ?s (COUNT(?c) AS ?cnt)
WHERE
{ ?s univ:takes ?c }
GROUP BY ?s
HAVING (COUNT(?c) > 20)
}
}
ORDER BY DESC(?cnt) ASC(?n)
Find information about Students that have taken more than 20 classes
50. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
SPARQL Property Path: Matching Arbitrary Length Paths
SELECT ?friend
WHERE
{ ?student foaf:name "Bill Brown" .
?student foaf:friendOf+ ?friend
}
Find all the friends of Bill Brown
Regular expression-style syntax
Syntax Matches
:predicate+ Path composed of one or more repetitions of :predicate
:predicate* Path composed of zero or more repetitions of :predicate
51. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
SPARQL 1.1 Update
• SPARQL 1.1 Update is intended to be a standard language for specifying and
executing updates to RDF graphs in a Graph Store.
Graph Update operations
INSERT DATA Adds some triples, given inline in the
request, into a graph.
DELETE DATA Removes some triples, given inline in the
request, if the respective graph contains those.
DELETE/INSERT Perform pattern-based actions for graph
updates
LOAD Reads the contents of a document representing a
graph into a graph in the Graph Store.
CLEAR Removes all the triples in (one or more) graphs.
Graph Management operations
CREATE Creates a new graph in stores that support empty
graphs.
DROP Removes a graph and all of its contents.
COPY Modifies a graph to contain a copy of another.
MOVE Moves all of the data from one graph into another.
ADD Reproduces all data from one graph into another.
52. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
SPARQL and SPARQL in SQL Architecture
Support for Apache Jena
Standard SPARQL Endpoint
Enhanced with query management control
SEM_MATCH
SEM_APIS.UPDATE_MODELSQL
Java
HTTP
SPARQL-to-SQL Core Logic
Apache Jena
53. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
SPARQL in SQL: SEM_MATCH
SELECT n1, n2
FROM
TABLE(
SEM_MATCH(
'PREFIX foaf: <http://...>
SELECT ?n1 ?n2
FROM <http://g1>
WHERE {?p foaf:name ?n1
OPTIONAL {?p foaf:knows ?f .
?f foaf:name ?n2 }
FILTER (REGEX(?n1, "^A")) }
ORDER BY ?n1 ?n2',
SEM_MODELS('M1'),…));
n1 n2
Alex Jerry
Alex Tom
Alice Bill
Alice Jill
Alice John
54. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
SPARQL in SQL: SEM_MATCH
• Extends SQL with full SPARQL 1.1 query constructs
• Benefits:
– Integrates graph data with existing enterprise data
– JOINs with other relational (and object-relational) data
– Allows SQL constructs/functions
– DDL Statements: create tables/views
– Allows use of enterprise SQL development tools
55. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
SPARQL Update: SEM_APIS.UPDATE_MODEL
begin
sem_apis.update_model(
apply_model=>'M1',
update_stmt=>'INSERT {?s :mbox ?n}
WHERE {?s :email ?n}'
);
end;
/
56. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Tools Make Things Easier
SQL Developer RDF Plugin Jena Fuseki Web Application
57. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Agenda
64
Definition and Use Cases for Knowledge Graphs
Modeling Knowledge Graphs using W3C RDF
Using Oracle RDF Knowledge Graph
Performing Analytics with RDF Knowledge Graph Data
1
2
3
4
58. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 65
Oracle RDF KG as an Integration / Analytics Platform
My SQL
SQL Server
DB2
Oracle Big
Data
Connectors
External
Table /
DB Link
Oracle
Database
Gateways
Oracle Advanced
AnalyticsOBIEE
Relational
Table/View
Property
Graph View
Property
Graph View
of RDF
RDF View
PGX
CREATE VIEW
SEM_MATCH
59. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Creating Property Graph Views on an RDF Graph
public static void createPropertyGraphViewOnRDF(Connection conn,
String pgGraphName,
String rdfModelName,
boolean virtualModel,
PGUtils.RDFPredicate[] predListForVertexAttrs,
PGUtils.RDFPredicate[] predListForEdges)
This method creates the property graph views (vertex and edge views) for the given RDF model.
Parameters:
conn - a connection instance to Oracle database
pgGraphName - the name of the property graph to be created
rdfModelName - the name of the RDF model
virtualModel - a flag represents if the RDF model is virtual model or not
predListForVertexAttrs - an array of RDFPredicate objects specifying how to create vertex view using these
predicates
predListForEdges - an array of RDFPredicate specifying how to create edge view using these predicates
60. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Creating Property Graph Views on an RDF Graph
// create PG view on RDF model
PGUtils.createPropertyGraphViewOnRDF(conn, "articles", "articles", false,
predsForVertexAttrs, predsForEdges);
// get the Property Graph instance
oracle = new Oracle(jdbcUrl, user, password);
pggraph = OraclePropertyGraph.getInstance(oracle, "articles");
// use like a normal Property Graph instance
System.err.println("------ Vertices from property graph view ------");
pggraph.getVertices();
System.err.println("------ Edges from property graph view ------");
pggraph.getEdges();
61. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Questions?
62. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 69