| Conditions | 3 |
| Total Lines | 15 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | """Annif backend mixins that can be used to implement features""" |
||
| 18 | def _suggest(self, text, project, params): |
||
| 19 | self.initialize() |
||
| 20 | self.debug('Suggesting subjects for text "{}..." (len={})'.format( |
||
| 21 | text[:20], len(text))) |
||
| 22 | sentences = project.analyzer.tokenize_sentences(text) |
||
| 23 | self.debug('Found {} sentences'.format(len(sentences))) |
||
| 24 | chunksize = int(params['chunksize']) |
||
| 25 | chunktexts = [] |
||
| 26 | for i in range(0, len(sentences), chunksize): |
||
| 27 | chunktexts.append(' '.join(sentences[i:i + chunksize])) |
||
| 28 | self.debug('Split sentences into {} chunks'.format(len(chunktexts))) |
||
| 29 | if len(chunktexts) == 0: # no input, empty result |
||
| 30 | return ListSuggestionResult( |
||
| 31 | hits=[], subject_index=project.subjects) |
||
| 32 | return self._suggest_chunks(chunktexts, project) |
||
| 33 |