Dear all:
If you are developing any kind of GoodRelations-related applications in
Python, I can recommend very much the combination of the two libraries
- RDFlib [1] for handling RDF in Python and
- SuRF [2] as an object mapper for RDF/OWL entities.
RDFlib provides a nice, "pythonic" framework for parsing, querying, or
generating RDF data, including support for RDF/XML, RDFa, and Turtle syntax.
SuRF turns RDF nodes and properties into Python classes and instances so
that you can access them in a clean, straightforward fashion.
See below for an example of loading two company profiles using rdflib
and SuRF and printing a few key facts to the screen.
SuRF has just added support for the GoodRelations vocabulary, i.e. you
can now access any GoodRelations element using shortcuts as shown below:
# Define a Python class for the OWL Classes gr:Offering and
gr:BusinessEntity
Offering = session.get_class(ns.GR['Offering'])
BusinessEntity = session.get_class(ns.GR['BusinessEntity '])
# Get an iterator for all instances of gr:Offering in the graph
all_offers = Offering.all()
# Get an iterator for all instances of gr:Offering in the graph
all_companies = BusinessEntity.all()
for company in all_companies:
print "Business Entity found: %s " % company.subject
print "Legal Name: %s" % company.gr_legalName.first
Thanks to Cosmin Basca for adding GoodRelations support so quickly, and
to Daniel Krech and all the other RDFlib contributors.
Best wishes
Martin Hepp
[1]
http://www.rdflib.net/[2]
http://code.google.com/p/surfrdf/Complete Example:
--------------------------------
from surf import *
store = Store( reader='rdflib',
writer='rdflib',
rdflib_store = 'IOMemory')
session = Session(store)
# Good Relations Namespace is now predefined in SuRF :-)
# ns.register(gr='
http://purl.org/goodrelations/v1#')
print 'Load RDF data'
store.load_triples(source='
http://purl.org/goodrelations/v1.owl')
store.load_triples(source='
http://www.collibra.com/semanticweb.rdf')
store.load_triples(source='
http://www.jarltech.de/semanticweb.rdf')
# Define a Python class for the OWL Classes gr:Offering and
gr:BusinessEntity
Offering = session.get_class(ns.GR['Offering'])
BusinessEntity = session.get_class(ns.GR['BusinessEntity '])
# Get an iterator for all instances of gr:Offering in the graph
all_offers = Offering.all()
print 'Found %d offers '%(len(all_offers))
for offer in all_offers :
print "Text: %s" % offer.rdfs_comment.first
print "URI: %s" % offer.rdfs_seeAlso.first
print "Eligible regions: ",
regions = offer.gr_eligibleRegions
if len(regions) == 0:
print "None specified"
else:
for region in regions:
print region,
print
print
# Get an iterator for all instances of gr:Offering in the graph
all_companies = BusinessEntity.all()
for company in all_companies:
print "Business Entity found: %s " % company.subject
print "Legal Name: %s" % company.gr_legalName.first
--
--------------------------------------------------------------
martin hepp
e-business & web science research group
universitaet der bundeswehr muenchen
e-mail:
hepp at ebusiness-unibw.orgphone: +49-(0)89-6004-4217
fax: +49-(0)89-6004-4620
www:
http://www.unibw.de/ebusiness/ (group)
http://www.heppnetz.de/ (personal)
skype: mfhepp
twitter: mfhepp
Check out GoodRelations for E-Commerce on the Web of Linked Data!
=================================================================
Project page:
http://purl.org/goodrelations/Resources for developers:
http://www.ebusiness-unibw.org/wiki/GoodRelationsWebcasts:
Overview -
http://www.heppnetz.de/projects/goodrelations/webcast/How-to -
http://vimeo.com/7583816Recipe for Yahoo SearchMonkey:
http://www.ebusiness-unibw.org/wiki/GoodRelations_and_Yahoo_SearchMonkeyTalk at the Semantic Technology Conference 2009:
"Semantic Web-based E-Commerce: The GoodRelations Ontology"
http://www.slideshare.net/mhepp/semantic-webbased-ecommerce-the-goodrelations-ontology-1535287Overview article on Semantic Universe:
http://www.semanticuniverse.com/articles-semantic-web-based-e-commerce-webmasters-get-ready.htmlTutorial materials:
ISWC 2009 Tutorial: The Web of Data for E-Commerce in Brief: A Hands-on Introduction to the GoodRelations Ontology, RDFa, and Yahoo! SearchMonkey
http://www.ebusiness-unibw.org/wiki/Web_of_Data_for_E-Commerce_Tutorial_ISWC2009