10.6.12 RDF Views from Relational Data

Starting from Graph Server and Client Release 25.3, you can easily create an RDF view graph using the RDF View Wizard in RDF Graph Server and Query UI. You can then run SPARQL queries on the RDF view graph and visualize the query output.

The wizard provides a structured step-by-step approach guiding you to create an R2RML mapping for viewing the contents of the relational tables as RDF triples. Also, note that viewing resources as blank nodes is not supported in mappings that are created using the wizard.

Note:

Oracle Graph also provides subprograms to create, export, and drop RDF Views. See API Support for RDF Views for more information. An RDF view graph can be queried using SPARQL queries.

The RDF View Wizard is based on the following concepts:

  • Resource Maps: These represent the mapping for obtaining the resources (nodes) in the graph structure. A resource map contains the mapping for viewing the content of each row in an entity table as a set of RDF triples. These triples use as subject the same resource, representing the entity corresponding to the row, along with all its properties.
  • Link Maps: These represent the mapping for obtaining the relationships (edges) between two resources in the graph structure. A link map contains the mapping for viewing each binary relationship, captured in a row of the relationship table, as an RDF triple whose predicate reflects the type of relationship and whose subject and object are resources obtained using the referenced (source and target) resource maps.

The following section explains the steps to create, query, and visualize an RDF view graph using the wizard:

10.6.12.1 Getting Started with the RDF View Wizard

The instructions in this section describe the steps to create an RDF view graph using the RDF View wizard. It is assumed that the application is connected to a data source. The required relational tables and RDF network exist in the database. The following figure provides a visual representation of the example schema used in the example steps:

Figure 10-72 Example Schema (RDFU)



As seen in the preceding diagram, the schema RDFU comprises three tables: EMP, JOB_HIST, and DEPT. (There is also a fourth table, JOB_MENTOR, but it is not shown in the preceding diagram as the example does not make use of it). The single-column primary keys for the three tables are EMPNO, JOBNO, and DEPTNO, respectively. The JOB_HIST table contains ENO and DNO as the foreign keys for referencing the EMP and DEPT tables respectively.

Perform the following steps to create an RDF view graph using the RDF View Wizard.
  1. Navigate to the Data page.
  2. Select the Data source and the RDF network.
  3. Right click RDF Views under RDF Objects in the RDF Network tab.
  4. Click Create using Wizard from the context menu.
    The Create RDF View Wizard page opens on the right panel as shown:

    Figure 10-73 Create RDF View Wizard



    You can begin creating the RDF view graph using one of the following approaches:

    • One-click bootstrap: Automatically build the mappings from database tables that you own. This approach is available only when no resource maps currently exist in your environment.
    • Expand existing resource and link mappings (Transitive Closure / Incremental Expansion): Use your current mappings and extend the RDF view graph mappings one foreign-key hop at a time.
    • Manual mapping: Manually select the tables to create resource and link mappings, and then follow the wizard workflow.

    You can also mix and match these approaches to create your RDF view graph.

  5. Perform the steps depending on the approach you wish to choose:
    • Build from Foreign Keys Automatically (First‑Time Bootstrap):

      When there are no resource maps existing in your environment, the hammer button on the top right corner displays Build from Foreign Keys. Use the button (shown highlighted in the following figure) to bootstrap mappings from your database with one click.

      Figure 10-74 Build from Foreign Keys



      The wizard performs the following actions:

      • Selects all the tables in your schema and inspects their foreign keys.
      • Creates RMAPs for entity tables with at least one non‑foreign key column. Pure join tables that only contain foreign keys are not created as standalone RMAPs.
      • Creates LMAPs for relationships discovered through foreign keys, including links derived from join tables that were not created as RMAPs.
    • Transitive Closure Step (Incremental Expansion):

      When at least one RMAP exists in your environment, the hammer button on the top right displays Transitive closure step. Each click on this button expands the RDF view graph mappings one foreign-key hop from your current RMAPs, adding relationship tables that reference your mapped entities and their other related parent entities.

      The wizard performs the following actions:

      • Creates RMAPs for newly found tables that have at least one non‑foreign key column.
      • Creates LMAPs between mapped tables.
      • Adds related tables from other schemas if you have the table privileges to read the necessary foreign key and column metadata.

      You can click repeatedly on the Transitive closure step button to continue expanding the RDF view graph mappings until you see a toast message, No new related tables found. Note that each expand action only adds new tables and preserves all edits to names, prefixes, keys, classes, properties, or predicates in your existing mappings.

    • Add Resource and Link Maps Manually:
  6. Optionally, click on any added Resource Map to view or edit its details.

    Figure 10-75 Viewing Resource Map Details



    Also, note the following:

    • If the underlying database table for the resource map does not have a primary key, then the first table column will be considered as the resource map Key by default.
    • You can choose to edit the name, key, class, graph map, and template (subject) of the resource map in the Resource Map Details section. For example, you may want to rename the JobHist resource map to a more meaningful name like workedFor.
    • You can choose to edit the mapping for the predicate and object of the properties in the Resource Map Properties section. Among many options for object, you can use template, column, or a constant IRI or literal, and for literals you can specify custom datatype, language tag, and so on. Additionally, each property triple can be associated with a named graph by choosing More options as shown.

      Figure 10-76 Editing Resource Map Properties



  7. Optionally, click on any added Link Map to view or edit its details.

    Figure 10-77 Viewing Link Map Details



    Additionally, you can easily reverse the direction of a link in a Link Map by clicking the switch arrows button, next to the edit button.

  8. Choose one of the following actions to proceed.
    • Continue to manually add additional Resource Maps or Link Maps.
    • Expand your mappings by clicking the hammer icon (Transitive Closure Step) to fetch related tables and relationships.
    • Download the raw R2RML for inspection or a PL/SQL ready-to-run script with the R2RML string in it (see step-9).
    • Create the RDF View directly by proceeding to step-10.
  9. Click the R2RML tab to inspect the raw R2RML.

    Optionally, click Download to download the PL/SQL ready-to-run script containing the R2RML string or the raw R2RML.

    • Click PL/SQL, enter the RDF View name, and click Download to download the PL/SQL anonymous block for creating the RDF View based on the current R2RML mapping.
    • Click R2RML and then Download to download the R2RML mapping document.
  10. Click Create (Create RDF View button) on the top right of the Create RDF View Wizard page.
    The Create RDF View window opens as shown:
  11. Enter RDF View name and click Create.
  12. Refresh RDF Views in the left pane under RDF Objects.
    The newly created view is successfully added to the list.

    Optionally, you can right click on an RDF view graph and click Open to view the RDF view graph details. You can execute SPARQL queries in the SPARQL tab. The results of the SPARQL query can be viewed either as a tabular output, graph, or both.

    Figure 10-81 Executing SPARQL Queries on an RDF View



    You can also right click on an RDF view graph and select Visualize. This opens the RDF view visualization page in a new tab. You can enter a SPARQL query in the Query selector section and click Execute. The output of the query is displayed as a graph in the Graphviz section. For example, consider running the following SPARQL query to find the department in which the employees work:

    PREFIX ex: <http://www.example.oracle.com/>
    
    CONSTRUCT {
        ?emp <http://www.example.oracle.com/workedFor> ?dept .
        ?job <http://www.example.oracle.com/employed> ?emp .
        ?job <http://www.example.oracle.com/atDepartment> ?dept .
    }
    WHERE { 
        graph ?job { 
          ?emp <http://www.example.oracle.com/workedFor> ?dept 
        }
    }
    LIMIT 500

    The query visualization output gets displayed as shown:

    Figure 10-82 Visualizing SPARQL Queries on an RDF View Graph



10.6.12.2 Creating Resource Maps Manually

Perform the following steps to manually create the Resource Maps for the RDF view graph in the Designer tab of the RDF View Wizard.
  1. Click the Add new Resource Map (+) icon.
    The Create Resource Maps dialog opens and lists the tables that you own.

    Figure 10-83 Create Resource Maps



  2. Optionally, click Show all accessible tables to include all the tables to which you have access from other schemas.
  3. Select the desired input tables and move the selection to the right.
  4. Select a prefix value from the Using prefix drop-down.
  5. Click Create.
    The selected tables are added to the Resource Maps section. Also, based on this selection some Link Maps may get created automatically. When a relationship table is selected together with both of its referenced parent tables, the wizard automatically creates one LMAP per unordered foreign key pair (including self‑relationships and multiple links for tables with more than three foreign keys).

    Tip:

    You can click the Transitive closure step button at any time while building the RDF view graph to expand your existing mappings.

10.6.12.3 Creating Link Maps Manually

Perform the following steps to manually create the Link Maps for the RDF view graph in the Designer tab of the RDF View Wizard.
  1. Click the Link Map (+) icon.
    The Create Link Map workflow opens and the Name step is displayed.

    Figure 10-84 Create Link Map: Name



  2. Enter the Link Map name.
  3. Click the Next arrow icon.
    The Select step opens as shown.

    Figure 10-85 Create Link Map: Select



  4. Select the Relationship table from the drop-down.
  5. Click the Next arrow icon.
    The Define step opens displaying the Source tab.

    Figure 10-86 Create Link Map: Define (Source Tab)



  6. Select the source References RMAP and Key in the Source tab.
  7. Specify how the predicate should be created for this link. It can be based on a template, column, or by explicitly specifying a constant absolute or compact IRI in the Relationship tab.

    Figure 10-87 Create Link Map: Define (Relationship Tab)



  8. Optionally, click More options to add the generated links to named graph(s) (see Figure 10-87).

    This allows creation of RDF quads. Graph Map can be based on template, column, constant (IRI), or based on a reference to a Resource Map and a matching key. For the Resource Map based option, the template of the referenced Resource Map is used with the columns substituted (from the relationship table) specified as the key and, as a result, the generated named graph IRI can be used as the identifier for the generated triple. See Named Graphs for more information on named graphs.

  9. Select the destination References RMAP and Key in the Target tab.

    Figure 10-88 Create Link Map: Define (Target Tab)



  10. Click the Next arrow icon.
    The Summary of the designed graph structure is displayed. For example:

    Figure 10-89 Create Link Map: Summary



  11. Click Create.
    The configured triple is added and displayed in the Link Maps section.