SuRF Object - RDF Mapper

SuRF is a python Object - RDF Mapper based on the python rdflib library.

It exposes the RDF triple sets as sets of resources and seamlessly integrates them into the Object Oriented paradigm of python.

Project Google Code site: http://code.google.com/p/surfrdf/

Documentation: packages.python.org/SuRF/

GoodRelations Support

SuRF includes support for the GoodRelations vocabulary,allowing access to GoodRelations element using shortcuts such as the following:

# 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

GoodRelations 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

References