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

annif.transform.inputlimiter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A InputLimiter.transform_fn() 0 2 1
A InputLimiter._validate_value() 0 5 2
A InputLimiter.__init__() 0 4 1
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