<commit_before>import webapp2
from config.config import _CLIENT_TOKEN
from flankers.graphtools import query, store_triples

__author__ = ['niels', 'Lorenzo']


class Querying(webapp2.RequestHandler):
    """
    /sparql GET: responds to SPARQL queries using the ?query= parameter
    /sparql POST: endpoint to store triples in the datastore
    """
    def get(self):
        if self.request.get('query'):
            self.response.headers['Access-Control-Allow-Origin'] = '*'
            self.response.headers['Content-Type'] = 'application/sparql-results+json; charset=utf-8'
            print(self.request.get('query'))
            return self.response.write(query(self.request.get('query')))
        return self.response.write("Query not defined")

    def post(self):
        self.response.headers['Access-Control-Allow-Origin'] = '*'
        if self.request.get('token') == _CLIENT_TOKEN:
            # use graphtools.store_triples()
            app_graph, cache_graph = store_triples(self.request.get('triple'))
            return self.response.write("GRAPH STORED OK: {} triples".format(len(cache_graph)))
        return self.response.set_status(405)<commit_msg>sparql handler: support multi graph shard<commit_after>import webapp2
from config.config import _CLIENT_TOKEN
from flankers.graphtools import query, store_triples

__author__ = ['niels', 'Lorenzo']


class Querying(webapp2.RequestHandler):
    """
    /sparql GET: responds to SPARQL queries using the ?query= parameter
    /sparql POST: endpoint to store triples in the datastore
    """
    def get(self):
        if self.request.get('query'):
            self.response.headers['Access-Control-Allow-Origin'] = '*'
            self.response.headers['Content-Type'] = 'application/sparql-results+json; charset=utf-8'
            print(self.request.get('query'))
            return self.response.write(query(self.request.get('query')))
        return self.response.write("Query not defined")

    def post(self):
        self.response.headers['Access-Control-Allow-Origin'] = '*'
        if self.request.get('token') == _CLIENT_TOKEN:
            # use graphtools.store_triples()
            data = self.request.get('triple')
            graph_id = self.request.get('graph_id')
            app_graph, cache_graph = store_triples(data, graph_id)
            return self.response.write("GRAPH STORED OK: {} triples".format(len(cache_graph)))
        return self.response.set_status(405)
{'fraction_non_alphanumeric': 0.12795436022819887, 'fraction_numerical': 0.004889975550122249, 'mean_word_length': 3.2109777015437393, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5129913', 'n_tokens_mistral': 744, 'n_tokens_neox': 728, 'n_words': 145}