<commit_before>#!/usr/bin/env python

import re
from icqShape import Shape


class CompositeShapeBuilder( Shape ):

    def __init__( self, shape_tuples=None ):
        """
        Constructor
        @param shape_tuples list of tuples (expr_var, shape)
        """
        self.shape_tuples = shape_tuples

    def compose( self, expression ):
        if expression is None or self.shape_tuples is None:
            return None
        expr = expression
        for expr_var, shape in self.shape_tuples:
            # Return the string obtained by replacing the leftmost
            # non-overlapping occurrences of expr_var in expr by
            # the replacement shape.
            expr = re.sub( expr_var, shape, expr )
        return eval( expr )
<commit_msg>Enhance the ShapeComposer - still not working.<commit_after>#!/usr/bin/env python

import re
from icqShape import Shape


class ShapeComposer( Shape ):

    def __init__( self, shape_tuples=None ):
        self.shape_tuples = shape_tuples
        self.csg = None

    def __add__( self, other ):
        """
        Union
        @param other Shape instance
        @return CompositeShape
        """
        self.csg = Shape( self.csg + other.csg )
        return self.csg

    def __sub__( self, other ):
        """
        Removal
        @param other Shape instance
        @return CompositeShape
        """
        self.csg = Shape( self.csg - other.csg )
        return self.csg

    def __mul__( self, other ):
        """
        Intersection
        @param other Shape instance
        @return CompositeShape
        """
        self.csg = Shape( self.csg * other.csg )
        return self.csg

    def compose( self, expression ):
        expr = expression
        for shape_tuple in self.shape_tuples:
            expr_var, shape = shape_tuple
            expr = re.sub( r'%s' % expr_var, shape, expr )
        return eval( expr )

{'fraction_non_alphanumeric': 0.08067050811943426, 'fraction_numerical': 0.0, 'mean_word_length': 1.9429892141756548, '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': '1540548', 'n_tokens_mistral': 561, 'n_tokens_neox': 532, 'n_words': 169}