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 the following:

  • Viewing resources as blank nodes is not supported in mappings that are created using the wizard.
  • Access allowed only to the database tables owned by the database user 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. Each 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. Each 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-73 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 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 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 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-74 Create RDF View Wizard



  5. Create the Resource Maps for the RDF view graph in the Designer tab.
    1. Click the Add new Resource Map (+) icon.
      The Create Resource Maps dialog opens.

      Figure 10-75 Create Resource Maps



    2. Select the required input tables and move the selection to the right.
    3. Select a prefix value from the Using prefix drop-down.
    4. Click Create.
      The selected tables are added and displayed in the Resource Maps section.

      You can click on a specific resource map to view the details as shown:

      Figure 10-76 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 key, class, and template (subject) of the resource map in the Resource Map Details section.
      • 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-77 Editing Resource Map Properties



  6. Create the Link Maps for the RDF view graph in the Designer tab.
    1. Click the Link Map (+) icon.
      The Create Link Map workflow opens and the Name step is displayed.

      Figure 10-78 Create Link Map: Name



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

      Figure 10-79 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-80 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-81 Create Link Map: Define (Relationship Tab)



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

      This allows creation of RDF quads. Graph Map can be based on template, column, constant (IRI), or based on a Resource Map and a matching key. For the Resource Map based option, the template for the Resource Map is used with the columns (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-82 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-83 Create Link Map: Summary



    11. Click Create.
      The configured triple is added and displayed in the Link Maps section.
    12. Optionally, repeat step-6 to add as many Link Maps as required.
      You can click on a specific Link Map to view or edit the details as shown:

      Figure 10-84 Viewing Link Map Details



  7. Click the R2RML tab to review the R2RML mapping document, and optionally, click Download to download the PL/SQL anonymous block for creating the RDF View based on the current R2RML mapping.
  8. 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:
  9. Enter RDF View name and click Create.
  10. 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-87 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-88 Visualizing SPARQL Queries on an RDF View Graph