<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function, unicode_literals
from base.setting.utility import Rank, RankArbitrator as Arbitrator
from util.json_load import JsonLoader

import sys
reload(sys)
sys.setdefaultencoding('UTF8')  # need this for str(pattern_of_type_unicode) can work


class Sentence(object):

    def __init__(self, rank, restrict, default_values):
        self.rank = rank
        self.__restrict = restrict
        self.__default_values = default_values

    def get_default_value(self, var_name):
        assert var_name in self.__default_values
        return self.__default_values[var_name]

    def satisfy(self, pattern_name, pattern_group_name):
        if not self.__restrict:
            return True
        return self.__restrict in [pattern_name, pattern_group_name]

    def print(self):
        self.rank.print('\t\t')
        if self.__restrict:
            print('\t\t', self.__restrict)

    @staticmethod
    def create(data):
        assert isinstance(data, dict)
        rank = Rank.create(
            data["rank"]) if "rank" in data else Rank.create_default()
        restrict = str(data["restrict"]) if "restrict" in data else None
        default_values = {}<commit_msg>Add message when default phrase value requirement assertion is met<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function, unicode_literals
from base.setting.utility import Rank, RankArbitrator as Arbitrator
from util.json_load import JsonLoader

import sys
reload(sys)
sys.setdefaultencoding('UTF8')  # need this for str(pattern_of_type_unicode) can work


class Sentence(object):

    def __init__(self, rank, restrict, default_values):
        self.rank = rank
        self.__restrict = restrict
        self.__default_values = default_values

    def get_default_value(self, var_name):
        assert var_name in self.__default_values, "need specify default value of \'%s\' in phrase" % var_name
        return self.__default_values[var_name]

    def satisfy(self, pattern_name, pattern_group_name):
        if not self.__restrict:
            return True
        return self.__restrict in [pattern_name, pattern_group_name]

    def print(self):
        self.rank.print('\t\t')
        if self.__restrict:
            print('\t\t', self.__restrict)

    @staticmethod
    def create(data):
        assert isinstance(data, dict)
        rank = Rank.create(
            data["rank"]) if "rank" in data else Rank.create_default()
        restrict = str(data["restrict"]) if "restrict" in data else None
        default_values = {}
{'fraction_non_alphanumeric': 0.09363153904473086, 'fraction_numerical': 0.001516300227445034, 'mean_word_length': 3.1105919003115265, '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': '3356477', 'n_tokens_mistral': 768, 'n_tokens_neox': 749, 'n_words': 212}