The ToWord class
Class for converting strings to list[int] with specified alphabet.
An instance of this class is callable and used to convert from str to
list[int]. The characters in the string are converted to integers according
to their position in the alphabet used to construct a ToWord instance if
one is provided, or using words.human_readable_index otherwise.
>>> from libsemigroups_pybind11 import ToWord
>>> to_word = ToWord("bac")
>>> to_word("bac")
[0, 1, 2]
>>> to_word("bababbbcbc")
[0, 1, 0, 1, 0, 0, 0, 2, 0, 2]
>>> to_word.init()    # clear the alphabet
<ToWord object with alphabet "">
>>> to_word("bac")
[1, 0, 2]
Contents
| Class for converting strings to  | |
| Return the alphabet used for conversion. | |
| Check if the current ToWord instance can convert a specified letter. | |
| 
 | Copy a  | 
| 
 | Check if the alphabet is defined. | 
| 
 | Overloaded function. | 
Full API
- class ToWord
- __init__(*args, **kwargs)
- Overloaded function. 
 - __call__(self: ToWord, input: str) list[int]
- Convert a string to a - list[int].- This function converts its argument input into a - list[int]. The characters of input are converted using the alphabet used to construct the object or set via- ToWord.init(), or with- words.human_readable_indexif- ToWord.empty()returns- True.- Parameters:
- input (str) – the string to convert. 
- Returns:
- the converted list. 
- Return type:
- Raises:
- LibsemigroupsError – if the alphabet used to define an instance of - ToWordis not empty and input contains letters that do not correspond to letters of the alphabet.
 
 - alphabet(self: ToWord) str
- Return the alphabet used for conversion. - This function returns a - strcorresponding to the ordered-set alphabet \(\{a_0, a_1, \dots, a_{n-1}\}\) that the initialised- ToWordobject will use to convert from- strto- list[int]. Specifically, \(a_i \mapsto i\) where \(a_i\) will correspond to a letter in a- str, and \(i\) is an- int.- If this function returns the empty string, then conversion will be performed using - words.human_readable_index.- Returns:
- The alphabet. 
- Return type:
 
 - can_convert_letter(self: ToWord, c: str) bool
- Check if the current ToWord instance can convert a specified letter. - This function returns - Trueif c can be converted to an- intusing this- ToWordinstance, and- Falseotherwise.- Parameters:
- c (str) – the letter to check the convertibility of. 
- Returns:
- Whether the letter can be converted. 
- Return type:
- Raises:
- LibsemigroupsError – if c is a multi-character string. 
 
 - empty(self: ToWord) bool
- Check if the alphabet is defined. - This function returns - Trueif no alphabet has been defined, and- Falseotherwise.- Returns:
- Whether the alphabet is empty. 
- Return type:
 
 - init(*args, **kwargs)
- Overloaded function. - init(self: ToWord) ToWord
- Initialize an existing ToWord object. - This function puts a - ToWordobject back into the same state as if it had been newly default constructed.- Returns:
- self. 
- Return type:
 - See also 
 - init(self: ToWord, alphabet: str) ToWord
- Initialize an existing ToWord object. - This function puts a - ToWordobject back into the same state as if it had been newly constructed from alphabet.- Parameters:
- alphabet (str) – the alphabet. 
- Returns:
- self. 
- Return type:
- Raises:
- LibsemigroupsError – if there are repeated letters in alphabet. 
 - See also