#This is a Python comment (starts with "#")
#Triple quotes in Python allow a string definition that spans multiple lines
rssstring = """<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/metadata/dublin_core#"
xmlns="http://purl.org/rss/1.0/"
>
<channel rdf:about="http://opentechnology.org/rssgateway.rss">
<title>OpenTechnology.org</title>
<description>
An XML community site for threaded discussion and knowledge management, using XML, DOM, XSLT, and RDF.
</description>
</channel>
<image rdf:about="http://opentechnology.org/images/openlogo.gif">
<inchannel rdf:resource="http://opentechnology.org/rssgateway.rss"/>
<title>OpenTechnology.org Logo</title>
<link>http://opentechnology.org</link>
<url>http://opentechnology.org/images/openlogo.gif</url>
</image>
<item rdf:about="http://www.opentechnology.org/talk/view.html?uri=urn:uuid:10a0b01-0-60b-a07-b090305f">
<inchannel rdf:resource="http://opentechnology.org/rssgateway.rss"/>
<title>RDF Inference Language (RIL)</title>
<link>http://www.opentechnology.org/talk/view.html?uri=urn:uuid:10a0b01-0-60b-a07-b090305f</link>
<description>
Discussion of RIL, a language for performing expert-systems-like inferencing on RDF data.
</description>
</item>
</rdf:RDF>
"""
#Using the memory driver, the resulting model will not be not persistent
from Ft.Rdf.Drivers import Memory
#Create an instance of the memory "database"
db = Memory.CreateDb('')
#Begin transaction. Optional (and usually omitted) in the memory driver
#Required for Database drivers
db.begin()
#Create a model with base URI of 'http://opentechnology.org/rsssample'
from Ft.Rdf import Model
model = Model.Model('http://opentechnology.org/rsssample', db)
#complete(None, None, None) returns all statements the model. It works
#On a pattern match basis with "None" acting as a wild-card matching any value
#The model starts out being empty
#OUTPUT 1
print model.complete(None, None, None)
#Read an RDF serialization into the model from DOM
from xml.dom.ext.reader import Sax2
doc = Sax2.FromXml(rssstring)
from Ft.Rdf.Serializers.Dom import Serializer
serializer = Serializer()
serializer.deserialize(model, doc, '')
#OUTPUT 2
print model.complete(None, None, None)
#OUTPUT 3
print model.complete(None, 'http://purl.org/rss/1.0/#title', None)
item_statements = model.complete('http://www.opentechnology.org/talk/view.html?uri=urn:uuid:10a0b01-0-60b-a07-b090305f', None, None)
for stmt in item_statements:
model.remove(stmt)
#Now write it all back out in XML
outdoc = serializer.serialize(model)
import xml.dom.ext
#OUTPUT 4
xml.dom.ext.PrettyPrint(outdoc)
xml.dom.ext.ReleaseNode(outdoc)
xml.dom.ext.ReleaseNode(doc)
#Commit Transaction. Optional (and usually omitted) in the memory driver
#Required for Database drivers
db.commit()