| Total Complexity | 6 |
| Total Lines | 33 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | """Dummy backend for testing basic interaction of projects and backends""" |
||
| 2 | |||
| 3 | |||
| 4 | from annif.hit import AnalysisHit, ListAnalysisResult |
||
| 5 | from . import backend |
||
| 6 | |||
| 7 | |||
| 8 | class DummyBackend(backend.AnnifLearningBackend): |
||
| 9 | name = "dummy" |
||
| 10 | initialized = False |
||
| 11 | uri = 'http://example.org/dummy' |
||
| 12 | label = 'dummy' |
||
| 13 | |||
| 14 | def initialize(self): |
||
| 15 | self.initialized = True |
||
| 16 | |||
| 17 | def _analyze(self, text, project, params): |
||
| 18 | score = float(params.get('score', 1.0)) |
||
| 19 | return ListAnalysisResult([AnalysisHit(uri=self.uri, |
||
| 20 | label=self.label, |
||
| 21 | score=score)], |
||
| 22 | project.subjects) |
||
| 23 | |||
| 24 | def learn(self, corpus, project): |
||
| 25 | # in this dummy backend we "learn" by picking up the URI and label |
||
| 26 | # of the first subject of the first document in the learning set |
||
| 27 | # and using that in subsequent analysis results |
||
| 28 | for doc in corpus.documents: |
||
| 29 | if doc.uris and doc.labels: |
||
| 30 | self.uri = list(doc.uris)[0] |
||
| 31 | self.label = list(doc.labels)[0] |
||
| 32 | break |
||
| 33 |