Tutorial - Data Virtualization

This tutorial demonstrates how to create a new dataset from a CSV file in SPARQUE Desk and perform the entire data virtualization process (upload, data mapping, graph loading) with a simple example. The graph of the dataset can then be used in a strategy.

Requirements:

  • A SPARQUE workspace
  • Login details for your workspace
  • A demo CSV file

For the purpose of this tutorial, the following simple CSV file is used. It contains a small list of products, with some being variation products of a base product.

id,type,name,baseproduct
P0001,product,USB Stick,
P0001-A,variation,USB Stick 16GB,P0001
P0001-B,variation,USB Stick 32GB,P0001
P0002,product,T-Shirt,
P0002-A,variation,T-Shirt blue,P0002
P0002-B,variation,T-Shirt green,P0002
P1234,product,Chair,
P5678,product,Camera,

Download the csv file.

Log In

To begin, log in to SPARQUE Desk:

  1. Go to desk.sparque.ai and sign in.


    SPARQUE login screen
  2. Select your workspace from the list of available workspaces.

    After logging in and selecting the workspace, the following menu appears:


    SPARQUE menu

Add a New CSV Dataset

To create a new dataset:

  1. Click Datasets | + Create dataset.

  2. Enter products as the name and click ADD.

    An empty dataset has now been created.

  3. Click + Add new data pipeline | CSV file to create a new pipeline for the data.


    Add data pipeline
  4. Click Upload files and browse for the CSV file.

    After uploading the file, XML fragments appear on the right. The data is being converted to XML, as SPARQUE always converts source data to an intermediate XML format during data mapping.

    Each of the first few rows in the CSV file corresponds to an XML fragment on the right. For other types of data sources, the XML fragments may look different.


    XML fragments

    Below the uploaded file, on the left side, additional settings are available. These settings help convert the source data into XML fragments. For example, the Column separator character can be found there. For other data source types, different settings appear here. The initial values of the settings may not always be correct, which can cause XML fragments to display incorrectly or not at all. Verify the settings and adjust them if necessary. For this tutorial, the Column separator character must be , and the Contains header row checkbox must be checked. The XML fragments update automatically when the settings change.

Create a New Data Mapping

To transform the XML fragments into triples, a data mapping is needed. Together, all triples form the graph. More information on triples can be found in Basic Concepts.

  1. Click Proceed to mapping in the top right corner.

  2. Enter the name products_csv_mapping for the data mapping and click CREATE.

    The mapping editor opens.


    empty csv mapping

    The left side shows one XML fragment of the source data is displayed. The middle shows the generated data mapping. The used mapping language is an extension of XSLT. The key concept is that the spinque:relation and spinque:attribute tags take properties from the XML fragment and output relation and attribute triples. For more details on the mapping language, see Mapping Language. The right shows the result of applying the data mapping to the XML fragment.

  3. The mapping editor has two modes, the Programming mode and the Visual mode. Make sure the Programming mode is selected. You can switch between modes at the top right.

  4. Adjust the mapping by placing the following templates before the last </xsl:stylesheet> line.

    • First add a match template:
      <xsl:template match="table/row">
      </xsl:template>
      This provides access to all elements inside the row element of the XML fragment.
    • Then create a variable for the product ID. Put the following mapping into the match template:
      <xsl:variable name="productID" select="su:uri('https://www.sparque.ai/product', field[@name='id'])"/>
      The variable productID has a URI as value, such as https://www.sparque.ai/product/P0001. A URI is created because this variable serves as the identifier for the mapped object. The identifier must always be a URI. field[@name='id'] provides the value of the field element that has the attribute name="id".
    • Because every mapped object should have a type, add this mapping:
      <xsl:variable name="productType" select="field[@name='type']"/>
      <spinque:relation subject="{$productID}"  
                    predicate="http://www.w3.org/1999/02/22-rdf-syntax-ns#type" 
                    object="https://www.sparque.ai/{$productType}"/>
      First the product type (product or variation) is stored in a variable, then it is used for the type. In this case, the type can be either https://www.sparque.ai/product or https://www.sparque.ai/variation.
    • Now add the name attribute to the product.
      <spinque:attribute subject="{$productID}" attribute="name" value="{field[@name='name']}" type="string"/>
      The product, identified by the productID, is assigned an attribute called name. Its value is provided by the field element that has the attribute name="name".
    • Add the sku attribute, which maps to the id field:
      <spinque:attribute subject="{$productID}" attribute="sku" value="{field[@name='id']}" type="string"/>
    • Finally, add the relation from the variation to the base product:
      <xsl:if test="field[@name='baseproduct']"> 
        <xsl:variable name="baseproductID" select="su:uri('https://www.sparque.ai/product', field[@name='baseproduct'])"/> 
        <spinque:relation subject="{$productID}" predicate="variation" object="{$baseproductID}"/> 
      </xsl:if>
      The if condition checks whether a field element with the attribute name="baseproduct" exists in the XML fragment. If that field exists, its value is used to create the baseproductID of the product and is saved in a variable. This value equals the productID of the base product. A relation called variation is created from the variation product to the base product.

    The mapping editor displays a heatmap. This shows the SPARQUE Mapping Language lines that are executed to produce the result, providing insight into which parts of the mapping are being used. The spinque:relation and spinque:attribute tags are highlighted in green if they were executed for the currently selected XML fragment. Use the Next and Previous buttons, in the top right of the source data pane on the left, to switch between individual XML fragments.

    Use the Items drop-down to explore the debug output in different formats. In addition to Items, Triples, and Type graph are available.

  5. The final mapping should look like this:


    finished csv mapping
  6. Click Save in the top right corner to save the mapping and return to the dataset detail page.


    dataset detail page

Load Graph

To load the graph and have it displayed on the detail page, do the following:

On the dataset's detail page, click Load graph now. In the background, the data mapping is applied to the data source. After a short time, the following graph appears:


dataset detail page

The two types, product and variation, and their relation to each other are visible in the graph. Clicking the graph opens the inspector. The left side shows the list of types and the number of items each type contains. Click a type to see the items inside.


dataset detail page