Navigation
gr_banner_small.png
GoodRelations is a standardized vocabulary for product, price, and company data that can be embedded into existing static and dynamic Web pages.

Project Main Page
Vocabulary
Documentation
Developer's Wiki
GoodRelations Cookbook

Overview

We provide a set of very sophisticated XHTML template files for generating Web content for shop software or other e-commerce applications.

All templates and code are available free of charge under the LGPL license.

Features

Download

The templates and documentation are available from http://code.google.com/p/templates4goodrelations/downloads/list

Minimal Example

Overview

The templates can be used to generate either a complete XHTML page or a snippet of additional <div> elements that can be inserted into any HTML page just before the closing <body> element.

The type of result is controlled via the "snippet" parameter.

  • snippet=True: return HTML for insertion into an existing HTML page
  • snippet=False: return a complete page.


If you have full control over the page template, it will be easier to use snippet=False and insert all of your visible XHTML markup into the respective template file.

If it is likely that users of your application edit or replace your XHTML templates, it is better to create RDFa snippets only and insert them just before the final HTML is sent to the client. <python> static_html = """< existing HTML content >"""

...

  1. Create RDFa snippet

snippet = template.render(company_data, snippet=True) # populate template snippet = snippet.encode('UTF-8')

  1. Insert the snippet just before the closing <body> element.

html = static_html.replace("</body>", snippet+"</body>") print html </python>

Company Page

<python> company_data = { 'company_name' : "Best Purchase Electronics Shop Ltd.", # Official name of the business making the offer 'country' : "Germany", 'language' : "en", # ISO 639-1 code for the language of the country name, see http://en.wikipedia.org/wiki/ISO_639-1 'city' : "Munich", 'zip' : "12345", 'street' : "Example Street 123", 'phone' : "+49-89-6004-4217", # Must include international prefix 'logo_uri' : "http:/www.heppnetz.de/gr4shops/logo.jpg" }

from jinja2 import * loader = FileSystemLoader('.') env = Environment( loader=loader, autoescape=True, trim_blocks=True) template = env.get_template('template-company.html')

  1. OPTION 1: Create full HTML+RDFa page

title = "Website of Best Purchase Electronics Shop Ltd." html = template.render(company_data, snippet=False, title=title) # populate template html = html.encode('UTF-8') print html

  1. OPTION 2: Create and insert a RDFa snippet

static_html = """ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.0" xml:lang="en"> <head> <title>My page</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> </head> <body>

Demo page

</body> </html> """

  1. Create RDFa snippet

snippet = template.render(company_data, snippet=True) # populate template snippet = snippet.encode('UTF-8')

  1. Insert the snippet just before the closing <body> element.

html = static_html.replace("</body>", snippet+"</body>") print html </python>

Product Page

<python>

  1. Product & Offer: Canon Rebel T2i for EUR 899 incl. VAT

product_data = { 'product_short' : "Canon Rebel T2i (EOS 550D)", # short product text 'product_long' : """The Rebel T2i EOS 550D is Canon's top-of-the-line consumer digital SLR camera.""", 'language' : "en", # ISO 639-1 code for the language of the text 'company_uri' : "http:/www.heppnetz.de/gr4shops/index.html#company", # This is the URI of the page that contains the company markup # plus the hash fragment ("#company") used in the company_template.html file 'business_function' : "http://purl.org/goodrelations/v1#Sell", 'currency' : "EUR", # ISO 4217 standard (3 characters): USD, GBP, ... 'price' : "899.00", # Amount 'vat' : "true", # Value-added tax included 'delivery_options' : [], # Will be populated below for readability 'valid_from' : "2010-05-01T00:00:00Z", # use current date and time 'valid_through' : "2010-05-07T23:59:59Z", # use current date and time + 1...7 days 'eligible_regions' : ["DE","AT","CH"], # ISO 3166-1 alpha-2 'payment_methods' : ["http://purl.org/goodrelations/v1#PayPal", "http://purl.org/goodrelations/v1#MasterCard"], # Accepted methods of payment; use GoodRelations URIs # Complete list at http://purl.org/goodrelations/v1#PaymentMethod 'product_image_uri' : "eos550d.jpg", # Product image URI 'product_thumbnail_uri' : "eos550d_small.jpg", # Product thumbnail URI 'ean' : "013803123784", # EAN-13, 13-digit UPC, or 13-digit ISBN code for the product. 'sku' : "CANON_EOS550D-KIT" # Store oder brand-specific identifier ("stock keeping unit"). Can be simply your internal ID for the item. }

fedex = {'method_uri' : "http://purl.org/goodrelations/v1#FederalExpress"} product_data['delivery_options'] = [fedex]

template = env.get_template('template-product.html')

  1. Create RDFa snippet

html = template.render(product_data, snippet=False, minimal=True) # populate template html = html.encode('UTF-8') print html </python>

Overview

All templates have a complete list of parameters at the beginning. The following are just a few selected examples.

The full executable code is available at http://code.google.com/p/templates4goodrelations/downloads/list

Company Template

<python>

  1. Example data for the company

company_data = { 'company_name' : "Best Purchase Electronics Shop Ltd.", # Official name of the business making the offer 'country' : "Germany", 'language' : "en", # ISO 639-1 code for the language of the country name, see http://en.wikipedia.org/wiki/ISO_639-1 'city' : "Munich", 'zip' : "12345", 'street' : "Example Street 123", 'phone' : "+49-89-6004-4217", # Must include international prefix 'logo_uri' : "http:/www.heppnetz.de/gr4shops/logo.jpg",

  1. The following codes are optional. Omit when in doubt.

'duns' : "012345678", # DUNS number for the company, see 'gln' : "1234567890123", # Global Location Number (GLN) for the company, see 'isic' : "5610", # ISIC code for your business, see http://unstats.un.org/unsd/cr/registry/isic-4.asp 'naics' : "722110" # North American Industry Classification System (NAICS) code for your business, see http://www.census.gov/eos/www/naics/ }

  1. Create RDFa snippet

template = env.get_template('template-company.html') result = template.render(company_data, snippet=True) # populate template r_utf8 = result.encode('UTF-8') open("output/snippet-company.html", 'w').write(r_utf8) # write result to file

  1. Create complete HTML+RDFa page

title = "Website of Best Purchase Electronics Shop Ltd." rdf_uri = "http:/www.heppnetz.de/gr4shops/goodrelations.rdf" result = template.render(company_data, snippet=False, rdf_uri=rdf_uri, title=title) # populate template r_utf8 = result.encode('UTF-8') open("output/index.html", 'w').write(r_utf8) # write result to file </python>

Brand List Template

<python>

  1. Example data for the brands listed in your shop

canon = { 'name' : "canon", # Short identifier (for URI fragment - no spaces, no special characters) 'company_name' : "Canon Europe Ltd.", # Official name 'logo_uri' : "http:/www.heppnetz.de/gr4shops/canon.jpg", # URI of manufacturer's logo 'uri' : "http://www.canon.com/" # URI of the manufacturer's official Web page }

ibm = { 'name' : "ibm", # Short identifier (for URI fragment - no spaces, no special characters) 'company_name' : "International Business Machines Inc.", # Official name 'logo_uri' : "http:/www.heppnetz.de/gr4shops/ibm.jpg", # URI of manufacturer's logo 'uri' : "http://www.ibm.com/" # URI of the manufacturer's official Web page }

brand_data = {'brands': [canon, ibm]} template = env.get_template('template-brands.html')

  1. Create RDFa snippet

result = template.render(brand_data, snippet=True) # populate template r_utf8 = result.encode('UTF-8') open('output/snippet-brands.html', 'w').write(r_utf8) # write result to file

  1. Create complete HTML+RDFa page

title = "Best Purchase Electronics: List of Brands in Our Store" company_name = "Best Purchase Electronics Shop Ltd." rdf_uri = "http:/www.heppnetz.de/gr4shops/goodrelations.rdf" result = template.render(brand_data, snippet=False, rdf_uri=rdf_uri, title=title, company_name=company_name) # populate template r_utf8 = result.encode('UTF-8') open('output/brands.html', 'w').write(r_utf8) # write result to file </python>

Stores Template

<python>

  1. Example data for the store

store_data = { 'company_uri' : "http:/www.heppnetz.de/gr4shops/index.html#company", 'stores' : [] # will be populated below }

  1. Store in Munich

store_munich = { 'id': "munich_store", # Short, unique identifier for the store ([a-z0-9-_]), will be hash fragment (#munich_store) 'name' : "Best Purchase Electronics Munich Store", # Short label for the store 'description' : "Our Munich store is the best in town ... ", # Longer text describing the store 'language' : "en", # ISO 639-1 code for the language of all textual elements 'country' : "Germany", 'city' : "Munich", 'zip' : "12345", 'street' : "Example Street 123", 'phone' : "+49-89-6004-4217", # Must include international prefix 'logo_uri' : "http:/www.heppnetz.de/gr4shops/munich_shop.jpg", # Logo or image URI 'lat' : "48.08", # Geo position of the store: Latitude 'long' : "11.64", # Geo position of the store: Longitude 'gln' : "1234567890123", # Global Location Number (GLN) for the store (optional) 'opening_hours' : [] # will be populated below for readability }

  1. Opening Hours

mon_fri = { 'opens' : "08:00:00", # must be xsd:time format including seconds! 'closes' : "18:00:00", # must be xsd:time format including seconds! 'days' : ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"], # Must be spelt EXACTLY as shown

  1. These will be expanded to GoodRelations URIs like http://purl.org/goodrelations/v1#Monday

'valid_from' : "2010-01-01T00:00:00Z", 'valid_through' : "2010-12-31T23:59:59Z" } sat = { 'opens' : "08:00:00", # must be xsd:time format including seconds! 'closes' : "18:00:00", # must be xsd:time format including seconds! 'days' : ["Saturday"] # Must be spelt EXACTLY as shown } store_munich['opening_hours'] = [mon_fri, sat] store_data['stores'] = [store_munich] # Add additional stores if needed

  1. Create RDFa snippet

template = env.get_template('template-stores.html') result = template.render(store_data, snippet=True) # populate template r_utf8 = result.encode('UTF-8') open("output/snippet-stores.html", 'w').write(r_utf8) # write result to file

  1. Create complete HTML+RDFa page

title = "Best Purchase Electronics: List of Stores" company_name = "Best Purchase Electronics Shop Ltd." rdf_uri = "http:/www.heppnetz.de/gr4shops/goodrelations.rdf" result = template.render(store_data, snippet=False, rdf_uri=rdf_uri, title=title, company_name=company_name) # populate template r_utf8 = result.encode('UTF-8') open("output/stores.html", 'w').write(r_utf8) # write result to file </python>

Products Template

<python>

  1. Product & Offer: Canon Rebel T2i for EUR 899 incl. VAT

product_data = { 'product_short' : "Canon Rebel T2i (EOS 550D)", # short product text 'product_long' : """The Rebel T2i EOS 550D is Canon's top-of-the-line consumer digital SLR camera. It can shoot up to 18 megapixel resolution photos and features an ISO range of 100-6400.""", # long product text 'language' : "en", # ISO 639-1 code for the language of the text, see http://en.wikipedia.org/wiki/ISO_639-1 'company_uri' : "http:/www.heppnetz.de/gr4shops/index.html#company", # Semantic URI of the company # This is the URI of the page that contains the company markup (STEP 1) # plus the hash fragment ("#company") used in the company_template.html file # In this example, http:/www.heppnetz.de/gr4shops/index.html#company"

'product_uri' : "http:/www.heppnetz.de/gr4shops/product-canon_eos550D-kit.html", # The URI of the page that will contain this snippet # Such is not needed for generating the snippet, but for the creation of the data dump later on. 'business_function' : "http://purl.org/goodrelations/v1#Sell", # We offer the item for SALE 'currency' : "EUR", # ISO 4217 standard (3 characters): USD, GBP, ... 'price' : "899.00", # Amount 'vat' : "true", # Value-added tax included 'delivery_options' : [], # Will be populated below for readability 'valid_from' : "2010-05-01T00:00:00Z", # use current date and time 'valid_through' : "2010-05-07T23:59:59Z", # use current date and time + 1...7 days 'eligible_regions' : ["DE","AT","CH"], # ISO 3166-1 alpha-2 country or ISO 3166-2 region codes indicating the regions for which the offer is valid. # Examples "US" for the United States, "US-AZ" for Arizona, or "DE-BY" for Bavaria 'payment_methods' : ["http://purl.org/goodrelations/v1#PayPal", "http://purl.org/goodrelations/v1#MasterCard"], # Accepted methods of payment; use GoodRelations URIs # Complete list at http://purl.org/goodrelations/v1#PaymentMethod 'product_image_uri' : "eos550d.jpg", # Product image URI 'product_thumbnail_uri' : "eos550d_small.jpg", # Product thumbnail URI 'ean' : "013803123784", # EAN-13, 13-digit UPC, or 13-digit ISBN code for the product. 'gtin14' : "0013803123784", # Global Trade Item Number (GTIN-14) for the product. Leave empty when in doubt. 'sku' : "CANON_EOS550D-KIT", # Store oder brand-specific identifier ("stock keeping unit"). Can be simply your internal ID for the item.

'stock_unit' : "C62", # UN CEFACT Unit of Measurement Code for the inventory level. Default is C62 for "piece, item" 'stock_level' : "9", # Lower bound of current inventory level

# Semantic Web URIs. Omit when in doubt. 'manufacturer_uri' : "http:/www.heppnetz.de/gr4shops/brands.html#canon", # Semantic URI of the manufacturer 'consumable_uris': ["http:/www.heppnetz.de/gr4shops/product_canon_battery.html#product"], # Semantic URI of consumables 'accessory_uris' : ["http:/www.heppnetz.de/gr4shops/product_canon_bag.html#product"], # Semantic URI of accessories 'datasheet_uri' : "http://openean.kaufkauf.net/id/EanUpc_001380303863" # Semantic link to product make and model dataset ("semantic datasheet") }

  1. Create RDFa snippet for the minimal version

product_data['delivery_options'] = [{'method_uri' : "http://purl.org/goodrelations/v1#FederalExpress"}] # minimal info about delivery options

template = env.get_template('template-product.html') result = template.render(product_data, snippet=True, minimal=True) # populate template r_utf8 = result.encode('UTF-8') open('output/snippet-product-canon_eos550D-kit-mini.html', 'w').write(r_utf8) # write result to file

  1. Create richer variant, including shipping charges etc.
  1. Shipment: 10 EUR including VAT for delivery via FedEx to Germany

fedex = { 'charge' : "10.00", # Amount 'currency' : "EUR", # ISO 4217 standard (3 characters): USD, GBP, ... 'method_uri' : "http://purl.org/goodrelations/v1#FederalExpress", 'region' : "de", # Two-character version of ISO 3166-1 (ISO 3166-1 alpha-2) for countries or ISO 3166-2 for states 'vat': "true" # Value-added tax included } product_data['delivery_options'] = [fedex]

  1. Create RDFa snippet

template = env.get_template('template-product.html') result = template.render(product_data, snippet=True, minimal=False) # populate template r_utf8 = result.encode('UTF-8') open('output/snippet-product-canon_eos550D-kit.html', 'w').write(r_utf8) # write result to file

  1. Create Full HTML+RDFa page

title = "Best Purchase Electronics: Canon Rebel T2i (EOS 550D)" rdf_uri = "http:/www.heppnetz.de/gr4shops/goodrelations.rdf" company_name = "Best Purchase Electronics Shop Ltd." result = template.render(product_data, snippet=False, minimal=False, rdf_uri=rdf_uri, title=title, company_name=company_name) # populate template r_utf8 = result.encode('UTF-8') open('output/product-canon_eos550D-kit.html', 'w').write(r_utf8) # write result to file </python>

Datasheets Template

<python>

  1. Semantic Datasheet
  2. It is important that special characters are properly escaped in the resulting markup! ( e.g. & as & etc.)
  1. Datasheet / Product Model: Canon Rebel T2i (EOS 550D)

datasheet_data = { 'product_short' : "Canon Rebel T2i (EOS 550D)", # short product text 'product_long' : """The Rebel T2i EOS 550D is Canon's top-of-the-line consumer digital SLR camera.""", # long product text 'language' : "en", # ISO 639-1 code for the language of the text, see http://en.wikipedia.org/wiki/ISO_639-1 'datasheet_uri' : "http:/www.heppnetz.de/gr4shops/datasheet-canon_eos550D-kit.html", # The URI of the page that will contain this snippet. Only needed for the RDF/XML dump.

'product_image_uri' : "eos550d.jpg", # Product image URI 'product_thumbnail_uri' : "eos550d_small.jpg", # Product thumbnail URI 'ean' : "013803123784", # EAN-13, 13-digit UPC, or 13-digit ISBN code for the product. 'gtin14' : "0013803123784", # Global Trade Item Number (GTIN-14) for the product. Leave empty when in doubt. 'sku' : "CANON_EOS550D-KIT", # Store oder brand-specific identifier ("stock keeping unit"). Can be simply your internal ID for the item.

# OPTIONAL: Semantic Web URIs. Omit when in doubt. 'manufacturer_uri' : "http:/www.heppnetz.de/gr4shops/brands.html#canon", # Semantic URI of the manufacturer 'variant_of_uri' : "http:/www.heppnetz.de/gr4shops/datasheet-canon_eos550-series.html#datasheet", # Semantic link to baseline product 'consumable_uris': ["http:/www.heppnetz.de/gr4shops/datasheets_canon_battery.html#datasheet"], # Semantic URI of consumables 'accessory_uris' : ["http:/www.heppnetz.de/gr4shops/datasheets_canon_bag.html#datasheet"], # Semantic URI of accessories 'related_datasheets_uris' : ["http:/www.heppnetz.de/gr4shops/datasheet-canon_eos550D-maxikit.html#datasheet"], 'predecessor_uris' : ["http:/www.heppnetz.de/gr4shops/datasheet-canon_eos440D.html#datasheet"], 'successor_uris' : ["http:/www.heppnetz.de/gr4shops/datasheet-canon_eos660D.html#datasheet"],

# Ontology-based description of technical features # You can also create a brand-specific vocabulary, see shop-vocabulary.py # Prefix and URI for the vocabulary/ies to be used 'prefixes' : [{ 'ns_prefix' : "ceo", # Consumer Electronics Ontology 'ns_uri' : "http://www.ebusiness-unibw.org/ontologies/consumerelectronics/v1#"}], # Specify class URI for product type 'product_class_uri' : "http://www.ebusiness-unibw.org/ontologies/consumerelectronics/v1#DigitalCamera", 'features' : [] # we populate that list in a second step for readability }

  1. Defining semantic properties
  2. The type of the property is determined by the products ontology that you use!
  3. See http://www.ebusiness-unibw.org/ontologies/consumerelectronics/v1 for this example
  1. Boolean Property: Digital zoom: yes

digital_zoom = { 'type' : "boolean", 'uri' : "ceo:hasDigitalZoom", 'value' : "true" # true or false }

  1. Text Property: Video resolution 1024x768 pixels

video_res = { 'type' : "text", 'uri' : "ceo:hasVideoResolution", 'value' : "1024x768 pixels", 'language' : "en" # ISO 639-1 code for the language of the text, see http://en.wikipedia.org/wiki/ISO_639-1 }

  1. Qualitative Property: Display Type: LCD

display = { 'type' : "qualitative", 'uri' : "ceo:hasDisplayType", 'value_uri' : "http://www.ebusiness-unibw.org/ontologies/consumerelectronics/v1#LCD" # Must be a full URI - RDFa 1.0 quirk }

  1. Quantitative Properties
  2. Weight: 280 gram

weight = { 'type' : "quantitative", 'uri' : "ceo:hasWeight", 'value' : "280", 'unit_code' : "GRM", # Unit: gram (use UN/CEFACT common code) 'datatype' : "float" # only "float" and "integer" are supported }

  1. Focal length range: 20-120 mm

focal_length = { 'type' : "quantitative", 'uri' : "ceo:hasFocalLength", 'min_value' : "20", 'max_value' : "120", 'unit_code' : "MMT", # Unit: mm (use UN/CEFACT common code) 'datatype' : "float" }

  1. Add list of features to the product data dict

datasheet_data['features'] = [digital_zoom, video_res, display, weight, focal_length]

  1. Create RDFa snippet

template = env.get_template('template-datasheet.html') result = template.render(datasheet_data, snippet=True) # populate template r_utf8 = result.encode('UTF-8') open('output/snippet-datasheet-canon_eos550D-kit.html', 'w').write(r_utf8) # write result to file

  1. Create Full HTML+RDFa page

template = env.get_template('template-datasheet.html') title = "Best Purchase Electronics: Datasheet for the Canon EOS 550D KIT " rdf_uri = "http:/www.heppnetz.de/gr4shops/datasheets.rdf" company_name = "Best Purchase Electronics Shop Ltd." result = template.render(datasheet_data, snippet=False, rdf_uri=rdf_uri, title=title, company_name=company_name) # populate template r_utf8 = result.encode('UTF-8') open('output/datasheet-canon_eos550D-kit.html', 'w').write(r_utf8) # write result to file </python>

RDF Data Dump Template

<python>

  1. Important: When using HTML templating APIs or simple string operations for creating
  2. the RDF/XML dump file, make sure you properly encode special characters like <,>, &, '
  3. In this example, this has been done by "autoescape=True" in the statement
  4. env = Environment( loader=loader, autoescape=True)

template = env.get_template('template-rdf.rdf') rdf_data = { 'company_data' : company_data, 'product_data' : [product_data,product_data2], # List of ALL products in your shop 'brand_data' : brand_data, 'store_data' : store_data, 'company_page' : "http:/www.heppnetz.de/gr4shops/index.html", 'brands_page' : "http:/www.heppnetz.de/gr4shops/brands.html", 'stores_page' : "http:/www.heppnetz.de/gr4shops/stores.html", # Prefix and URI for the vocabulary/ies to be used 'prefixes' : [{'ns_prefix' : "ceo", 'ns_uri' : "http://www.ebusiness-unibw.org/ontologies/consumerelectronics/v1#"}], # For the RDF/XML template, those are defined globally and you MUST use the prefixes consistently accross all products and datasheet. }

result = template.render(rdf_data, minimal=False) # populate template r_utf8 = result.encode('UTF-8') open('output/goodrelations.rdf', 'w').write(r_utf8) # write result to file </python>

Vocabulary Template

<python>

  1. Creating a shop-specific GoodRelations Vocabulary
  2. It is important that special characters are properly escaped in the resulting markup! ( e.g. & as & etc.)
  1. Master data for the company

base_uri = 'http:/www.heppnetz.de/gr4shops/shop-vocabulary.html' language = "en" # ISO 639-1 code for the language of the class and property labels, see http://en.wikipedia.org/wiki/ISO_639-1 company_data = { 'company_name' : "Best Purchase Electronics Shop Ltd.", # Official name of the business making the offer

'license' : "Insert terms or conditions for using this page or URI of standard license - e.g. Creative Commons" }

  1. --------------------------------------------------
  2. Products or services categories
  3. --------------------------------------------------

categories = [

  1. Top-level Category - Clothing

{ 'id' : "clothing", # short identifier for the product category (avoid special chars) 'label' : "Clothing and Accessories", # name of the category 'image_uri': "http:/www.heppnetz.de/gr4shops/images/clothing.png" # URI of an image for the category (optional) # no supercategory_id, because this is the top-level category },

  1. T-Shirts

{ 'id' : "tshirts", 'label' : "T-Shirts and related products", 'image_uri': "http:/www.heppnetz.de/gr4shops/images/tshirts.png", 'supercategory_id' : "clothing", # The ID of the parent category, if it exists. # Note: The prefix C_ will be added by the template. },

  1. Accessories

{ 'id' : "accessories", 'label' : "Ties and Accessories", 'image_uri': "http:/www.heppnetz.de/gr4shops/images/accessories.png", 'supercategory_id' : "clothing" } ]

  1. --------------------------------------------------
  2. Quantitative ("numerical") features for products
  3. Use this pattern for features that refer to a quantitative measurement, e.g.
  4. screen diameter, weight, seating capacity, operating voltage, etc.
  5. Note: You can always safely use text features (see below) as a fall-back option if unsure.
  6. However, this reduces the market visibility of your data.
  7. --------------------------------------------------

quantitative_properties = [

  1. Weight

{ 'id' : "weight", 'label' : "Net weight of the product" # Note: The unit of measurement will be determined when describing an actual product },

  1. Operating temperature

{ 'id' : "operating_temp", 'label' : "Recommended operating temperature (can be a point value or interval)" # Note: The unit of measurement will be determined when describing an actual product } ]

  1. --------------------------------------------------
  2. Textual features for products
  3. Use this pattern for all features that hold textual values and that you cannot represent in a more granular way, e.g.
  4. color or maintenance instructions
  5. If you have a small, controlled set of allowed values, it is better to use qualitative properties
  6. and to predefine all allowed values.
  7. --------------------------------------------------

text_properties = [

  1. Color

{ 'id' : "color", 'label' : "Color of the product" },

  1. Care Instructions

{ 'id' : "care_instructions", 'label' : "Care and maintenance instructions for the product" } ]

  1. --------------------------------------------------
  2. Boolean features for products
  3. Use this pattern for all features that hold yes/no values
  4. --------------------------------------------------

boolean_properties = [

  1. All-weather

{ 'id' : "all_weather", 'label' : "Suited for all-weather use" } ]

  1. --------------------------------------------------
  2. Qualitative properties, values, and value classes
  3. --------------------------------------------------

qualitative_properties = [

  1. Material

{ 'id' : "material", 'label' : "Main material of the product" }, { 'id' : "garment_size", 'label' : "Garment size for T-Shirts and Sweaters" } ]

  1. --------------------------------------------------
  2. Value Classes
  3. --------------------------------------------------

value_classes = [

  1. Shirt Size (S, M, L, XL, XXL)

{ 'id' : "shirt_sizes", 'label' : "Garment sizes for shirts and sweaters" },

  1. Materials (Leather, Cotton, Synthetics)

{ 'id' : "material_types", 'label' : "Material types for products" } ]

  1. --------------------------------------------------
  2. Values
  3. --------------------------------------------------

values = [

  1. Shirt Sizes (S, M, L, XL, XXL)
  2. Example of ordered values

{ 'id' : "S", 'label' : "Garment size: Small (S)", 'class_id' : "shirt_sizes", # The ID of the value type 'lesser' : "M", # The ID of the next greater value # 'greater' : None # The ID of next smaller value }, { 'id' : "M", 'label' : "Garment size: Medium (M)", 'class_id' : "shirt_sizes", # The ID of the value type 'lesser' : "L", # The ID of the next greater value 'greater' : "S" # The ID of next smaller value }, { 'id' : "L", 'label' : "Garment size: Large (L)", 'class_id' : "shirt_sizes", # The ID of the value type 'lesser' : "XL", # The ID of the next greater value 'greater' : "M" # The ID of next smaller value }, { 'id' : "XL", 'label' : "Garment size: Extra Large (XL)", 'class_id' : "shirt_sizes", # The ID of the value type 'lesser' : "L", # The ID of the next greater value 'greater' : "XL" # The ID of next smaller value }, { 'id' : "XXL", 'label' : "Garment size: XXL", 'class_id' : "shirt_sizes", # The ID of the value type # 'lesser' : None, # The ID of the next greater value 'greater' : "XL" # The ID of next smaller value },

  1. Materials (Leather, Cotton, Synthetics)
  2. Example of unordered values

{ 'id' : "leather", 'label' : "Material: Genuine Leather", 'class_id' : "material_types" # The ID of the value type }, { 'id' : "cotton", 'label' : "Material: Cotton", 'class_id' : "material_types" # The ID of the value type }, { 'id' : "synthetics", 'label' : "Material: Synthetics", 'class_id' : "material_types" # The ID of the value type } ]

template = env.get_template('template-shop_vocabulary.html')

data = {'base_uri' : base_uri, 'language': language,'company_data' : company_data, 'categories' : categories, 'quantitative_properties' : quantitative_properties, 'text_properties' : text_properties, 'boolean_properties' : boolean_properties, 'qualitative_properties' : qualitative_properties, 'value_classes' : value_classes, 'values' : values}

result = template.render(data) # populate template

r_utf8 = result.encode('UTF-8') open("output/shop-vocabulary.html", 'w').write(r_utf8) # write result to file </python>

Sitemap Template

<python>

  1. Important: When using HTML templating APIs or simple string operations for creating
  2. the XML sitemap file, make sure you properly encode special characters like <,>, &, '
  3. In this example, this has been done by "autoescape=True" in the statement
  4. env = Environment( loader=loader, autoescape=True)

template = env.get_template('template-sitemap.xml')

sitemap_data = { 'uris' : [], # List with all "regular" HTML pages, will be populated later 'label' : "GoodRelations RDF Data Dump for http://www.heppnetz.de/gr4shops/", 'rdf_uri' : "http://www.heppnetz.de/gr4shops/goodrelations.rdf", # URI of the RDF data dump file 'rdf_example_product' : "http://www.heppnetz.de/gr4shops/product-canon_eos550D-kit.html", # URI of one product page 'rdf_example_company' : "http://www.heppnetz.de/gr4shops/index.html", # URI of the company page 'rdf_example_brand' : "http://www.heppnetz.de/gr4shops/brands.html", # URI of the brand page (or one example page, if you have multiple) 'rdf_example_store' : "http://www.heppnetz.de/gr4shops/stores.html", # URI of the stores page (or one example page, if you have multiple) 'rdf_example_datasheet' : "http://www.heppnetz.de/gr4shops/product-canon_eos550D-kit.html",# URI of one datasheet page 'rdf_changefreq' : "daily" # Typical change frequency of the RDF/XML data dump }

  1. Compile a list of all company, product item, and brand URIs

pages = ['http:/www.heppnetz.de/gr4shops/index.html', 'http:/www.heppnetz.de/gr4shops/brands.html', 'http:/www.heppnetz.de/gr4shops/stores.html', 'http:/www.heppnetz.de/gr4shops/product-canon_eos550D-kit.html', 'http:/www.heppnetz.de/gr4shops/datasheet-canon_eos550D-kit.html' # Add URIs of all shop item pages here # ... ]

for uri in pages: sitemap_data['uris'].append(dict(uri=uri,lastmod="2010-05-28",changefreq="daily", priority="0.5")) # 'lastmod' : "2010-05-28", # Date of last change on the page # 'changefreq' : "daily" # Typical change frequency for that page

result = template.render(sitemap_data)

  1. write result to file

r_utf8 = result.encode('UTF-8') open('output/sitemap.xml', 'w').write(r_utf8) </python>