Total Complexity | 7 |
Total Lines | 48 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | """Type declarations for vocabulary functionality""" |
||
2 | |||
3 | from __future__ import annotations |
||
4 | |||
5 | import abc |
||
6 | |||
7 | from annif.corpus import Subject |
||
8 | |||
9 | |||
10 | class SubjectIndex(metaclass=abc.ABCMeta): |
||
11 | """Base class for an index that remembers the associations between |
||
12 | integer subject IDs and their URIs and labels.""" |
||
13 | |||
14 | @abc.abstractmethod |
||
15 | def __len__(self) -> int: |
||
16 | pass # pragma: no cover |
||
17 | |||
18 | @property |
||
19 | @abc.abstractmethod |
||
20 | def languages(self) -> list[str] | None: |
||
21 | pass # pragma: no cover |
||
22 | |||
23 | @abc.abstractmethod |
||
24 | def __getitem__(self, subject_id: int) -> Subject: |
||
25 | pass # pragma: no cover |
||
26 | |||
27 | @abc.abstractmethod |
||
28 | def contains_uri(self, uri: str) -> bool: |
||
29 | pass # pragma: no cover |
||
30 | |||
31 | @abc.abstractmethod |
||
32 | def by_uri(self, uri: str, warnings: bool = True) -> int | None: |
||
33 | """return the subject ID of a subject by its URI, or None if not found. |
||
34 | If warnings=True, log a warning message if the URI cannot be found.""" |
||
35 | pass # pragma: no cover |
||
36 | |||
37 | @abc.abstractmethod |
||
38 | def by_label(self, label: str | None, language: str) -> int | None: |
||
39 | """return the subject ID of a subject by its label in a given |
||
40 | language""" |
||
41 | pass # pragma: no cover |
||
42 | |||
43 | @abc.abstractmethod |
||
44 | def active(self) -> list[tuple[int, Subject]]: |
||
45 | """return a list of (subject_id, Subject) tuples of all subjects that |
||
46 | are available for use""" |
||
47 | pass # pragma: no cover |
||
48 |