Esempio n. 1
0
    def load_graph(self):
        result = 0
        end = False
        it = 1
        offset = 0

        while not end:
            query = 'SELECT DISTINCT * WHERE { ?s ?p ?o } OFFSET %s LIMIT %s' % (str(offset), str(self.LIMIT))
            params = {'query': query, 'output': 'json'}
            headers = {'Accept': 'application/json'}
            self.sparql_http_connection.request('GET', self.route + '?' + urllib.urlencode(params), "", headers )
            response = self.sparql_http_connection.getresponse()
            if response.status == 200:
                data = response.read()
                json_data = json.loads(data)
                if len(json_data['results']['bindings']) > 0:
                    for json_triple in json_data['results']['bindings']:
                        subject = URIRef(json_triple['s']['value'])
                        predicate = URIRef(json_triple['p']['value'])
                        if json_triple['o']['type'] == "literal":
                            object = Literal(json_triple['o']['value'])
                        else:
                            object = URIRef(json_triple['o']['value'])
                        self.graph.add((subject, predicate, object))
                else:
                    end = True
            offset = (self.LIMIT * it)
            it = it + 1
            self.graph.commit()
        SWAnalyzer.load_graph(self)
Esempio n. 2
0
    def load_graph(self):
        if self.store is not None:            
            result = 0
            end = False
            it = 1
            offset = 0

            while not end:
                query = 'SELECT DISTINCT * WHERE { ?s ?p ?o } OFFSET %s LIMIT %s' % (str(offset), str(self.LIMIT))
                #params = {'query': query, 'output': 'json', 'format': 'application/sparql-results+json'}
                #headers = {'Accept': 'application/json, application/sparql-results+json'}
                #self.sparql_http_connection.request('GET', self.route + '?' + urllib.urlencode(params))
                #response = self.sparql_http_connection.getresponse()
                params = urllib.urlencode({'query': query, 'output': 'json', 'format': 'application/sparql-results+json'})
                request = urllib2.Request(self.sparql_endpoint + '?' + params)
                request.add_header('Accept', 'application/rdf+xml, application/sparql-results+json')
                response = urllib2.urlopen(request)

                if response.code == 200:
                    data = response.read()
                    json_data = json.loads(data)
                    if len(json_data['results']['bindings']) > 0:
                        for json_triple in json_data['results']['bindings']:
                            subject = URIRef(json_triple['s']['value'])
                            predicate = URIRef(json_triple['p']['value'])
                            if json_triple['o']['type'] == "literal":
                                object = Literal(json_triple['o']['value'])
                            else:
                                object = URIRef(json_triple['o']['value'])
                            self.graph.add((subject, predicate, object))
                    else:
                        end = True
                offset = (self.LIMIT * it)
                it = it + 1
                self.graph.commit()

        SWAnalyzer.load_graph(self)
Esempio n. 3
0
 def open(self):
     SWAnalyzer.open(self)
Esempio n. 4
0
 def __init__(self, path, identifier, configstring, proxy=None):
     SWAnalyzer.__init__(self, identifier, configstring, proxy=proxy)
     self.path = path
Esempio n. 5
0
 def load_graph(self):
     self.graph.parse(self.path)
     self.graph.commit()
     SWAnalyzer.load_graph(self)
Esempio n. 6
0
 def close(self):
     SWAnalyzer.close(self)
Esempio n. 7
0
 def open(self):
     SWAnalyzer.open(self)
     self.host, self.port, self.route = ld_utils.get_host_port_route(self.sparql_endpoint)
Esempio n. 8
0
 def __init__(self, sparql_endpoint, identifier=None, configstring=None, store=None, proxy=None, subprocess=True):
     SWAnalyzer.__init__(self, sparql_endpoint, identifier, configstring, store, proxy, subprocess)
Esempio n. 9
0
 def close(self):
     SWAnalyzer.close(self)
     self.sparql_http_connection.close()
Esempio n. 10
0
 def open(self):
     SWAnalyzer.open(self)
     self.host, self.port, self.route = ld_utils.get_host_port_route(self.sparql_endpoint)
     self.sparql_http_connection = httplib.HTTPConnection(self.host, self.port)
Esempio n. 11
0
 def __init__(self, sparql_endpoint):
     SWAnalyzer.__init__(self)
     self.sparql_endpoint = sparql_endpoint