Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
RDFLib with RDF 1.1: XMLLiteral and HTML Literal
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Ivan Herman  
View profile  
 More options Nov 5 2012, 11:35 am
From: Ivan Herman <ivan.her...@gmail.com>
Date: Mon, 5 Nov 2012 11:35:41 -0500
Local: Mon, Nov 5 2012 11:35 am
Subject: RDFLib with RDF 1.1: XMLLiteral and HTML Literal
These are defined in

http://www.w3.org/TR/2012/rdf11-concepts/#section-XMLLiteral
http://www.w3.org/TR/2012/rdf11-concepts/#section-html

The current RDFLib does not implement equality for XML Literal datatypes (which is understandable, the old spec required a string level comparison after canonicalization). The RDF 1.1 changes the XML Literal equality notion, it is now based on DOM 3 method, namely the usage of the Dom3 isEqualNode() method.

Unfortunately, the DOM environments distributed in the Python core libraries do not implement isEqualNode(). To make things worse, RDF 1.1 has introduced a new datatype, rdf:HTML, which is very similar to XML Literals, except based on HTML5 syntax; on the other hand, html5lib does not implement isEqualNode.

That being said, implementation of isEqualNode is not terribly complicated using other DOM methods. This makes it possible to properly add XML and HTML Literals, ie, their equivalence. So I did that.

Here is what I did:

- added rdf:HTML to _RDFNamespace in rdflib/namespace.py
- added three classes to rdflib/term.py:

class XMLOrHTMLLiteral(Literal)
class XMLLiteral(XMLOrHTMLLiteral)
class HTMLLiteral(XMLOrHTMLLiteral)

A literal automatically gets the right (Python) type by a modified Literal constructor; XMLOrHTMLLiteral contains a bunch of common methods (all numerical methods like __add_ to raise a 'not a number' exception, etc), and also a common (static) _isEqualNode method.

The XMLLiteral and HTML classes redefine _toCompareValue by generating a DOM tree for the top node, using the respective parsers (minidom and html5lib) and the __eq__ makes the right comparison if all types are right.

I have also added HTMLLiteral and XMLLiteral to the __init__.py file to get the terms directly imported

Ivan

----
Ivan Herman
4, rue Beauvallon, clos St Joseph
13090 Aix-en-Provence
France
http://www.ivan-herman.net


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »