How to Expose Your Cloud Data as RDF Data Model
- Amani Soysa
- Associate Technical Lead - WSO2
Introduction
The Resource Description Framework (RDF) is one of the most powerful techniques to expose and interlink data (knowledge) in the decentralized world. It is also the latest trend in publishing and consuming linked data on the cloud. WSO2 Stratos Data Services Server, expose data as a service facilitates the feature to expose and extract RDF data. This tutorial explains how to expose a Google spreadsheet as RDF data source using WSO2 Stratos Data Services Server.
Prerequisites
Creating a tenant in StratosLive
Applies to:
|
WSO2 Data Services Server |
2.6.0 |
RDF Basics
RDF data model consist of set of statements which has a way of publishing link data on the web as triplets (with the use of subject predicate and object). In simple terms RDF model is a way of representing machine understandable data on the web as shown in the diagram below.

Figure 1 - RDF Model
In the above arc and node diagram, the resources Product and Car are represented using eclipses and they are identified by Uniform Resource Identifiers (URIs). Resources can have properties such as ProductCode, ProductName and Price which needs to be linked with literal values.
Our examples in this tutorial will be about vehicle vendors, which has information regarding vehicles. Which can be mapped as a RDF model as shown below.
<rdf:RDF xmlns:rdf="https://www.w3.org/1999/02/22-rdf-syntax-ns# xmlns:cd="https://www.product.fake/cd#">
Creating Google Spreadsheet Data Source
Now that we have a brief understanding on RDF and the importance of RDF data, lets see how we can generate RDF data source from a Google spread sheet.
First you need to create a Google spread sheet of your choice which has some sensible information. To get the full usage of RDF you need to have several data sources so that RDF resources can be linked with each other. However, for clarity purposes I will demonstrate how to create a single RDF resource and link it with an existing RDF resources.
Create a simple Google spreadsheet with the following data.
| ID | Model | Classification | Qty |
|---|---|---|---|
| S10_1678 | 1996 Moto Guzzi 1100i | Motorcycles | 12 |
| S10_1949 | 2003 Harley-Davidson Eagle Drag Bike | Classic Cars | 23 |
| S10_2016 | 1972 Alfa Romeo GTA | Motorcycles | 18 |
| S10_4698 | 1962 LanciaA Delta 16V | Motorcycles | 15 |
| S10_4757 | 1968 Ford Mustang | Classic Cars | 13 |
| S10_4962 | 2001 Ferrari Enzo | Classic Cars | 12 |
| S12_1099 | 1968 Ford Mustang | Classic Cars | 4 |
| S12_1108 | 2001 Ferrari Enzo | Classic Cars | 10 |
Product – Describe the currently available products in a car sale vendor.

Figure 2 - Google Spread sheet for product table.
Lets assume we have another set of RDF resources on product line ( which has information on each product line type) ie https://productLines/car , https://productLines/cycle, https://productLines/bus.
Creating Data Service
To create a data dervice you need to login to StratosLive using your tenant and go to WSO2 Stratos Data services from the WSO2 Stratos Manager home page. To create a data service go to the left side menu bar and click on create under webservices -> Add -> Data Services. Then you will get a wizard as shown below. Give a proper data service name and click on next.

Figure 3 - Create new data service
Once you click on next you will be directed to add data source page. And give information regarding the Google spreadsheet you created along with your credentials. You can test your data source by clicking on test connection.

Figure 4 - Create new data source
Click on next to go to the Query page. Query page contains the data mapping to extract your data from the data source (Google spreadsheet). Lets extract ProductID, Model,Classification and Qty.
Since our output is RDF result set, we need to specify our output type as RDF. RDF Base URI is the format of rdf:about URI which uniquely identifies each resource.
We will give RDF base URI as https://www.product/cd/{1}; this takes the Spreadsheet column 1(which is the ID) value for each row and replaces it for the RDF about attribute inside rdf:Description element.

Figure 5 - Add Query
- Output Type – RDF
- RDF Base URI :- https://www.product/cd/{1}
- Row namespace :- https://www.product/cd#
To generate the response in RDF format click on "Add New Output Mappings" button. There are two mapping types in RDF Output mapping. 1) as a element (resource properties which has literal values needs to be mapped as elements), 2) as a resource. When mapping an element as a resource, you need to give the resource URI along with the column name which needs to be mapped in curly brackets as shown below. This way we can link two RDF resources together and create a relationship between each other.

Figure 6- Mappings of RDF element

Figure 7 - Mappings of RDF resource

Resource URI https://productLines/{3} (as you can see we put the column 3 to get each classification type of the product).
Resouce Field Name - Classification
Once we create the the query click on next to add Resources. Since we are exposing data as RDF resource we need to create a resource to expose the data. Lets give our query information when creating the resource.

Figure 8 - Add Resource
Resouce Path – Products
Resource Method – Get
Query ID – spreadsheetQuery
Click on finish to deploy the data service. Once you click on finish you can see your deployed data service under service list as shown below.

Figure 9 - Deployed Services
Now that we created our RDF resource we can test it by accessing it as a rest call or by using the try its feature.
Rest URL https://data.StratosLive.wso2.com/services/t/tenantdomain/ProductVendor… (replace the tenant domain with your tenant domain)

Figure 10 - RDF souce
You can validate this RDF resource by using the online RDF validator by copy pasting the RDF resource (right click on the page and view page source copy paste it inside the validation)

Figure 11 - Validate RDF resource
Now we have successfully created RDF resource using a Google spreadsheet, you can create RDF resources in the same manner using other data sources such as CSV, Excel sheets, RDBMS, Web ect.
Summary
In this tutorial we discussed how we can model a data set as a RDF model and map data as Subject Predicate and Object. Further, we discuss how we can expose a given data source as an RDF resource in cloud space using WSO2 Stratos Data Services Server.
Author
Amani Soysa, Software Engineer, WSO2 Inc
About Author
- Amani Soysa
- Associate Technical Lead
- WSO2