Whether you’re using Oracle 23ai, 19c, Exadata, Autonomous Database, on-premise, or any other Oracle database platform, Oracle has supported RDF (Resource Description Framework) graphs for years. This powerful option has been part of Oracle’s converged database offering since 2007. Although it’s been available for a long time, many users are unaware of its capabilities.

RDF Graph is closely related to the Linked Data Principles, particularly the concept of 5-Star Data, which provides guidelines for publishing data in an open and linked manner, developed by the World Wide Web Consortium (W3C) for structuring data on the web. It helps organize and query large datasets with complex relationships, serving as both a trust Layer and a semantic layer to improve the accuracy of search results. Additionally, RDF enables seamless data integration within and between organizations. This makes it an essential tool for AI applications. RDF also solves interoperability issues across different databases and applications. These capabilities within Oracle’s converged database strengthen it further by enabling easy conversion and integration of RDF data with other database systems.

RDF graphs are becoming increasingly important for developers, data engineers, and others working with data. This blog is intended for those interested in working with RDF graphs within a converged database. I will walk you through a simple scenario to help you get started with an RDF graph. You will learn how to insert data, query the graph, remodel the data graph, create views from the RDF graph, and finally, how to federate queries, integrate and enrich it with another RDF graph.

Table of Contents

Introduction

Getting started with RDF Graph

Graph Evaluation: Quality Check with WH-Questions

Create View and Further Steps

Federating queries 

Conclusion

Introduction

Whether you’re a literature enthusiast, a data expert, or simply curious about uncovering the hidden connections between stories, this journey will open your eyes to the power of Knowledge Graphs (KG). This blog shows how Knowledge Graphs can be used to reveal the connections between authors and their inspirations. By doing so, it makes the invisible visible, showcasing how ideas flow and evolve over time, connecting writers and their works across cultures and centuries.

We’ll start from scratch, assuming you have no experience with RDF graphs, just like I did when I first began. However, I’ll also assume you already have a database connection set up in Oracle SQL Developer. To get started, please watch this video to learn about SPARQL, and then read RDF 1.1 Concepts and Abstract Syntax, Graph in oracle,  and Ted Talk.

Getting started with RDF Graph

The below scenario is executed on Automomous Database to showcase their functionality and performance. First step is to enable Java, If you may need to. Open SQL Worksheet in Database Action as ADMIN user. Execute the following script:

BEGIN
DBMS_CLOUD_ADMIN>ENABLE_FEATURE(
feature_name=JAVAM);
END;

In the next step, restart the Auronomous Database instance. Then, check if Java is enabled with these queries:

SELECT status, version FROM DBA_REGISTRY
WHERE comp_id = JAVAVM;
STATUS VERSION
------ ----------
VALID 23.0.0.0.0
SELECT dbms_java.get_jdk_version FROM DUAL;
GET_JDK_VERSION
---------------
11.0.26

Right click on the RDF Semantic Graph in Oracle SQL Developer and set up the RDF Semantic Graph…

RDF Network Creation

Under RDF Semantic Graph, right click on Networks and select ‘Create semantic network…’

create new model

Alternatively, you can use the script below. However before running it, make sure that the tablespace name is correct.

BEGIN
SEM_APIS.CREATE_SEM_NETWORK(
tablespace_name = DATA,
network_owner = MARYAMSAJJADIAN,
network_name = RDF_NETWORK);
END;

 If you are using an Autonomous database and do not see the Tablespace, check your database user and verify that you gave some quota on the DATA tablespace when you created the user in the Autonomous database.

 

ADB setting

Create a model under RDF_NETWORK, right-click on ‘New Model…’, name the model ‘biography,’ and select the Tablespace.

 

Create new model

You will see the biography model created in the section regular models.

see Model

Now, it’s time to insert dummy graph data into the ‘biography’ model. The data was manually gathered from Wikidata and other open sources, such as OpenStreetMap, at the start of my KG journey in 2019. Execute the script below in user worksheet where you created the model. More information on the usage of SEM_APIS and SEM_APIS.UPDATE_MODEL can be found in the documentation.

begin
  sem_apis.update_model('biography',
  'prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix xml: <http://www.w3.org/XML/1998/namespace>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix dbp: <http://dbpedia.org/resource/>
prefix dbp-ont: <http://dbpedia.org/ontology/>
prefix dct: <http://purl.org/dc/terms/>
prefix wgs84: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix ps: <http://www.w3.org/2004/02/skos/core#primarySubject>
prefix maps: <http://geographicknowledge.de/vocab/maps#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
INSERT DATA { 
dbp:Rumi dbp-ont:birthPlace dbp:Balkh ;
foaf:name "Rumi";
dbp-ont:birthDate  "1207"^^xsd:gYear;
dbp-ont:deathPlace dbp:Konya;
dbp-ont:deathDate  "1263"^^xsd:gYear;
dbp-ont:thumbnail <https://upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Mevlana_Statue%2C_Buca.jpg/200px-Mevlana_Statue%2C_Buca.jpg>;
dbp-ont:influenced dbp:Paulo_Coelho .
dbp:Paulo_Coelho foaf:name "Paulo Coelho".
dbp:Paulo_Coelho dbp-ont:wasfrom dbp:Brezil .
dbp:Berzil wgs84:geometry "<http://xmlns.oracle.com/rdf/geo/srid/4326> POINT(-46.6455467 -23.5521163)"^^<http://www.opengis.net/ont/geosparql#wktLiteral>;
rdfs:label "Brezil".  
dbp:Balkh wgs84:geometry "<http://xmlns.oracle.com/rdf/geo/srid/4326> POINT(66.89785 36.75831)"^^<http://www.opengis.net/ont/geosparql#wktLiteral>;
rdfs:label "Balkh".
dbp:Konya wgs84:geometry "<http://xmlns.oracle.com/rdf/geo/srid/4326> POINT(32.5047313 37.8707495)"^^<http://www.opengis.net/ont/geosparql#wktLiteral>;
rdfs:label "Konya".
#works
dbp:Fihi_Ma_Fihi dbp-ont:author dbp:Rumi ;
rdfs:label "Fihi Ma Fihi".
dbp:Diwan-e_Shams-e_Tabrizi dbp-ont:author dbp:Rumi ;
rdfs:label "Diwan-e Shams-e Tabrizi".
#dbp:Masnavi and The Alchemist .
dbp:Masnavi dbp-ont:author dbp:Rumi ;
rdfs:label "Masnavi";
ps:influencedOn "The Alchemist" ;
dc:coverage dbp:Spain.
dbp:Spain wgs84:geometry "<http://xmlns.oracle.com/rdf/geo/srid/4326> POINT(-5.1707031 40.2837917)"^^<http://www.opengis.net/ont/geosparql#wktLiteral>;
rdfs:label "Spain";
maps:mapsArea _:b1  . 
_:b1 wgs84:geometry "<http://xmlns.oracle.com/rdf/geo/srid/4326> POLYGON((-7.3904876 37.184715, -7.5224427 37.5569718, -6.9315685 38.2083085, -4.8697591 38.6809765, -2.5673828 38.4906399, -1.6304819 37.3752224, -5.6111932 36.0011219 ))"^^<http://www.opengis.net/ont/geosparql#wktLiteral> .
dbp:Spain rdfs:label "Andalusia";
maps:mapsArea _:b2  . 
_:b2 wgs84:geometry "<http://www.opengis.net/def/crs/OGC/1.3/CRS84>POINT((-5.3652496 36.7581194 ))"^^<http://www.opengis.net/ont/geosparql#wktLiteral> .
dbp:Spain rdfs:label "Church of Our Lady of Aurora".
dbp:Masnavi dbp-ont:popularIn dbp:USA.
dbp:USA wgs84:geometry "<http://xmlns.oracle.com/rdf/geo/srid/4326> POINT(-101.0147894 41.6751441)"^^<http://www.opengis.net/ont/geosparql#wktLiteral>;
rdfs:label "United States".
dbp:Masnavi dbp-ont:wasdestination dbp:pyramid.
dbp:pyramid wgs84:geometry "<http://xmlns.oracle.com/rdf/geo/srid/4326> POINT(31.1341214 29.979274)"^^<http://www.opengis.net/ont/geosparql#wktLiteral>;
rdfs:label "Pyramid".
dbp:Masnavi dbp-ont:departure dbp:baghdad.
dbp:baghdad wgs84:geometry "<http://xmlns.oracle.com/rdf/geo/srid/4326> POINT(44.3763842 33.3140503)"^^<http://www.opengis.net/ont/geosparql#wktLiteral>;
rdfs:label "Baghdad".
}',  
   network_owner=>'MARYAMSAJJADIAN',
   network_name=>'RDF_NETWORK',
   options=>' CLOB_UPDATE_SUPPORT=T '
);
end;

Graph Evaluation: Quality Check with WH-Questions

Now, let’s take a closer look at the RDF graph to understand its structure and data. To do this, we use WH-questions (like who, what, where, when, why) to check the content of the graph. This process acts as a quality check, helping us make sure the data is accurate and complete before moving on to the next steps. More information on the usage of SEM_MATCH can be found in the documentation.

Question one: When and Where was Rumi born?

SELECT Born, place, birthdate,geometry
from table(sem_match('
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix xml: <http://www.w3.org/XML/1998/namespace>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix dbp: <http://dbpedia.org/resource/>
prefix dbp-ont: <http://dbpedia.org/ontology/>
prefix dct: <http://purl.org/dc/terms/>
prefix wgs84: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix ps: <http://www.w3.org/2004/02/skos/core#primarySubject>
prefix maps: <http://geographicknowledge.de/vocab/maps#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
SELECT
?Born ?geometry ?place ?birthdate
WHERE {
dbp:Rumi dbp-ont:birthDate ?birthdate . 
 dbp:Rumi dbp-ont:birthPlace ?Born .
 ?Born rdfs:label ?place .
 ?Born wgs84:geometry ?geometry . 
}',
sem_models('biography'),
null,null,null,null,
' PLUS_RDFT=VC ',
null,null,
'MARYAMSAJJADIAN','RDF_NETWORK'));

1q

 

Question two: When and Where did Rumi die?

SELECT 
Death, place, geometry
from table(sem_match('
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix xml: <http://www.w3.org/XML/1998/namespace>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix dbp: <http://dbpedia.org/resource/>
prefix dbp-ont: <http://dbpedia.org/ontology/>
prefix dct: <http://purl.org/dc/terms/>
prefix wgs84: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix ps: <http://www.w3.org/2004/02/skos/core#primarySubject>
prefix maps: <http://geographicknowledge.de/vocab/maps#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
SELECT 
?Death ?geometry ?place ?deathdate
WHERE {
dbp:Rumi dbp-ont:deathPlace ?Death .
?Death rdfs:label ?place .
dbp:Rumi dbp-ont:deathDate ?deathdate . 
?Death wgs84:geometry ?geometry .
 }',
sem_models('biography'),
null,null,null,null,
' PLUS_RDFT=VC ',
null,null,
'MARYAMSAJJADIAN','RDF_NETWORK'));

2q

Question three: What age did Rumi die and how long he lived?

SELECT 
age,daysOfLife,geometry
from table(sem_match('
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix xml: <http://www.w3.org/XML/1998/namespace>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix dbp: <http://dbpedia.org/resource/>
prefix dbp-ont: <http://dbpedia.org/ontology/>
prefix dct: <http://purl.org/dc/terms/>
prefix wgs84: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix ps: <http://www.w3.org/2004/02/skos/core#primarySubject>
prefix maps: <http://geographicknowledge.de/vocab/maps#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
SELECT 
?age ?daysOfLife ?geometry 
WHERE {
?person dbp-ont:birthDate ?born1.
?person dbp-ont:deathDate ?died1.
bind(xsd:integer(STR(?born1)) as ?born)
bind(xsd:integer(STR(?died1)) as ?died)
bind(?died - ?born AS ?age) .
bind(?age * 365 as ?daysOfLife) .
dbp:Rumi dbp-ont:deathPlace ?place .
?place rdfs:label ?name .
?place wgs84:geometry ?geometry .
}',
sem_models('biography'),
null,null,null,null,
' PLUS_RDFT=VC ',
null,null,
'MARYAMSAJJADIAN','RDF_NETWORK'));

3q

Question four: What are his most popular works and where they have been written?

SELECT 
city,workList,geometry
from table(sem_match('
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix xml: <http://www.w3.org/XML/1998/namespace>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix dbp: <http://dbpedia.org/resource/>
prefix dbp-ont: <http://dbpedia.org/ontology/>
prefix dct: <http://purl.org/dc/terms/>
prefix wgs84: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix ps: <http://www.w3.org/2004/02/skos/core#primarySubject>
prefix maps: <http://geographicknowledge.de/vocab/maps#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
SELECT ?city (Group_CONCAT(Distinct ?worksName; separator=", ")as ?workList) ?geometry
WHERE {
?rumi dbp-ont:deathPlace dbp:Konya.
dbp:Konya wgs84:geometry ?geometry ;
rdfs:label ?city.
?works dbp-ont:author dbp:Rumi ;
rdfs:label ?worksName.
}group by ?city ?geometry 
',
sem_models('biography'),
null,null,null,null,
' PLUS_RDFT=VC ',
null,null,
'MARYAMSAJJADIAN','RDF_NETWORK'));

4q

Question five: Who was influenced by Masnavi?

SELECT 
author,country,geometry
from table(sem_match('
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix xml: <http://www.w3.org/XML/1998/namespace>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix dbp: <http://dbpedia.org/resource/>
prefix dbp-ont: <http://dbpedia.org/ontology/>
prefix dct: <http://purl.org/dc/terms/>
prefix wgs84: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix ps: <http://www.w3.org/2004/02/skos/core#primarySubject>
prefix maps: <http://geographicknowledge.de/vocab/maps#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
SELECT
?author  ?country ?geometry
WHERE {
dbp:Rumi dbp-ont:influenced ?Name1 . 
?Name1 foaf:name  ?author .
dbp:Paulo_Coelho dbp-ont:wasfrom dbp:Brezil .
dbp:Berzil rdfs:label ?country .
dbp:Berzil wgs84:geometry ?geometry . 
 }
',
sem_models('biography'),
null,null,null,null,
' PLUS_RDFT=VC ',
null,null,
'MARYAMSAJJADIAN','RDF_NETWORK'));

5

Question six: Which Paulo’s works is very similar with Masnavi? and where was it written by him?

SELECT 
sameAs ,geometry
from table(sem_match('
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix xml: <http://www.w3.org/XML/1998/namespace>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix dbp: <http://dbpedia.org/resource/>
prefix dbp-ont: <http://dbpedia.org/ontology/>
prefix dct: <http://purl.org/dc/terms/>
prefix wgs84: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix ps: <http://www.w3.org/2004/02/skos/core#primarySubject>
prefix maps: <http://geographicknowledge.de/vocab/maps#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
SELECT
 ?sameAs ?geometry
WHERE {
?work dbp-ont:author dbp:Rumi  . 
?work ps:influencedOn ?sameAs .
dbp:Berzil wgs84:geometry ?geometry . 
dbp:Berzil rdfs:label ?label
}',
sem_models('biography'),
null,null,null,null,
' PLUS_RDFT=VC ',
null,null,
'MARYAMSAJJADIAN','RDF_NETWORK'));

6

Question seven: Where is the start point of the story in the alchemist?

SELECT 
Story_Happens, geometry
from table(sem_match('
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix xml: <http://www.w3.org/XML/1998/namespace>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix dbp: <http://dbpedia.org/resource/>
prefix dbp-ont: <http://dbpedia.org/ontology/>
prefix dct: <http://purl.org/dc/terms/>
prefix wgs84: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix ps: <http://www.w3.org/2004/02/skos/core#primarySubject>
prefix maps: <http://geographicknowledge.de/vocab/maps#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
SELECT 
?departure ?Story_Happens ?geometry
WHERE {
dbp:Masnavi dc:coverage ?departure  .
?departure rdfs:label "Spain".
?departure wgs84:geometry ?geometry .
?departure rdfs:label ?Story_Happens .
}
ORDER BY DESC (?Story_Happens)
LIMIT 1
',
sem_models('biography'),
null,null,null,null,
' PLUS_RDFT=VC ',
null,null,
'MARYAMSAJJADIAN','RDF_NETWORK'));

7

Question eight: Which places did Santiago visit in Spain?

SELECT 
name,geometry
from table(sem_match('
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix xml: <http://www.w3.org/XML/1998/namespace>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix dbp: <http://dbpedia.org/resource/>
prefix dbp-ont: <http://dbpedia.org/ontology/>
prefix dct: <http://purl.org/dc/terms/>
prefix wgs84: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix ps: <http://www.w3.org/2004/02/skos/core#primarySubject>
prefix maps: <http://geographicknowledge.de/vocab/maps#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
SELECT 
?name ?geometry 
WHERE {
?s dc:coverage ?departure  .
?departure rdfs:label ?name .
?departure wgs84:geometry ?geometry .
}
',
sem_models('biography'),
null,null,null,null,
' PLUS_RDFT=VC ',
null,null,
'MARYAMSAJJADIAN','RDF_NETWORK'));

8

Quenstion nine: Where is the start and end points of the story in Masnavi?

SELECT 
place, geometry
from table(sem_match('
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix xml: <http://www.w3.org/XML/1998/namespace>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix dbp: <http://dbpedia.org/resource/>
prefix dbp-ont: <http://dbpedia.org/ontology/>
prefix dct: <http://purl.org/dc/terms/>
prefix wgs84: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix ps: <http://www.w3.org/2004/02/skos/core#primarySubject>
prefix maps: <http://geographicknowledge.de/vocab/maps#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
SELECT ?place ?geometry
WHERE {
{dbp:Masnavi dbp-ont:wasdestination dbp:pyramid.
dbp:pyramid wgs84:geometry ?geometry; 
rdfs:label ?place.}union{
dbp:Masnavi dbp-ont:departure dbp:baghdad.
dbp:baghdad wgs84:geometry ?geometry ;
rdfs:label ?place.}
} order by ?place
',
sem_models('biography'),
null,null,null,null,
' PLUS_RDFT=VC ',
null,null,
'MARYAMSAJJADIAN','RDF_NETWORK'));

9

Quenstion ten: Which place was visited by both characters in the stories?

SELECT 
place,geometry
from table(sem_match('
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix xml: <http://www.w3.org/XML/1998/namespace>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix dbp: <http://dbpedia.org/resource/>
prefix dbp-ont: <http://dbpedia.org/ontology/>
prefix dct: <http://purl.org/dc/terms/>
prefix wgs84: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix ps: <http://www.w3.org/2004/02/skos/core#primarySubject>
prefix maps: <http://geographicknowledge.de/vocab/maps#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
SELECT
?place ?geometry
WHERE {
?uri ?p dbp:pyramid.
dbp:pyramid wgs84:geometry ?geometry; 
rdfs:label ?place.
 }
',
sem_models('biography'),
null,null,null,null,
' PLUS_RDFT=VC ',
null,null,
'MARYAMSAJJADIAN','RDF_NETWORK'));

10

Quenstion eleven: Where is Masnavi the bestselling poet and where is english version of it?

SELECT 
country,paper, EnglishVersion, geometry
from table(sem_match('
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix xml: <http://www.w3.org/XML/1998/namespace>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix dbp: <http://dbpedia.org/resource/>
prefix dbp-ont: <http://dbpedia.org/ontology/>
prefix dct: <http://purl.org/dc/terms/>
prefix wgs84: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix ps: <http://www.w3.org/2004/02/skos/core#primarySubject>
prefix maps: <http://geographicknowledge.de/vocab/maps#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
SELECT
  ?country ?geometry ?paper ?englishVersion
WHERE {
dbp:Masnavi dbp-ont:popularIn dbp:USA.
dbp:USA wgs84:geometry ?geometry ;
rdfs:label ?country.
bind ("https://financialtribune.com/articles/art-and-culture/30372/rumi-best-selling-poet-in-us" as ?paper)
bind("https://www.holybooks.com/wp-content/uploads/Masnavi-I-Manavi-Teachings-of-Rumi.pdf" as ?englishVersion) 
  }
',
sem_models('biography'),
null,null,null,null,
' PLUS_RDFT=VC ',
null,null,
'MARYAMSAJJADIAN','RDF_NETWORK'));

11

Quenstion twelve: Which places did we explore today?

SELECT 
Here,geometry
from table(sem_match('
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix xml: <http://www.w3.org/XML/1998/namespace>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix dbp: <http://dbpedia.org/resource/>
prefix dbp-ont: <http://dbpedia.org/ontology/>
prefix dct: <http://purl.org/dc/terms/>
prefix wgs84: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix ps: <http://www.w3.org/2004/02/skos/core#primarySubject>
prefix maps: <http://geographicknowledge.de/vocab/maps#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
SELECT 
?Here ?geometry
WHERE {
?place rdfs:label ?Here .
?place wgs84:geometry ?geometry.
}',
sem_models('biography'),
null,null,null,null,
' PLUS_RDFT=VC ',
null,null,
'MARYAMSAJJADIAN','RDF_NETWORK'));

12

Remodeling

Remodeling graphs is a common approach used in many situations, especially when there is a need to adjust an existing model to better align with internal data model, needs, or systems. This process involves changing the structure of a graph, such as altering relationships between nodes, or improving the properties, to make it more accurate. In our case, the biography model is not enough good to be fully accurate, and it needs more consistency.

The biography graph faces challenges due to the lack of RDFS and RDF elements, as well as reasoning capabilities for semantic inference. For example, without properly using rdf:type and rdfs:subClassOf, the graph may fail to recognize an author as a person. If an author like Paulo Coelho isn’t defined as rdf:type owl:Person, queries like “list all authors” would be incomplete. Similarly, without reasoning capabilities, the graph may not link authors to genres, leading to incorrect or incomplete search results.

To improve the graph’s effectiveness, the remodeling process is carried out in two steps. The first step is remodeling from dbp-ont to schema org/and foaf. It provides a more organized structure that supports better queries, and future expansion. Authors like Rumi and Paulo Coelho are enriched by adding rdf:type or rdfs:subClassOf  relations (e.g., owl:Person) and linking them to their works with properties such as owl:author and foaf:influenced for clearer relationships. In the second step, geo:hasGeometry replaces geo:asWKT to align with best practices for geospatial data, ensuring proper encoding for spatial querying. These changes make the RDF graph more interoperable and equipped for data management in the converged database. 

In the first step, let’s create a new model:

begin sem_apis.create_sem_model('biography_remodel',null,null,network_owner=>'MARYAMSAJJADIAN',network_name=>'RDF_NETWORK'); end;

Then continue with the following script to complete the first step:

begin
  sem_apis.update_model('biography_remodel','
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix xml: <http://www.w3.org/XML/1998/namespace>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix dbp: <http://dbpedia.org/resource/>
prefix dbp-ont: <http://dbpedia.org/ontology/>
prefix dct: <http://purl.org/dc/terms/>
prefix wgs84: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix ps: <http://www.w3.org/2004/02/skos/core#primarySubject>
prefix maps: <http://geographicknowledge.de/vocab/maps#>
prefix  owl: <http://www.w3.org/2002/07/owl#>
prefix schema: <https://schema.org/>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix dc:<http://purl.org/dc/elements/1.1/>
prefix geo: <http://www.opengis.net/ont/geosparql#>
prefix wde: <http://www.wikidata.org/entity/>
prefix wdt: <http://www.wikidata.org/prop/direct/>
prefix wd: <http://www.wikidata.org/entity/>
prefix skos: <http://www.w3.org/2004/02/skos/core#>
INSERT {
<https://www.oracle.com/author_Rumi> 
a owl:Author; 
dc:source wd:Q43347;
rdfs:subClassOf owl:Person;
schema:name ?name; 
schema:birthPlace <https://www.oracle.com/city_Balkh>;
schema:birthDate  ?gYear;
schema:deathPlace <https://www.oracle.com/city_Konya>;
schema:deathDate  ?Year;
schema:thumbnail ?photo ;
foaf:influenced <https://www.oracle.com/author_PauloCoelho> .
<https://www.oracle.com/author_PauloCoelho> 
a owl:Author; 
dc:source wd:Q9067130;
rdfs:subClassOf owl:Person;
schema:name "Paulo Coelho";
schema:birthPlace <https://www.oracle.com/city_SãoPaulo>;
schema:thumbnail "https://en.wikipedia.org/wiki/Paulo_Coelho#/media/File:Paulo_Coelho,_June_2024.jpg" ;
rdfs:label ?name_bre. 
<https://www.oracle.com/city_Balkh>
a owl:City;
rdfs:subClassOf owl:SpatialThings; 
schema:name "Balkh";
geo:asWKT  ?geo_balkh .
<https://www.oracle.com/city_Konya>
a owl:City;
rdfs:subClassOf owl:SpatialThings; 
schema:name "Konya";
geo:asWKT  ?geo_konya .
<https://www.oracle.com/cityGeneva>
a owl:City ;
rdfs:subClassOf owl:SpatialThings;
schema:name "Geneva" ;
geo:asWKT "<http://xmlns.oracle.com/rdf/geo/srid/4326> POINT(6.1432 46.2044)"^^<http://www.opengis.net/ont/geosparql#wktLiteral>.
<https://www.oracle.com/city_SãoPaulo>
a owl:City;
rdfs:subClassOf owl:SpatialThings; 
schema:name "SãoPaulo";
geo:asWKT ?brezil_geo.
<https://www.oracle.com/works/masnavi> 
a owl:Book ;
rdfs:subClassOf owl:CreativeWork;
schema:author <https://www.oracle.com/author_Rumi>;
schema:description "Masnavi is a poetic work of spiritual guidance and mysticism by Rumi. Masnavi is a mystical poetic work. The work is divided into 6 notebooks, with the first and second notebooks containing a story about a man who saw a dream, beginning his journey in Baghdad and ending at the Pyramid." ;
schema:pdf "https://www.holybooks.com/wp-content/uploads/Masnavi-I-Manavi-Teachings-of-Rumi.pdf" ;
foaf:popularIn ?country_people.
<https://www.oracle.com/country_US>
a owl:Country;
rdfs:subClassOf owl:SpatialThings; 
schema:name "USA";
geo:asWKT "<http://xmlns.oracle.com/rdf/geo/srid/4326> POINT(-98.5805 38.4601)^^<http://www.opengis.net/ont/geosparql#wktLiteral>".
<https://www.oracle.com/works/TheAlchemist> 
a owl:Book ;
rdfs:subClassOf owl:CreativeWork;
schema:author <https://www.oracle.com/author_PauloCoelho>;
schema:pdf "https://icrrd.com/public/media/15-05-2021-084550The-Alchemist-Paulo-Coelho.pdf" ;
schema:sameAs <https://www.oracle.com/works/masnavi> ;
schema:description "The Alchemist is a novel by Paulo Coelho, heavily influenced by spiritual and mystical themes similar to those in Rumis Masnavi.";
foaf:popularIn "all countries".   
}
WHERE {
?Rumi dbp-ont:birthPlace dbp:Balkh ;
foaf:name ?name;
dbp-ont:birthDate  ?gYear;
dbp-ont:deathPlace ?dbp_Konya; 
dbp-ont:deathDate  ?Year;
dbp-ont:thumbnail ?photo ;
dbp-ont:influenced ?dbp_author . 
?dbp_author foaf:name ?name_author_alchmist;
dbp-ont:wasfrom ?dbp_country .
dbp:Berzil wgs84:geometry ?brezil_geo;
rdfs:label ?name_bre.  
dbp:Balkh wgs84:geometry ?geo_balkh ; 
rdfs:label ?balkh .
dbp:Konya wgs84:geometry ?geo_konya ;
rdfs:label ?konya.
dbp:Fihi_Ma_Fihi dbp-ont:author ?Rumi ;
rdfs:label ?worksName.
dbp:Diwan-e_Shams-e_Tabrizi dbp-ont:author ?Rumi ;
rdfs:label ?worksName2.
?dbp_Masnavi dbp-ont:author ?Rumi ;
rdfs:label ?work;
ps:influencedOn ?sp ;
dc:coverage ?sp_countr.
?Masnavi dbp-ont:popularIn ?country_people.
?country_people wgs84:geometry ?geo_us;
rdfs:label ?populare_country.
?Masnavi dbp-ont:wasdestination ?dbp_pyramid.
?dbp_pyramid wgs84:geometry ?geo_pyramid;
rdfs:label ?nameOfpyramid.
?Masnavi dbp-ont:departure ?dbp_baghdad.
?dbp_baghdad wgs84:geometry ?geo_baghdad;
rdfs:label ?nameofcity2.
}',
   match_models=>sem_models('biography'),
   network_owner=>'MARYAMSAJJADIAN',
   network_name=>'RDF_NETWORK',
   options=>' CLOB_UPDATE_SUPPORT=T '
    )
   ;
end;

Before remodeling the geometry in phase 2, in ADB-S we need to execute the following as user ADMIN:

alter system set optimizer_ignore_hints=false;
alter system set optimizer_ignore_parallel_hints=false;
EXECUTE IMMEDIATE 'ALTER SESSION SET optimizer_ignore_hints = FALSE;END;

Then, update the model with the below script:

begin
  sem_apis.update_model('biography_remodel','
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix xml: <http://www.w3.org/XML/1998/namespace>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix dbp: <http://dbpedia.org/resource/>
prefix dbp-ont: <http://dbpedia.org/ontology/>
prefix dct: <http://purl.org/dc/terms/>
prefix wgs84: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix ps: <http://www.w3.org/2004/02/skos/core#primarySubject>
prefix maps: <http://geographicknowledge.de/vocab/maps#>
prefix  owl: <http://www.w3.org/2002/07/owl#>
prefix schema: <https://schema.org/>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix dc:<http://purl.org/dc/elements/1.1/>
prefix geo: <http://www.opengis.net/ont/geosparql#>
delete {?s geo:asWKT  ?geo }
insert {?s geo:hasGeometery [
a geo:Point;
geo:asWKT ?geo;
].
}
WHERE 
  { ?s geo:asWKT  ?geo } ',
   network_owner=>'MARYAMSAJJADIAN',
   network_name=>'RDF_NETWORK',
   options=>' CLOB_UPDATE_SUPPORT=T STREAMING=F'
    )
   ;
end;

Alternatively, you can use the update SPARQL Editor in Oracle SQL DEVELOPER by double click on the biography_remodel:

remodelling in sparql

The last step is to create data type index on WKT:

BEGIN 
  SEM_APIS.ADD_DATATYPE_INDEX(
    datatype => 'http://www.opengis.net/ont/geosparql#wktLiteral',
    tablespace_name => 'DATA',
    parallel => to_number('1'),
    options => 'TOLERANCE=0.01 SRID=4326 DIMENSIONS=((LONGITUDE,-180,180) (LATITUDE,-90,90)) MATERIALIZE=T',
    network_owner => 'maryamsajjadian',
    network_name => 'RDF_NETWORK');
END;

Create View and Further Steps

Now, let’s focus on one of the most powerful features of Oracle’s converged database: the ability to create any type of view or table from an RDF graph. This capability allows users to easily repurpose RDF data for use in any application that supports tables. Depending on the specific needs, you can choose to work with a table, view, materialized view, or analytic view. The database platform you’re using doesn’t affect this process, but it’s important to create indexes and metadata when setting up views or tables. These elements will be useful if you intend to leverage the data in other applications, such as Spatial Studio. If you’re familiar with tools like Spatial Studio or Oracle Apex, you can experiment with these apps yourself and explore the potential of Oracle echosystem.
Here, I am using a simple view since my model is small.

create or replace view Rumi as 
SELECT 
city,
description,
website,
SEM_APIS.getV$GeometryVal(geo$rdfvtyp, geo$_prefix, geo$_suffix, geo$rdfltyp, geo$rdflang, geo$rdfclob, 4326) as geom
from table (sem_match('prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix xml: <http://www.w3.org/XML/1998/namespace>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix dbp: <http://dbpedia.org/resource/>
prefix dbp-ont: <http://dbpedia.org/ontology/>
prefix dct: <http://purl.org/dc/terms/>
prefix wgs84: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix ps: <http://www.w3.org/2004/02/skos/core#primarySubject>
prefix maps: <http://geographicknowledge.de/vocab/maps#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix schema: <https://schema.org/>
prefix geo: <http://www.opengis.net/ont/geosparql#>
SELECT ?city ?geo ?description ?website WHERE {
{<https://www.oracle.com/author_Rumi> 
a owl:Author; 
dc:source ?Rumi;
rdfs:subClassOf owl:Person;
schema:name ?name; 
schema:birthPlace ?birthPlace;
schema:birthDate  ?gYear;
schema:deathPlace ?deathPlace ;
schema:deathDate  ?Year;
schema:thumbnail ?photo ;
foaf:influenced ?inf.}
union {
<https://www.oracle.com/author_Rumi> 
a owl:Author; 
schema:birthPlace ?birthPlace.
?birthPlace
a owl:City;
rdfs:subClassOf owl:SpatialThings; 
schema:name ?city;
geo:hasGeometery [
a geo:Point;
geo:asWKT ?geo;
].
bind ( "rumi was borned in Afghanestan and when he was child experience Attar who was a famous Sufi in Neishabour. https://pen.org/simorgh-thirty-birds-on-translating-farid-ud-din-attar/ " as ?description )
bind ( "https://www.theheritagelab.in/conference-birds-sufi/ " as ?website )
}union {
<https://www.oracle.com/author_Rumi> 
a owl:Author; 
schema:deathPlace ?deathPlace.
?deathPlace
a owl:City;
rdfs:subClassOf owl:SpatialThings; 
schema:name ?city;
geo:hasGeometery [
a geo:Point;
geo:asWKT ?geo;
].
bind ( "https://sacredsites.com/middle_east/turkey/shrine_of_rumi_konya.html" as ?website)
bind ( "rumi lived  and passed away in Konya and all of his works were written there." as ?description )
}
FILTER (?city != "" && ?geo != "") 
}', sem_models('biography_remodel'), null, null, null, null, ' ', null, null, 'MARYAMSAJJADIAN', 'RDF_NETWORK'))

Now, check the view and GEOM column, you will see that WKT converted to SDO_GEOMETRY using  SEM_APIS package:

select * from rumi ;

Federating queries 

Data federation is a technique that allows the integration data from two or more repositories located in different places into a single query result. More information on the federating queries can be found in the documentation.
Here are the steps you need to federate a query:
Assume you want to run SERVICE queries as database user MARYAMSAJJADIAN, you need to open a SQL worksheet :

1. As admin, grant execute privilege on SPARQL_SERVICE to MARYAMSAJJADIAN:
grant execute on mdsys.sparql_service to maryamsajjadian;
2. As admin, grant MARYAMSAJJADIAN network connect privileges with an Access Control List and grant execute on mdsys.sparql_service to MARYAMSAJJADIAN.

Begin
dbms_network_acl_admin.create_acl (
 acl => 'maryamsajjadian.xml',
 description => 'Allow maryamsajjadian to query SPARQL endpoints',
 principal => 'MARYAMSAJJADIAN',
 is_grant => true,
 privilege => 'connect'
);
END;
/

 

/
Begin
dbms_network_acl_admin.assign_acl (
 acl => 'maryamsajjadian.xml',
 host => '*'
);
End;
 
grant execute on mdsys.sparql_service to MARYAMSAJJADIAN;

Please note that SPARQL endpoints must meet certain requirements to be accessible from an Autonomous Database:
1.The URL must use a domain name instead of an IP address.
2.The URL must use HTTPS and be signed with an SSL certificate issued by a recognized certificate authority.
3.By default, HTTP GET is used for SPARQL SERVICE, but you can use direct POST by including ‘HTTP_METHOD=POST_DIR’ in the SEM_MATCH options string.
 

First, check the query here on WikiData.

Here is lines  show the connection between Rumi and Shams Tabrizi:

wd:Q43347 ?p wd:Q796587.

BIND(IF(?p = wdt:P737, wdt:influencedBy, ?p) AS ?newP)

Now, it’s time to federate the query and fetch data from the WikiData repository in Oracle SQL.

select name, nameOfAuthor, image, occupation, nationality
from table (sem_match('
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix prov: <http://www.w3.org/ns/prov#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix wde: <http://www.wikidata.org/entity/>
prefix wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
select * where {
<https://www.oracle.com/author_Rumi> a owl:Author; 
dc:source wd:Q43347.
service <https://query.wikidata.org/sparql> {
 wd:Q43347 wdt:P373 ?name .
    FILTER(?name = "Rumi")
   BIND(wd:Q796587 AS ?Author)  
  # "Shams Tabrizi"
  ?Author wdt:P373 ?nameOfAuthor .
  FILTER(?nameOfAuthor = "Shams Tabrizi")  
  # Optional additional properties
  OPTIONAL { ?Author wdt:P18 ?image. }             
  OPTIONAL { ?Author wdt:P106 ?occupation. }       
  OPTIONAL { ?Author wdt:P27 ?nationality. }            
  OPTIONAL { ?Author wdt:P31 ?instanceOfH. }   
 wd:Q43347 ?p wd:Q796587.  
    FILTER(?p = wdt:P737)
  BIND(IF(?p = wdt:P737, wdt:influencedBy, ?p) AS ?newP)
} }limit 1', 
sem_models('BIOGRAPHY_REMODEL'), null, null, null, null,'PLUS_RDFT=VC HTTP_METHOD=POST_DIR', null, null, 'MARYAMSAJJADIAN', 'RDF_NETWORK'))

Last but not least, create a new model and remodel WikiData in Oracle repository: 

By following these steps, you should be able to enrich the Biography model with data returned through query federation. In this step, you will use an INSERT statement with a WHERE clause to add Shams Tabrizi’s triples to the biography model.

begin
  sem_apis.update_model('BIOGRAPHY_REMODEL','
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix prov: <http://www.w3.org/ns/prov#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix wde: <http://www.wikidata.org/entity/>
prefix wdt: <http://www.wikidata.org/prop/direct/>
prefix wd: <http://www.wikidata.org/entity/>
prefix skos: <http://www.w3.org/2004/02/skos/core#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix xml: <http://www.w3.org/XML/1998/namespace>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix schema: <https://schema.org/>

INSERT {
<https://www.oracle.com/author_Shams>
a owl:Author;
dc:source wd:Q796587;
rdfs:subClassOf owl:Person;
schema:name ?nameOfAuthor;
schema:thumbnail ?image ;
foaf:influenced <https://www.oracle.com/author_Rumi> .
} where {
<https://www.oracle.com/author_Rumi> a owl:Author;
dc:source wd:Q43347.
service <https://query.wikidata.org/sparql> {
wd:Q43347 wdt:P373 ?name .
FILTER(?name = "Rumi")
BIND(wd:Q796587 AS ?Author)
# "Shams Tabrizi"
?Author wdt:P373 ?nameOfAuthor .
FILTER(?nameOfAuthor = "Shams Tabrizi")
# Optional additional properties
OPTIONAL { ?Author wdt:P18 ?image. }             
OPTIONAL { ?Author wdt:P106 ?occupation. }       
OPTIONAL { ?Author wdt:P27 ?nationality. }            
OPTIONAL { ?Author wdt:P31 ?instanceOfH. }
wd:Q43347 ?p wd:Q796587.
FILTER(?p = wdt:P737)
BIND(IF(?p = wdt:P737, wdt:influencedBy, ?p) AS ?newP)}}',
network_owner=>'MARYAMSAJJADIAN',
network_name=>'RDF_NETWORK',
match_options=>'HTTP_METHOD=POST_DIR',
options=>'CLOB_UPDATE_SUPPORT=T'
);
end;

Check the results of update query and the model in SPARQL Editor:

shams2

Conclusions

In conclusion, working with RDF graphs in Oracle’s converged database enables seamless integration and offers flexible usage of data graphs. By leveraging techniques such as data federation and remodeling, you can significantly improve data quality, accessibility, and structure, ensuring interoperability and relevance across diverse applications. Whether you’re utilizing views, tables, or any advanced tools like Spatial Studio and/or Oracle Apex, the ability to efficiently manage and work with RDF data unlocks numerous opportunities for data-driven solutions. These solutions provide value to a wide range of users with varying levels of expertise, allowing them to interact with RDF both directly and indirectly, sometimes without needing to understand SPARQL or RDF. As you continue exploring, remember that this flexibility is key to maximizing the potential of the RDF graph within a converged database environment.

Further Readings