Example #1
0
def _recur_split(s, dtype_as):
    """Splits (possibly nested list of) strings recursively.
    """
    if is_str(s):
        return _maybe_list_to_array(s.split(), dtype_as)
    else:
        s_ = [_recur_split(si, dtype_as) for si in s]
        return _maybe_list_to_array(s_, s)
Example #2
0
def _recur_split(s: MaybeSeq[str], dtype_as: Collection[str]) -> MaybeSeq[str]:
    r"""Splits (possibly nested list of) strings recursively.
    """
    if isinstance(s, str):
        return _maybe_list_to_array(s.split(), dtype_as)
    else:
        s_ = [_recur_split(si, dtype_as) for si in s]
        return _maybe_list_to_array(s_, s)
Example #3
0
 def _recur_strip(s):
     if is_str(s):
         return ' '.join(s.strip().split()).\
             replace(' '+token, '').replace(token+' ', '')
     else:
         s_ = [_recur_strip(si) for si in s]
         return _maybe_list_to_array(s_, s)
Example #4
0
 def _recur_join(s):
     if len(s) == 0:
         return ''
     elif is_str(s[0]):
         return sep.join(s)
     else:
         s_ = [_recur_join(si) for si in s]
         return _maybe_list_to_array(s_, s)
Example #5
0
 def _recur_strip(s):
     if isinstance(s, str):
         if bos_token == '':
             return ' '.join(s.strip().split())
         else:
             return ' '.join(s.strip().split()).replace(bos_token + ' ', '')
     else:
         s_ = [_recur_strip(si) for si in s]
         return _maybe_list_to_array(s_, s)
Example #6
0
 def _recur_strip(s):
     if is_str(s):
         s_tokens = s.split()
         if eos_token in s_tokens:
             return ' '.join(s_tokens[:s_tokens.index(eos_token)])
         else:
             return s
     else:
         s_ = [_recur_strip(si) for si in s]
         return _maybe_list_to_array(s_, s)
Example #7
0
 def _recur_split(s):
     if is_str(s):
         return _maybe_list_to_array(s.split(), str_)
     else:
         s_ = [_recur_split(si) for si in s]
         return _maybe_list_to_array(s_, s)