<commit_before>from data_models.core import NamedEntity, BaseDataModel


class LobbyAgency(NamedEntity):
    def __init__(self, name=None):
        NamedEntity.__init__(self)
        self.exists = False
        self.label = "Lobby Agency"
        self.primary_attribute = "name"
        self.name = name
        self.exists = self.fetch(
            "Named Entity", self.primary_attribute, self.name
        )
        if self.exists:
            self.clients = self._get_clients()
            self.employees = self._get_employees()
            count = self._get_counts()
            self.client_count = count[0]
            self.employee_count = count[1]

    def _get_clients(self):
        results = []
        search_string = u"""
            MATCH (f:`Lobbying Firm` {{name: "{0}"}})
            MATCH (f)-[:REGISTERED_LOBBYIST]-(r) with f, r
            MATCH (r)-[:HIRED]-(c) with f, r, c
            MATCH (c)-[x]-() with f, r, c, x
            RETURN c.name as name, labels(c) as labels, count(x) as weight
            ORDER BY weight DESC
        """.format(self.name)
        output = self.query(search_string)
        for entry in output:
            detail = {
                "name": entry["name"],
                "weight": entry["weight"],
                "labels": entry["labels"]
            }
            results.append(detail)
        return results

    def _get_employees(self):
        results = []
        search_string = u"""
            MATCH (f:`Lobbying Firm` {{name: "{0}"}})
            MATCH (f)-[:REGISTERED_LOBBYIST]-(r) with f, r
            MATCH (r)-[:WORKS_FOR]-(e) with f, r, e
            RETURN e.name as name, labels(e) as labels
        """.format(self.name)
        output = self.query(search_string)
        for entry in output:
            detail = {
                "name": entry["name"],
                "labels": entry["labels"]
            }
            results.append(detail)
        return results

    def _get_counts(self):
        search_string = u"""
            MATCH (f:`Lobbying Firm` {{name: "{0}"}})
            MATCH (f)-[:REGISTERED_LOBBYIST]-(r) with f, r
            OPTIONAL MATCH (r)-[:HIRED]-(c) with f, r, c
            OPTIONAL MATCH (r)-[:WORKS_FOR]-(e) with f, r, c, e
            RETURN count(c) as clients, count(e) as employees
        """.format(self.name)
        output = self.query(search_string)
        return output[0]["clients"], output[0]["employees"]

    def set_lobbyist_details(self, properties=None):
        properties = self._add_namedentity_properties(properties)
        labels = ["Lobby Agency", "Named Entity"]
        self.set_node_properties(properties, labels)


class LobbyAgencies(BaseDataModel):
    def __init__(self):
        BaseDataModel.__init__(self)
        self.count = self._get_count()

    def get_all(self):
        search_string = u"""
            MATCH (f:`Lobbying Firm`)
            MATCH (f)-[:REGISTERED_LOBBYIST]-(r) with f, r
            OPTIONAL MATCH (r)-[:HIRED]-(c) with f, r, c
            OPTIONAL MATCH (r)-[:WORKS_FOR]-(e) with f, r, c, e
            RETURN f.name, count(c) as clients, count(e) as employees, labels(f)
            ORDER BY clients DESC
        """
        search_result = self.query(search_string)
        return search_result

    def _get_count(self):
        search_string = u"""
            MATCH (f:`Lobbying Firm`)
            RETURN count(f)
        """
        search_result = self.query(search_string)
        return search_result[0][0]<commit_msg>lobby agency data model workaround<commit_after>from data_models.core import NamedEntity, BaseDataModel


class LobbyAgency(NamedEntity):
    def __init__(self, name=None):
        NamedEntity.__init__(self)
        self.exists = False
        self.label = "Lobby Agency"
        self.primary_attribute = "name"
        self.name = name
        self.exists = self.fetch(
            "Named Entity", self.primary_attribute, self.name
        )
        if self.exists:
            self.clients = self._get_clients()
            self.employees = self._get_employees()
            count = self._get_counts()
            self.client_count = count[0]
            self.employee_count = count[1]

    def _get_clients(self):
        results = []
        search_string = u"""
            MATCH (f:`Lobby Agency` {{name: "{0}"}})
            MATCH (f)-[:REGISTERED_LOBBYIST]-(r) with f, r
            MATCH (r)-[:HIRED]-(c) with f, r, c
            MATCH (c)-[x]-() with f, r, c, x
            RETURN c.name as name, labels(c) as labels, count(x) as weight
            ORDER BY weight DESC
        """.format(self.name)
        output = self.query(search_string)
        for entry in output:
            detail = {
                "name": entry["name"],
                "weight": entry["weight"],
                "labels": entry["labels"]
            }
            results.append(detail)
        return results

    def _get_employees(self):
        results = []
        search_string = u"""
            MATCH (f:`Lobby Agency` {{name: "{0}"}})
            MATCH (f)-[:REGISTERED_LOBBYIST]-(r) with f, r
            MATCH (r)-[:WORKS_FOR]-(e) with f, r, e
            RETURN e.name as name, labels(e) as labels
        """.format(self.name)
        output = self.query(search_string)
        for entry in output:
            detail = {
                "name": entry["name"],
                "labels": entry["labels"]
            }
            results.append(detail)
        return results

    def _get_counts(self):
        search_string = u"""
            MATCH (f:`Lobby Agency` {{name: "{0}"}})
            MATCH (f)-[:REGISTERED_LOBBYIST]-(r) with f, r
            OPTIONAL MATCH (r)-[:HIRED]-(c) with f, r, c
            OPTIONAL MATCH (r)-[:WORKS_FOR]-(e) with f, r, c, e
            RETURN count(c) as clients, count(e) as employees
        """.format(self.name)
        output = self.query(search_string)
        return output[0]["clients"], output[0]["employees"]

    def set_lobbyist_details(self, properties=None):
        properties = self._add_namedentity_properties(properties)
        labels = ["Lobby Agency", "Named Entity"]
        self.set_node_properties(properties, labels)


class LobbyAgencies(BaseDataModel):
    def __init__(self):
        BaseDataModel.__init__(self)
        self.count = self._get_count()

    def get_all(self):
        search_string = u"""
            MATCH (f:`Lobby Agency`)
            MATCH (f)-[:REGISTERED_LOBBYIST]-(r) with f, r
            OPTIONAL MATCH (r)-[:HIRED]-(c) with f, r, c
            OPTIONAL MATCH (r)-[:WORKS_FOR]-(e) with f, r, c, e
            RETURN f.name, count(c) as clients, count(e) as employees, labels(f)
            ORDER BY clients DESC
        """
        search_result = self.query(search_string)
        return search_result

    def _get_count(self):
        search_string = u"""
            MATCH (f:`Lobby Agency`)
            RETURN count(f)
        """
        search_result = self.query(search_string)
        return search_result[0][0]
{'fraction_non_alphanumeric': 0.12934472934472935, 'fraction_numerical': 0.002564102564102564, 'mean_word_length': 1.9388865634156551, 'pattern_counts': {'":': 10, '<': 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': '3377092', 'n_tokens_mistral': 2186, 'n_tokens_neox': 2103, 'n_words': 519}