Completed
Push — master ( f6c6f1...e349d9 )
by Juho
26s queued 19s
created

InputLimiter.__init__()   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
"""A simple transformation that truncates the text of input documents to a
2
given character length."""
3
4
from annif.exception import ConfigurationException
5
from . import transform
6
7
8
class InputLimiter(transform.BaseTransform):
9
10
    name = 'limit'
11
12
    def __init__(self, project, input_limit):
13
        super().__init__(project)
14
        self.input_limit = int(input_limit)
15
        self._validate_value(self.input_limit)
16
17
    def transform_fn(self, text):
18
        return text[:self.input_limit]
19
20
    def _validate_value(self, input_limit):
21
        if input_limit < 0:
22
            raise ConfigurationException(
23
                'input_limit in limit_input transform cannot be negative',
24
                project_id=self.project.project_id)
25