<commit_before>import yaml
import inflection
import re
import os

from collections import OrderedDict


class QuestionsLoader(object):

    def __init__(self,
                 manifest='questions_manifest.yml',
                 questions_dir=''):

        with open(manifest, "r") as file:
            section_order = yaml.load(file)

        self._directory = questions_dir
        self._question_cache = {}
        self.sections = [
            self.__populate_section__(s) for s in section_order
        ]

    def get_section(self, requested_section):

        for section in self.sections:
            if section["id"] == requested_section:
                return section

    def get_question(self, question):

        if question not in self._question_cache:

            question_file = self._directory + question + ".yml"

            if not os.path.isfile(question_file):
                self._question_cache[question] = {}
                return {}

            with open(question_file, "r") as file:
                question_content = yaml.load(file)

            question_content["id"] = question

            # wrong way to do it? question should be shown by default.
            question_content["depends_on_lots"] = (
                self.__get_dependent_lots__(question_content["dependsOnLots"])
            ) if "dependsOnLots" in question_content else (
                ["saas", "paas", "iaas", "scs"]
            )

            self._question_cache[question] = question_content

        return self._question_cache[question]

    def __populate_section__(self, section):
        section["questions"] = [
            self.get_question(q) for q in section["questions"]
        ]
        all_dependencies = [
            q["depends_on_lots"] for q in section["questions"]
        ]
        section["depends_on_lots"] = [
            y for x in all_dependencies for y in x  # flatten array
        ]
        section["id"] = self.__make_id__(section["name"])
        return section

    def __make_id__(self, name):
        return inflection.underscore(
            re.sub("\s", "_", name)
        )

    def __get_dependent_lots__(self, dependent_lots_as_string):
        return [
            x.strip() for x in dependent_lots_as_string.lower().split(",")
        ]<commit_msg>Rename private methods in questions.py helper<commit_after>import yaml
import inflection
import re
import os

from collections import OrderedDict


class QuestionsLoader(object):

    def __init__(self,
                 manifest='questions_manifest.yml',
                 questions_dir=''):

        with open(manifest, "r") as file:
            section_order = yaml.load(file)

        self._directory = questions_dir
        self._question_cache = {}
        self.sections = [
            self._populate_section_(s) for s in section_order
        ]

    def get_section(self, requested_section):

        for section in self.sections:
            if section["id"] == requested_section:
                return section

    def get_question(self, question):

        if question not in self._question_cache:

            question_file = self._directory + question + ".yml"

            if not os.path.isfile(question_file):
                self._question_cache[question] = {}
                return {}

            with open(question_file, "r") as file:
                question_content = yaml.load(file)

            question_content["id"] = question

            # wrong way to do it? question should be shown by default.
            question_content["depends_on_lots"] = (
                self._get_dependent_lots_(question_content["dependsOnLots"])
            ) if "dependsOnLots" in question_content else (
                ["saas", "paas", "iaas", "scs"]
            )

            self._question_cache[question] = question_content

        return self._question_cache[question]

    def _populate_section_(self, section):
        section["questions"] = [
            self.get_question(q) for q in section["questions"]
        ]
        all_dependencies = [
            q["depends_on_lots"] for q in section["questions"]
        ]
        section["depends_on_lots"] = [
            y for x in all_dependencies for y in x  # flatten array
        ]
        section["id"] = self._make_id_(section["name"])
        return section

    def _make_id_(self, name):
        return inflection.underscore(
            re.sub("\s", "_", name)
        )

    def _get_dependent_lots_(self, dependent_lots_as_string):
        return [
            x.strip() for x in dependent_lots_as_string.lower().split(",")
        ]
{'fraction_non_alphanumeric': 0.09574468085106383, 'fraction_numerical': 0.0, 'mean_word_length': 2.0692871419053964, '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': '4298388', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1219, 'n_words': 295}