<commit_before>#=========================================================================
# StrSearchFunc.py
#=========================================================================

from new_pymtl import *
from new_pymtl.SignalValue import SignalValue

class StrSignalValue( SignalValue, str ):
  def __init__( self, str_="" ):
    self._str  = str_
    self.nbits = None
  def write_value( self, value ):
    try:    self._str = value._str
    except: self._str = value
  def write_next( self, value ):
    try:    self._next._str = value._str
    except: self._next._str = value
  def __eq__( self, value ):
    return self._str == value
  def __ne__( self, value ):
    return self._str != value
  def __str__( self ):
    return self._str[0:10].zfill( 10 )
  def data( self ):
    return self._str


#-------------------------------------------------------------------------
# StrSearchMath
#-------------------------------------------------------------------------
# Simple python string searcher.
class StrSearchMath( Model ):

  #-----------------------------------------------------------------------
  # __init__
  #-----------------------------------------------------------------------
  def __init__( s, max_doc_chars, string ):
    s.string = string

    s.in_    = InPort ( StrSignalValue() )
    s.out    = OutPort( 1 )
<commit_msg>[new_strsearch] update to StrSignalValue wrapper<commit_after>#=========================================================================
# StrSearchFunc.py
#=========================================================================

from new_pymtl import *
from new_pymtl.SignalValue import SignalValue

class StrSignalValue( SignalValue, str ):
  def __init__( self, str_="" ):
    self._str  = str_
    self.nbits = None
  def write_value( self, value ):
    try:                   self._str = value._str
    except AttributeError: self._str = value
  def write_next( self, value ):
    try:                   self._next._str = value._str
    except AttributeError: self._next._str = value
  def __eq__( self, value ):
    return self._str == value
  def __ne__( self, value ):
    return self._str != value
  def __str__( self ):
    return self._str[0:10].zfill( 10 )
  def data( self ):
    return self._str


#-------------------------------------------------------------------------
# StrSearchMath
#-------------------------------------------------------------------------
# Simple python string searcher.
class StrSearchMath( Model ):

  #-----------------------------------------------------------------------
  # __init__
  #-----------------------------------------------------------------------
  def __init__( s, max_doc_chars, string ):
    s.string = string

    s.in_    = InPort ( StrSignalValue() )
    s.out    = OutPort( 1 )

{'fraction_non_alphanumeric': 0.38568872987477637, 'fraction_numerical': 0.004293381037567084, 'mean_word_length': 1.5722171113155474, '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': '7366608', 'n_tokens_mistral': 694, 'n_tokens_neox': 658, 'n_words': 182}