| Total Complexity | 4 |
| Total Lines | 23 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # TODO Add docstring |
||
| 2 | from annif.exception import ConfigurationException |
||
| 3 | from . import transformer |
||
| 4 | |||
| 5 | |||
| 6 | class InputLimiter(transformer.IdentityTransformer): |
||
| 7 | |||
| 8 | name = 'limit_input' |
||
| 9 | |||
| 10 | def __init__(self, project, input_limit): |
||
| 11 | self.project = project |
||
| 12 | self.input_limit = int(input_limit) |
||
| 13 | self._validate_value(self.input_limit) |
||
| 14 | |||
| 15 | def transform_text(self, text): |
||
| 16 | return text[:self.input_limit] |
||
| 17 | |||
| 18 | def _validate_value(self, input_limit): |
||
| 19 | if input_limit < 0: |
||
| 20 | raise ConfigurationException( |
||
| 21 | 'input_limit in limit_input transformer cannot be negative', |
||
| 22 | project_id=self.project.project_id) |
||
| 23 |