<commit_before>from pathlib import Path

from PySide.QtCore import QObject, QSettings, Signal

from inselect.lib.templates.dwc import DWC
from inselect.lib.user_template import UserTemplate
from inselect.lib.utils import debug_print


class UserTemplateChoice(QObject):
    "Maintains the user's choice of UserTemplate"

    KEY = 'user_template_path'

    # Emitted when the user picks a new template
    template_changed = Signal()

    def __init__(self):
        super(UserTemplateChoice, self).__init__()
        self._current = DWC
        previous = QSettings().value(self.KEY)
        if previous:
            try:
                self._current = self._load(previous)
            except Exception:
                debug_print(u'Error loading user template [{0}]'.format(previous))

    def _load(sef, path):
        "Loads the UserTemplate in path"
        debug_print('UserTemplateChoice._load [{0}]'.format(path))
        with Path(path).open(encoding='utf8') as infile:
            return UserTemplate.from_file(infile)

    def load(self, path):
        "Loads the UserTemplate in path"
        debug_print('UserTemplateChoice.load [{0}]'.format(path))
        self._current = self._load(path)
        QSettings().setValue(self.KEY, str(path))
        self.template_changed.emit()

    def select_default(self):
        "Selects the default Darwin Core Archive template"
        debug_print('UserTemplateChoice.select_default'.format())
        self._current = DWC
        QSettings().setValue(self.KEY, '')
        self.template_changed.emit()

    @property
    def current(self):
        "The selected UserTemplate"
        return self._current

<commit_msg>Correct a couple of typos<commit_after>from pathlib import Path

from PySide.QtCore import QObject, QSettings, Signal

from inselect.lib.templates.dwc import DWC
from inselect.lib.user_template import UserTemplate
from inselect.lib.utils import debug_print


class UserTemplateChoice(QObject):
    "Maintains the user's choice of UserTemplate"

    KEY = 'user_template_path'

    # Emitted when the user picks a new template
    template_changed = Signal()

    def __init__(self):
        super(UserTemplateChoice, self).__init__()
        self._current = DWC
        previous = QSettings().value(self.KEY)
        if previous:
            try:
                self._current = self._load(previous)
            except Exception:
                debug_print(u'Error loading user template [{0}]'.format(previous))

    def _load(self, path):
        "Loads the UserTemplate in path"
        debug_print('UserTemplateChoice._load [{0}]'.format(path))
        with Path(path).open(encoding='utf8') as infile:
            return UserTemplate.from_file(infile)

    def load(self, path):
        "Loads the UserTemplate in path"
        debug_print('UserTemplateChoice.load [{0}]'.format(path))
        self._current = self._load(path)
        QSettings().setValue(self.KEY, str(path))
        self.template_changed.emit()

    def select_default(self):
        "Selects the default Darwin Core Archive template"
        debug_print('UserTemplateChoice.select_default')
        self._current = DWC
        QSettings().setValue(self.KEY, '')
        self.template_changed.emit()

    @property
    def current(self):
        "The selected UserTemplate"
        return self._current


{'fraction_non_alphanumeric': 0.09701492537313433, 'fraction_numerical': 0.0023880597014925373, 'mean_word_length': 2.8695150115473442, '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': '804328', 'n_tokens_mistral': 942, 'n_tokens_neox': 915, 'n_words': 234}