The Resource Description Framework (RDF) is one of the most powerful technique 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 therefore, lets discuss how we can expose our data as a RDF resource in the cloud using WSO2 Stratos Data Services Server.
1) use the RDF data model to publish structured data on the Web
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.
-------------------Simple RDF file --------------
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 create several rdf
resource for the linking purposes however, for clarity purposes I will demonstrate how to create a single RDF resource and link it with an existing RDF resources.
Lets expose a google spreadsheet with product information on vehicle sales.
Product – Describe the currently available products in a car sale vendor.
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 |
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.
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 click on test connection to confirm your connection.
Click on next to go to the Query page. Query page describe the extracting algorithm 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 http://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
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, 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.
Lets map ID, Model and Qty as elements and Classification as a resouce, Lets link classification column to the productline resouces as i mention earlier ( http://productLines/car , http://productLines/cycle, http://productLines/bus )
Mappings of RDF resource
Resource URI http://productLines/{3} (as you can see we put the column 3 to get each classification type of the product).
Resouce Field Name - Classification
Mappings of RDF element
Following diagram shows the output mappings which we mapped from google spreadsheet to RDF resource.
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.
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/amani123.com/RDFDataSource/_getproducts (replace the tenant name amani123.com with your tenant domain)
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)
Now we exposed our spreadsheet data in the cloud space just within 10 mins :) you can create more rdf data sources using the same manner with different data sources (csv/excel/rdbms) and expose those data as RDF data sources. I will further explain how we can extract RDF data using SPARQL in my next blog post :)
No comments:
Post a Comment