|
14 | 14 | """ |
15 | 15 |
|
16 | 16 | from _libsemigroups_pybind11 import ( |
| 17 | + PresentationWords as _PresentationWords, |
| 18 | + InversePresentationWords as _InversePresentationWords, |
| 19 | + StephenPresentationWords as _StephenPresentationWords, |
| 20 | + StephenInversePresentationWords as _StephenInversePresentationWords, |
17 | 21 | accepts, |
| 22 | + dot, |
18 | 23 | is_left_factor, |
19 | 24 | left_factors, |
20 | 25 | number_of_left_factors, |
21 | 26 | number_of_words_accepted, |
22 | 27 | words_accepted, |
23 | 28 | ) |
| 29 | + |
| 30 | + |
| 31 | +# TODO(2): Make this work with string presentations once it works |
| 32 | +# TODO(0): Change this to a proper class similar to what's done with Kambites |
| 33 | +# (once the proper classes PR is merged) |
| 34 | +def Stephen(*args): # pylint: disable=invalid-name |
| 35 | + """Construct a Stephen instance of the type specified by its arguments. |
| 36 | +
|
| 37 | + Options for calling this function are: |
| 38 | + 1 Stephen(presentation: PresentationWords) |
| 39 | + 2 Stephen(presentation: InversePresentationWords) |
| 40 | + 3 Stephen(presentation: StephenPresentationWords) |
| 41 | + 4 Stephen(presentation: StephenInversePresentationWords) |
| 42 | +
|
| 43 | + In cases 1 and 2 a new Stephen object is constructed with the given |
| 44 | + presentation. In cases 3 and 4 the Stephen object is constructed by copying |
| 45 | + an existing Stephen object. In cases 1 and 3 a StephenPresentationWords |
| 46 | + object is returned. In cases 2 and 4 a StephenInversePresentationWords |
| 47 | + object is returned. |
| 48 | + """ |
| 49 | + |
| 50 | + if len(args) != 1: |
| 51 | + raise ValueError(f"expected 1 argument, but got {len(args)}") |
| 52 | + |
| 53 | + presentation_or_stephen = args[0] |
| 54 | + # Order important here due to inheritance |
| 55 | + if isinstance( |
| 56 | + presentation_or_stephen, |
| 57 | + (_InversePresentationWords, _StephenInversePresentationWords), |
| 58 | + ): |
| 59 | + PresentationType = _InversePresentationWords |
| 60 | + elif isinstance( |
| 61 | + presentation_or_stephen, (_PresentationWords, _StephenPresentationWords) |
| 62 | + ): |
| 63 | + PresentationType = _PresentationWords |
| 64 | + else: |
| 65 | + raise TypeError( |
| 66 | + f"expected first argument to have type in {{PresentationWords, " |
| 67 | + f"InversePresentationWords, StephenPresentationWords, " |
| 68 | + f"StephenInversePresentationWords}}, but found {type(presentation_or_stephen)}" |
| 69 | + ) |
| 70 | + |
| 71 | + cpp_type = { |
| 72 | + _PresentationWords: _StephenPresentationWords, |
| 73 | + _InversePresentationWords: _StephenInversePresentationWords, |
| 74 | + } |
| 75 | + |
| 76 | + return cpp_type[PresentationType](presentation_or_stephen) |
0 commit comments