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