import sys import re import string import ntriples import rdfstore S, P, O, C = 0, 1, 2, 3 V, T = 0, 1 URI = 'tag:infomesh.net,2001-08-07:URI' LIT = 'tag:infomesh.net,2001-08-07:Literal' ANON = 'tag:infomesh.net,2001-08-07:Anon' RC = 'tag:infomesh.net,2001-08-07:RootContext' CONT = 'tag:infomesh.net,2001-08-07:Context' # For extensibility RDF_NS = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' EARL095_NS = 'http://www.w3.org/2001/03/earl/0.95#' EARL_NS = EARL095_NS EARL_ASSERTS = (EARL_NS+'asserts', URI) EARL_PURPOSE = (EARL_NS+'purpose', URI) EARL_FAILS = (EARL_NS+'fails', URI) EARL_RI = (EARL_NS+'repairInfo', URI) EARL_EXPR = (EARL_NS+'expectedResult', URI) EARL_DATE = (EARL_NS+'date', URI) RDF_S = (RDF_NS+'subject', URI) RDF_P = (RDF_NS+'predicate', URI) RDF_O = (RDF_NS+'object', URI) class EARL(rdfstore.RDFStore): """An EARL store.""" def __init__(self, data=[]): rdfstore.RDFStore.__init__(self, data=data) self.earl = [] def earlget(self, stid='', s='', r='', rp='', t='', b='', d=''): # print str(self.quads) for quad in self.quads: # print str(quad) if quad[P] == RDF_S: # print 'earlget quad: '+str(quad)+' matches' stid = quad[S]; s = quad[O] self.getpredicate(stid, s, r, rp, t, b, d) def getpredicate(self, stid='', s='', r='', rp='', t='', b='', d=''): # print 'getting predicate, with',stid,s,r,rp,t,b,d for quad in self.quads: if quad[P] == RDF_P and quad[S] == stid and quad[O] == EARL_FAILS: # print 'predicate quad: '+str(quad)+' matches' self.getobject(stid, s, r, rp, t, b, d) def getobject(self, stid='', s='', r='', rp='', t='', b='', d=''): for quad in self.quads: if quad[P] == RDF_O and quad[S] == stid: # print 'object quad: '+str(quad)+' matches' r = quad[O] self.getpurpose(stid, s, r, rp, t, b, d) def getpurpose(self, stid='', s='', r='', rp='', t='', b='', d=''): for quad in self.quads: if quad[P] == EARL_PURPOSE and quad[S] == r: # print 'purpose quad: '+str(quad)+' matches' t = quad[O] self.getrepairinfo(stid, s, r, rp, t, b, d) def getrepairinfo(self, stid='', s='', r='', rp='', t='', b='', d=''): for quad in self.quads: if quad[P] == EARL_RI and quad[S] == r: # print 'repairinfo quad: '+str(quad)+' matches' b = quad[O] self.getexpectedresult(stid, s, r, rp, t, b, d) def getexpectedresult(self, stid='', s='', r='', rp='', t='', b='', d=''): for quad in self.quads: if quad[P] == EARL_EXPR and quad[S] == b: # print 'expr quad: '+str(quad)+' matches' rp = quad[O] self.getdate(stid, s, r, rp, t, b, d) def getdate(self, stid='', s='', r='', rp='', t='', b='', d=''): for quad in self.quads: if quad[P] == EARL_DATE and quad[S] == s: # print 'date quad: '+str(quad)+' matches' d = quad[O] print """


The page fragment %s
FAILED the test %s on %s
description: %s
here is the repair information: %s
""" % (s[V], s[V], r[V], r[V], d[V], t[V], rp[V], rp[V]) def run(): x = ntriples.NTriples() x.parsen(sys.argv[1]) e = EARL(data=x.quads) e.earlget() # Main program if __name__ == "__main__": run() # Phew