source: sesame_util.py @ 23:e97c3dd6107b

Revision 23:e97c3dd6107b, 1.3 KB checked in by andre.hagenbruch@rub.de, 7 years ago (diff)

Implemented link checkers, improved support for publication types...

Line 
1#!/usr/bin/env python
2# encoding: utf-8
3
4from urllib import urlopen,quote_plus,unquote
5from simplejson import loads
6
7class connection:
8    def __init__(self,url):
9        self.baseurl=url
10        self.sparql_prefix=""
11   
12    def addnamespace(self,id,ns):
13        self.sparql_prefix+='PREFIX %s:<%s>\n' % (id,ns) 
14   
15    def __getsparql__(self,method):
16        #print self.baseurl+method
17        data=urlopen(self.baseurl+method).read()
18        try:
19            result=loads(data)['results']['bindings']
20            return result
21        except:
22            return [{'error':data}];
23   
24    def repositories(self):
25        return self.__getsparql__('repositories')
26       
27    def use_repository(self,r):
28        self.repository=r
29   
30    def query(self,q):
31        q='repositories/'+self.repository+'?query='+quote_plus(self.sparql_prefix+q)
32        return self.__getsparql__(q)
33       
34    def construct_query(self,q):
35        q='repositories/'+self.repository+'?query='+quote_plus(self.sparql_prefix+q)
36        data=urlopen(self.baseurl+q).read()
37        return data
38   
39    def postdata(self,data):
40        #/openrdf-sesame/repositories/mem-rdf/statements
41        host=baseurl+'/repositories/'+self.repository+'/statements'
42        res=urlopen(host,data)
43        return res
44
45def main():
46        pass
47
48
49if __name__ == '__main__':
50        main()
Note: See TracBrowser for help on using the repository browser.