Package moap :: Package doap :: Module common
[hide private]
[frames] | no frames]

Source Code for Module moap.doap.common

 1  # -*- Mode: Python -*- 
 2  # vi:si:et:sw=4:sts=4:ts=4 
 3   
 4  # common routines to parse the given list of doap files 
 5   
 6  import RDF 
 7   
8 -class RDFException(Exception):
9 pass
10
11 -class Querier:
12 - def __init__(self, location=None):
13 """ 14 Create a querier for the .doap file at the given location. 15 """ 16 # need to create a storage to create a model 17 self.storage = RDF.Storage( 18 storage_name="hashes", 19 name="test", 20 options_string="new='yes',hash-type='memory',dir='.'" 21 ) 22 if self.storage is None: 23 raise RDFException("new RDF.Storage failed") 24 25 # need to create a model to add statements to 26 self.model = RDF.Model(self.storage) 27 if self.model is None: 28 raise RDFException("new RDF.model failed") 29 30 self.parser = RDF.Parser('raptor') 31 assert self.parser 32 33 if location: 34 self.addLocation(location)
35
36 - def addLocation(self, location):
37 uri = RDF.Uri(string=location) 38 39 for s in self.parser.parse_as_stream(uri, uri): 40 self.model.add_statement(s)
41
42 - def query(self, querystring, query_language='sparql'):
43 q = RDF.Query(querystring, query_language=query_language) 44 return q.execute(self.model)
45