<commit_before>from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

import os.path

import yaml
import pkg_resources

from . import permissive
from . import _panphon


class Collapser(object):
    def __init__(self, tablename='dogolpolsky_prime.yml', feature_set='spe+', feature_model='strict'):
        fm = {'strict': _panphon.FeatureTable,
              'permissive': permissive.PermissiveFeatureTable}
        self.fm = fm[feature_model](feature_set=feature_set)
        self.rules = self._load_table(tablename)

    def _load_table(self, tablename):
        fn = os.path.join('data', tablename)
        fn = pkg_resources.resource_filename(__name__, fn)
        with open(fn, 'r') as f:
            rules = []
            table = yaml.load(f.read())
            for rule in table:
                rules.append(_panphon.fts(rule['def']), rule['label'])
        return rules

    def collapse(self, s):
        segs = []
        for seg in self.fm.seg_regex.findall(s):<commit_msg>Sorted imports<commit_after>from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

import os.path

import pkg_resources
import yaml

from . import _panphon, permissive


class Collapser(object):
    def __init__(self, tablename='dogolpolsky_prime.yml', feature_set='spe+', feature_model='strict'):
        fm = {'strict': _panphon.FeatureTable,
              'permissive': permissive.PermissiveFeatureTable}
        self.fm = fm[feature_model](feature_set=feature_set)
        self.rules = self._load_table(tablename)

    def _load_table(self, tablename):
        fn = os.path.join('data', tablename)
        fn = pkg_resources.resource_filename(__name__, fn)
        with open(fn, 'r') as f:
            rules = []
            table = yaml.load(f.read())
            for rule in table:
                rules.append(_panphon.fts(rule['def']), rule['label'])
        return rules

    def collapse(self, s):
        segs = []
        for seg in self.fm.seg_regex.findall(s):
{'fraction_non_alphanumeric': 0.11304347826086956, 'fraction_numerical': 0.0, 'mean_word_length': 2.7248201438848922, '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': '4696848', 'n_tokens_mistral': 656, 'n_tokens_neox': 617, 'n_words': 134}