<commit_before>"""Class in charge of managing the SPARQL Endpoints."""
from SPARQLWrapper import SPARQLWrapper, JSON
import sys
import json


class Singleton(object):

    """Base singleton class."""

    _instance = None

    def __new__(cls, *args, **kwargs):
        """Instantiation."""
        if not isinstance(cls._instance, cls):
            cls._instance = object.__new__(cls, *args, **kwargs)
        return cls._instance


class SparqlEndpoint(Singleton):

    """Class in charge of managing the SPARQL Endpoints."""

    endpoints = {}
    settings = {}

    def __init__(self, settings):
        """Initialize."""
        self.settings = settings
        for k, e in self.settings["endpoints"].iteritems():
            self.endpoints[k] = SPARQLWrapper(e)

    def query(self, q, thisEndpoint="local"):
        """Query an endpoint."""
        ns = Namespace()
        sparql = self.endpoints[thisEndpoint]
        sparql.setQuery(q)
        sparql.setReturnFormat(JSON)
        try:
            results = sparql.query().convert()
            try:
                if self.settings["mirrored"] is True:
                    for row in results["results"]["bindings"]:
                        for elem in row:<commit_msg>Include nonexistant variables, so template won't raise an exception<commit_after>"""Class in charge of managing the SPARQL Endpoints."""
from SPARQLWrapper import SPARQLWrapper, JSON
import sys
import json


class Singleton(object):

    """Base singleton class."""

    _instance = None

    def __new__(cls, *args, **kwargs):
        """Instantiation."""
        if not isinstance(cls._instance, cls):
            cls._instance = object.__new__(cls, *args, **kwargs)
        return cls._instance


class SparqlEndpoint(Singleton):

    """Class in charge of managing the SPARQL Endpoints."""

    endpoints = {}
    settings = {}

    def __init__(self, settings):
        """Initialize."""
        self.settings = settings
        for k, e in self.settings["endpoints"].iteritems():
            self.endpoints[k] = SPARQLWrapper(e)

    def query(self, q, thisEndpoint="local"):
        """Query an endpoint."""
        ns = Namespace()
        sparql = self.endpoints[thisEndpoint]
        sparql.setQuery(q)
        sparql.setReturnFormat(JSON)
        try:
            results = sparql.query().convert()
            try:
                if self.settings["mirrored"] is True:
                    for row in results["results"]["bindings"]:
                        for elem in results["head"]["vars"]:
                            if elem not in row:
                                row[elem] = {}                                
{'fraction_non_alphanumeric': 0.11950394588500564, 'fraction_numerical': 0.0, 'mean_word_length': 2.1354534746760896, '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': '5403686', 'n_tokens_mistral': 726, 'n_tokens_neox': 706, 'n_words': 199}