Total Complexity | 6 |
Total Lines | 35 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | """Common functionality for backends.""" |
||
9 | class AnnifBackend(metaclass=abc.ABCMeta): |
||
1 ignored issue
–
show
|
|||
10 | """Base class for Annif backends that perform analysis. The |
||
11 | non-implemented methods should be overridden in subclasses.""" |
||
12 | |||
13 | name = None |
||
14 | |||
15 | def __init__(self, backend_id, config): |
||
16 | """Initialize backend with a specific configuration. The |
||
17 | configuration is a dict. Keys and values depend on the specific |
||
18 | backend type.""" |
||
19 | self.backend_id = backend_id |
||
20 | self.config = config |
||
21 | self._datadir = None |
||
22 | |||
23 | def _get_datadir(self): |
||
24 | """return the path of the directory where this backend can store its |
||
25 | data files""" |
||
26 | if self._datadir is None: |
||
27 | self._datadir = os.path.join( |
||
28 | annif.cxapp.app.config['DATADIR'], |
||
29 | 'backends', |
||
30 | self.backend_id) |
||
31 | if not os.path.exists(self._datadir): |
||
32 | os.makedirs(self._datadir) |
||
33 | return self._datadir |
||
34 | |||
35 | def load_subjects(self, subjects, analyzer): |
||
36 | """load the given subjects analyzed using the given analyzer""" |
||
37 | pass # default is to do nothing, subclasses may override |
||
38 | |||
39 | @abc.abstractmethod |
||
40 | def analyze(self, text): |
||
41 | """Analyze some input text and return a list of subjects represented |
||
42 | as a list of AnalysisHit objects.""" |
||
43 | pass |
||
44 |