SemanticProductDB

From Wiki of the E-Business and Web Science Research Group

Jump to: navigation, search

Contents

Fetching Product Properties for Camcorders from the Semantic Web

This page describes a quick demo of how the Web of Data can be queried for product features for Camcorders.

SPARQL Query

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX gr: <http://purl.org/goodrelations/v1#>

# show properties an property values for EAN "8714574993836"

SELECT ?p ?v ?uom WHERE
{
?uri rdf:type gr:ProductOrServiceModel.
?uri gr:hasEAN_UCC-13  "8714574993836"^^xsd:string.
?uri ?p ?qv.
?qv gr:hasValueFloat ?v.
?qv gr:hasUnitOfMeasurement ?uom.} 

Note: Instead of hasValueFloat, hasMaxValueFloat or hasMaxValue should be used, but this requires inferencing which may not be available on all endpoints.


Example: Query the Virtuoso LOD instance for the EAN code: Click here

Python Code


 
#!/usr/bin/env python
# encoding: utf-8
"""
SemanticProductDB.py
 
Created by Martin Hepp on 2009-06-15.
Copyright (c) 2009 Universität der Bundeswehr. All rights reserved.
"""
 
import webbrowser
import urllib
 
def fetchProperties(ean):
	'''Fetch product properties from the Semantic Web'''
	query = """
	PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
	PREFIX gr: <http://purl.org/goodrelations/v1#>
 
	SELECT ?p ?v ?uom WHERE 
	{
	?uri rdf:type gr:ProductOrServiceModel. 
	?uri gr:hasEAN_UCC-13  \""""+ean+"""\"^^xsd:string. 
	?uri ?p ?qv.
	?qv gr:hasValueFloat ?v.
	?qv gr:hasUnitOfMeasurement ?uom.
	}
	"""	
	params = urllib.urlencode({'default-graph-uri': '', 'query': query,
	'format': 'text/html', 'debug' : 'on', 'timeout' : ''})
	webbrowser.open("http://lod2.openlinksw.com/sparql?%s" % params)	
 
while True:
	ean = raw_input('Enter EAN or scan item')  # fetch EAN from keyboard
	if (ean==''): break             # stop when input is empty
	ean = "0"+ean 
	print ean                       # print EAN
	fetchProperties(ean)
print 'Program completed.'
 
 
 


Sample Barcodes as PDF

Click on the following link to download a PDF document with barcodes that should work:

BarcodeFeatureDemo.pdf (file size: 103 KB, MIME type: application/pdf)

Personal tools
Navigation