Category Archives: Python

Using contexts in rdflib

I am playing with rdflib, a fantastic python library to handle RDF data. I had trouble understanding how to use contexts so to partition my ConjunctiveGraph into independent subgraphs. Here is the code

import rdflib
from rdflib.Graph import Graph

conj=rdflib.ConjunctiveGraph()

NS=rdflib.Namespace(“http://example.com/#”)
NS_CTX=rdflib.Namespace(“http://example.com/context/#”)

alice=NS.alice
bob=NS.bob
charlie=NS.charlie

pizza=NS.pizza
meat=NS.meat
chocolate=NS.chocolate

loves=NS.loves
hates=NS.hates
likes=NS.likes
dislikes=NS.dislikes

love_ctx=Graph(conj.store, NS_CTX.love)
food_ctx=Graph(conj.store, NS_CTX.food)

love_ctx.add( (alice, loves, bob) )
love_ctx.add( (alice, loves, charlie) )
love_ctx.add( (bob, hates, charlie) )
love_ctx.add( (charlie, loves, bob) )

food_ctx.add( [...]

Can’t grok grok. Back to Django.

I wanted to use Grok for my future development, so I just spent a week trying to do porting of a project from Django to Grok. I had to back down.
Grok is very powerful without doubt. However, the learning curve is steep, and I am not talking about “mountain trekking” steep, I’m talking about “walking [...]

Pythonic Evolution – Part 3

You are welcome to take a look at Part 1 and Part2 of this series.
In this third part of the “silicon-based” bacterial evolution, we move to the real action. I developed a program (you can download it from here), which perform evolutive selection based on mathematical criteria.  The program has a set of rules to [...]

Pythonic Evolution – Part 2

This is the second part of a post relative to evolution. You can find the first part of the post here.
The last argument in the first post was relative to the requirements for evolution to happen. To recall, you need

An imperfect replicator, an entity able to produce a copy of itself, for example the DNA [...]

Pythonic Evolution – Part 1

This post is in different parts. The fact is that it requires quite a lot of time investment, something I really don’t have in this period.
A long time ago I wanted to play with the concept of genetic code, and how it represents nothing but a language to code for molecular machines. As the Jacquard [...]

What’s the point of inheritance in python ?

Python is a fascinating language. It makes you think. Sometimes it can destroy your beliefs.
My background is in statically typed languages. I came from C++, camped there for a while, then moved to python. I also explored Java recently.
I would like to present my case by remembering the three pillars of object oriented programming:

Encapsulation
Inheritance
Polymorphism

In particular, [...]

Multithreaded testing

Suppose you have to perform tests. Lots of tests. Functional tests, where each test could take a lot of time.
Suppose also that

you don’t want to wait three days until your tests are done
you have a massively parallel architecture available
you are using python unittest framework
you enjoy colors

What would you do?
You install testoob. This thing is [...]

Script relocatability

I wrote the first part of some research I did on script relocatability. The basic problem is to make a script and its resources relocatable. It is not meant to be correct, actually I believe there are many errors and inaccuracies, but it brings a lot of arguments to discuss. I will write the second [...]

Python 3000 alpha released

Python 3000 alpha has just been released, and I am downloading it right now. There are many changes, and a conversion tool is available to update 2.x sources to 3.0.

InspectorWordpress has prevented 1 attacks.