python patch for rdflib 3.1

35 views
Skip to first unread message

Dave V

unread,
Aug 9, 2011, 11:52:41 AM8/9/11
to foresite
The following patch applied to svn revision 83 of foresite-python
enables it to work with rdflib 3.1.

Note that the foresite library functionality was not extensively
evaluated, but the tests pass and everything seems to work fine for me
on OS X python 2.7 with rdflib 3.1 and rdfextras installed with
easy_install.

cheers,
Dave V.

== snip ==

Index: foresite/serializer.py
===================================================================
--- foresite/serializer.py (revision 83)
+++ foresite/serializer.py (working copy)
@@ -5,14 +5,15 @@
from foresite import libraryName, libraryUri, libraryVersion
from utils import namespaces, OreException, unconnectedAction,
pageSize
from utils import gen_uuid, build_html_atom_content
-from rdflib import URIRef, BNode, Literal, plugin, syntax, RDF
+from rdflib import URIRef, BNode, Literal, plugin, RDF #syntax, RDF
+from rdflib.serializer import Serializer
from rdflib.util import uniq
from lxml import etree
from lxml.etree import Element, SubElement

-plugin.register('rdfa', syntax.serializers.Serializer,
'foresite.RDFaSerializer', 'RDFaSerializer')
-plugin.register('json', syntax.serializers.Serializer,
'foresite.JsonSerializer', 'JsonSerializer')
-plugin.register('pretty-json', syntax.serializers.Serializer,
'foresite.JsonSerializer', 'PrettyJsonSerializer')
+plugin.register('rdfa', Serializer, 'foresite.RDFaSerializer',
'RDFaSerializer')
+plugin.register('json', Serializer, 'foresite.JsonSerializer',
'JsonSerializer')
+plugin.register('pretty-json', Serializer, 'foresite.JsonSerializer',
'PrettyJsonSerializer')



@@ -329,7 +330,7 @@
for m in mytypes:
if m != namespaces['ore']['Aggregation'] and \
m in atypes:
- possAlt.append(r.uri)
+ possAlts.append(r.uri)

if not altDone and possAlts:
# XXX more intelligent algorithm here
Index: foresite/parser.py
===================================================================
--- foresite/parser.py (revision 83)
+++ foresite/parser.py (working copy)
@@ -3,12 +3,19 @@
from utils import namespaces, OreException, unconnectedAction,
protocolUriRe
from lxml import etree
from xml.dom import minidom
-from rdflib import StringInputSource, URIRef, plugin, syntax
+from rdflib.parser import StringInputSource
+from rdflib import URIRef, plugin, query #, syntax
+from rdflib.parser import Parser

-plugin.register('json', syntax.parsers.Parser, 'foresite.JsonParser',
'JsonParser')
+plugin.register('sparql', query.Processor,
+ 'rdfextras.sparql.processor', 'Processor')
+plugin.register('sparql', query.Result,
+ 'rdfextras.sparql.query', 'SPARQLQueryResult')

+plugin.register('json', Parser, 'foresite.JsonParser', 'JsonParser')


+
class OREParser(object):
# Take some data and produce objects/graph
def __init__(self):
Index: foresite/README.txt
===================================================================
--- foresite/README.txt (revision 83)
+++ foresite/README.txt (working copy)
@@ -23,9 +23,9 @@
And retrieve properties:

>>> a._dc.title
- [rdflib.Literal('My Aggregation', ...
+ [rdflib.term.Literal(u'My Aggregation')]
>>> a.created
- [rdflib.Literal('2008-07-10T12:00:00', ...
+ [rdflib.term.Literal(u'2008-07-10T12:00:00')]

Note that they become lists as any property can be added multiple
times.

@@ -48,7 +48,7 @@
If no URI assigned, then it will be a blank node:

>>> me.uri
- rdflib.BNode(...
+ rdflib.term.BNode(...

Create an agent with a URI:

@@ -64,13 +64,13 @@

>>> remdoc = a.get_serialization()
>>> print remdoc.data
- <entry ...
+ <atom:entry ...

Or, equivalently:

>>> remdoc = rem.get_serialization()
>>> print remdoc.data
- <entry ...
+ <atom:entry ...

Resource Maps can be created by hand:

Index: foresite/RDFaSerializer.py
===================================================================
--- foresite/RDFaSerializer.py (revision 83)
+++ foresite/RDFaSerializer.py (working copy)
@@ -1,14 +1,14 @@
from __future__ import generators

-from rdflib.syntax.serializers import Serializer
+from rdflib.serializer import Serializer

-from rdflib.URIRef import URIRef
-from rdflib.Literal import Literal
-from rdflib.BNode import BNode
+from rdflib.term import URIRef
+from rdflib.term import Literal
+from rdflib.term import BNode

from rdflib.util import uniq
from rdflib.exceptions import Error
-from rdflib.syntax.xml_names import split_uri
+#from rdflib.syntax.xml_names import split_uri

from xml.sax.saxutils import quoteattr, escape


Robert Sanderson

unread,
Aug 9, 2011, 12:01:35 PM8/9/11
to fore...@googlegroups.com
Very nice! Many thanks for your work on this!

Would you prefer to just have commit access to the svn rather than
sending patches? :)

Rob

> --
> You received this message because you are subscribed to the Google Groups "foresite" group.
> To post to this group, send an email to fore...@googlegroups.com.
> To unsubscribe from this group, send email to foresite+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/foresite?hl=en-GB.
>
>

Dave Vieglais

unread,
Aug 9, 2011, 12:12:30 PM8/9/11
to fore...@googlegroups.com
Sure, though I don't anticipate many changes will be required beyond this quick fix.

thanks,
Dave V.

Reply all
Reply to author
Forward
0 new messages