<commit_before># Three clause BSD license: https://opensource.org/licenses/BSD-3-Clause

# Copyright (c) 2017, <NAME> All rights reserved.

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:

# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.

# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.

# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

__author__ = "<NAME>"
__copyright__ = "Copyright (c) 2017 <NAME>"
__license__ = "BSD-3-Clause"

import datetime
import calendar
import collections

import rts23_table2

import locale
locale.setlocale(locale.LC_ALL, '')


class TaxonomyNode(object):
    """
    This class defines the API which much be implemented by all nodes.
    Essentially this means requiring that every node knows it's parent
    and children.  Handy for presenting the taxonomy as a tree.
    """

    @property
    def parent(self):
        raise NotImplementedError('parent() must be implemented in concrete subclass {my_class}'
                                  .format(my_class=type(self)))

    @parent.setter
    def parent(self, value):
        raise NotImplementedError('*setter* of @property parent() must be implemented in concrete subclass {my_class}'
                                  .format(my_class=type(self)))

    @property
    def children(self):
        raise NotImplementedError('children() must be implemented in concrete subclass {my_class}'
                                  .format(my_class=type(self)))

    @property
    def parents(self):
        """
        I return the list of my parents with the root first and me last.
        """
        if self.parent is None:
            return [self]
        else:
            return self.parent.parents.append(self)


class AssetClassSet(TaxonomyNode):

    def __init__(self, version_id, asset_classes=None):
        self.version_id = version_id
        self._asset_classes = []
        given_asset_classes = asset_classes or []
        self._asset_classes.extend(given_asset_classes)

    @property
    def asset_classes(self):
        return self._asset_classes

    def leaf_for(self, subject):
        """
        This method simply delegates to the newer visitor-pattern based classification_for()
        Consider this method deprecated.
        """
        return self.classification_for(subject)

    def classification_for(self, subject):
        classification = Classification(subject=subject, root=self)
        asset_class = self.asset_class_by_name(subject.asset_class_name)
        if asset_class:
            asset_class.extend_classification(classification)
        else:
            classification.errors.append("RTS 2 has no Asset Class named '{asset_class_name}'.".format(
                asset_class_name=subject.asset_class_name
            ))
        return classification

    def asset_class_by_name(self, asset_class_name):
        return next((asset_class
                     for asset_class
                     in self.asset_classes
                     if asset_class_name == asset_class.name),
                    None)

    def append(self, asset_class):
        self._asset_classes.append(asset_class)

    def display(self, prefix=""):
        target = "The set of all Asset Classes:"
        for asset_class in self._asset_classes:
            target += "\n"
            target += asset_class.display(prefix=prefix+'- ')
        return target

    @property
    def parent(self):
        return None

    @property
    def children(self):
        return self.asset_classes

    def all_sub_asset_classes(self):
        sub_asset_class_list = []
        for asset_class in self.children:
            sub_asset_class_list.extend(asset_class.children)
        return sub_asset_class_list

<commit_msg>Building sample trade generation logic.<commit_after># Three clause BSD license: https://opensource.org/licenses/BSD-3-Clause

# Copyright (c) 2017, <NAME> All rights reserved.

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:

# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.

# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.

# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

__author__ = "<NAME>"
__copyright__ = "Copyright (c) 2017-2018 <NAME>"
__license__ = "BSD-3-Clause"

import datetime
import calendar
import collections
import random

import rts23_table2

import locale
locale.setlocale(locale.LC_ALL, '')


class SampleTrade(object):
    """
    This class is used by the test data generation code.  The classes
    have no instance variables by default, they are force fed the 
    values they need.
    """
    pass


class TaxonomyNode(object):
    """
    This class defines the API which much be implemented by all nodes.
    Essentially this means requiring that every node knows it's parent
    and children.  Handy for presenting the taxonomy as a tree.
    """

    @property
    def parent(self):
        raise NotImplementedError('parent() must be implemented in concrete subclass {my_class}'
                                  .format(my_class=type(self)))

    @parent.setter
    def parent(self, value):
        raise NotImplementedError('*setter* of @property parent() must be implemented in concrete subclass {my_class}'
                                  .format(my_class=type(self)))

    @property
    def children(self):
        raise NotImplementedError('children() must be implemented in concrete subclass {my_class}'
                                  .format(my_class=type(self)))

    @property
    def parents(self):
        """
        I return the list of my parents with the root first and me last.
        """
        if self.parent is None:
            return [self]
        else:
            return self.parent.parents.append(self)


class AssetClassSet(TaxonomyNode):

    def __init__(self, version_id, asset_classes=None):
        self.version_id = version_id
        self._asset_classes = []
        given_asset_classes = asset_classes or []
        self._asset_classes.extend(given_asset_classes)

    @property
    def asset_classes(self):
        return self._asset_classes

    def leaf_for(self, subject):
        """
        This method simply delegates to the newer visitor-pattern based classification_for()
        Consider this method deprecated.
        """
        return self.classification_for(subject)

    def classification_for(self, subject):
        classification = Classification(subject=subject, root=self)
        asset_class = self.asset_class_by_name(subject.asset_class_name)
        if asset_class:
            asset_class.extend_classification(classification)
        else:
            classification.errors.append("RTS 2 has no Asset Class named '{asset_class_name}'.".format(
                asset_class_name=subject.asset_class_name
            ))
        return classification

    def asset_class_by_name(self, asset_class_name):
        return next((asset_class
                     for asset_class
                     in self.asset_classes
                     if asset_class_name == asset_class.name),
                    None)

    def append(self, asset_class):
        self._asset_classes.append(asset_class)

    def display(self, prefix=""):
        target = "The set of all Asset Classes:"
        for asset_class in self._asset_classes:
            target += "\n"
            target += asset_class.display(prefix=prefix+'- ')
        return target

    @property
    def parent(self):
        return None

    @property
    def children(self):
        return self.asset_classes

    def all_sub_asset_classes(self):
        sub_asset_class_list = []
        for asset_class in self.children:
            sub_asset_class_list.extend(asset_class.children)
        return sub_asset_class_list

    def make_test_samples(self, number, sink=None):
        """
        Synthesize a number of sample trades from my asset classes.  If
        a sink function/lambda is given this will be called with each
        sample as it is generated, otherwise the generated trades will
        be returned in a list.
        """
        sample_list=[]
        a_sink = sink or lambda x: sample_list.append(x)
        number_of_children = len(self.children)
        for _ in range(number):
            random_child = self.children[random.randint(0, number_of_children - 1)]
            sample = random_child.make_test_samples(number=1, sink=a_sink)
        return sample_list


{'fraction_non_alphanumeric': 0.0691835425639146, 'fraction_numerical': 0.003756987079629799, 'mean_word_length': 2.8798435833629576, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3916184', 'n_tokens_mistral': 2919, 'n_tokens_neox': 2706, 'n_words': 1035}