Tripoli + XMLRPC = Somewhat Useful?
I’ve wrapped the main Tripoli object, the impressively-named Manifold, in an XMLRPC server and created a client for it. The client needs to be connected to a TripleCallbackListener that will receive callbacks from the server when a triple matching a request pattern becomes available. This means that get and read operations are completely asynchronous.
Here’s a quick start guide to using the stuff. First, do this:
from xmlrpc import TripleCallbackListener, ManifoldServer, ManifoldClient listener = TripleCallbackListener(8023) server = ManifoldServer(8024) client = ManifoldClient(server.url, listener) server.start() listener.start()
We’ll start by requesting some things that don’t exist yet, so we can see what happens when they do.
def printTriple(triple):
print triple.subject, triple.predicate, triple.object
client.get("likes", "*", "*", "*", printTriple)
client.get("dislikes", "*", "*", "*", printTriple)
The first parameter is the name of the triple space to query, the next three are a pattern to match (all wildcards here, so any triple will do), and the last is a function to call back when a matching triple becomes available. Ours will just print whatever matching triple is returned.
Now we will create some triples in a triple space called “default”:
client.put("default", "Dominic", "likes", "Python")
client.put("default", "Dominic", "hates", "VB.Net")
client.put("default", "Python", "is", "cool")
client.put("default", "VB.Net", "is", "teh suck")
We’ll copy my likes into one triple space, “likes”, and my dislikes into another, “dislikes”. The pattern here is wildcarded for the subject and object of the triple, but requires an exact match on the predicate.
client.copy("default", "*", "likes", "*", "likes")
client.copy("default", "*", "hates", "*", "dislikes")
Our callbacks got called (hopefully)!
Note that copy returns an integer, which is the number of tuples copied. Now we’ll copy-collect the whole graph into another triple space:
count = client.copy_collect_graph("default", "Dominic", "dominic")
Let’s retrieve those triples:
for i in xrange(count):
client.get("dominic", "*", "*", "*", printTriple)
That should give you the general idea.
