The Eep RDF API

This is general overview of the Eep API, as well as the best documentation for it that you're going to find.

Main Files

eep.py

This is the main base of the API - it contains the extremely important Article class, which is the basic atom of all RDF stores - doing work such as parsing NTriples, serializing lists, and generally being rather helpful.

class Article(s)
This is the general "thing" in all RDF APIs.
It has some built-in variables, demonstrated in the following:-
>>> a = Article('<#x>')
>>> a
<#x>
>>> a.repr
'<#x>'
>>> a.type
'URI'
>>> a.val
'#x'

This module also contains the following functions:-

parse(s, [t])
Parses an NTriples string, s, into an Eep store, appending to any triples in the optional argument t.
serialize(triples)
Serializes an Eep store, triples, into an NTriples string.
contains(triple, store)
Tests for whether the store contains the triple "triple". If yes, it will return 1, if not it will return 0.
>>> eep.contains(eep.parse('<#x> _:y "z" .')[0], 
                 eep.parse('?p _:q <#s> .\n<#x> _:y "z" .'))
1
>>> eep.contains(eep.parse('<#l> _:m "n" .')[0], 
                 eep.parse('?p _:q <#s> .\n<#x> _:y "z" .'))
0
>>>

Using eep.py

>>> eep.parse('?p _:q <#s> .\n<#x> _:y "z" .')
[[?p, _:q, <#s>], [<#x>, _:y, "z"]]
>>> eep.serialize(eep.parse('?p _:q <#s> .\n<#x> _:y "z" .'))
'?p _:q <#s> .\n<#x> _:y "z" .'
>>> for triple in eep.parse('?p _:q <#s> .\n<#x> _:y "z" .'):
	for term in triple: print term.type, term.val, term.repr

Univar p ?p
Exivar q _:q
URI #s <#s>
URI #x <#x>
Exivar y _:y
Literal z "z"
>>> 

Note that eep.parse always returns a store! To get one triple, use eep.parse(s)[0].

query.py

This is the query module for Eep. It has simple and complex querying functionalities.

squery(q, fs)
A simple query. It queries the triple "q" (which should be a list with three article in it) against the file store fs (a list with various triples in it). It returns a store of matched triples, depending upon the variables in the query triple. It does not attempt to match variables.
rquery(q, fs)
This does the same as above, but matches variables as well. For example, try the following:-
>>> query.squery(eep.parse('?x <#y> ?x .')[0],
                 eep.parse('<#x> <#y> <#z> .'))
[[<#x>, <#y>, <#z>]]
>>> query.rquery(eep.parse('?x <#y> ?x .')[0],
                 eep.parse('<#x> <#y> <#z> .'))
[]
Since "<#x>" is not the same as "<#z>", rquery does not match it.
tquery(qs, fs, [NTriples])
This is the main query function. It queries every triple in the query store qs, against every triple in the file store fs, and performs matching. If NTriples is "1", then it will format the result as NTriples. This function can do transitive closure. For example:-
>>> print query.tquery(eep.parse('?x <#sonOf> ?y .\n?y <#sonOf> ?z .'), 
                       eep.parse("""<#Bob> <#sonOf> <#Fred> .
                                    <#Fred> <#sonOf> <#John> .
                                    <#John> <#sonOf> <#Wayne> ."""), 1)
<#Bob> <#sonOf> <#Fred> .
<#Fred> <#sonOf> <#John> .

<#Fred> <#sonOf> <#John> .
<#John> <#sonOf> <#Wayne> .

The test file for this module is querytest.py.

infer.py

This is an inference engine.

>>> store = eep.parse("""<#Bob> <#sonOf> <#Fred> .
                         <#Fred> <#sonOf> <#John> .
                         <#John> <#sonOf> <#Wayne> .""")
>>> r = infer.rule('?x <#sonOf> ?y .\n?y <#sonOf> ?z .', # log:implies
                   '?x <#grandchildOf> ?z .')
>>> for p in infer.filter(r, store): print eep.serialize(p)

<#Bob> <#grandchildOf> <#John> .
<#Fred> <#grandchildOf> <#Wayne> .
Sean B. Palmer