SemanticProductDB

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: [http://lod.openlinksw.com/sparql?default-graph-uri=&should-sponge=&query=PREFIX+xsd%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%23%3E%0D%0APREFIX+gr%3A+%3Chttp%3A%2F%2Fpurl.org%2Fgoodrelations%2Fv1%23%3E%0D%0A%0D%0A%23+show+properties+an+property+values+for+EAN+%228714574993836%22%0D%0A%0D%0ASELECT+%3Fp+%3Fv+%3Fuom+WHERE%0D%0A%7B%0D%0A%3Furi+rdf%3Atype+gr%3AProductOrServiceModel.%0D%0A%3Furi+gr%3AhasEAN_UCC-13++%228714574993836%22^^xsd%3Astring.%0D%0A%3Furi+%3Fp+%3Fqv.%0D%0A%3Fqv+gr%3AhasValueFloat+%3Fv.%0D%0A%3Fqv+gr%3AhasUnitOfMeasurement+%3Fuom.%0D%0A}&format=text%2Fhtml&debug=on&timeout= 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)