Passed
Push — issue735-subject-filtering ( d4533d...f9dfa6 )
by Osma
03:38
created

annif.vocab.types   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A SubjectIndex.__getitem__() 0 3 1
A SubjectIndex.languages() 0 4 1
A SubjectIndex.active() 0 5 1
A SubjectIndex.by_label() 0 5 1
A SubjectIndex.by_uri() 0 5 1
A SubjectIndex.__len__() 0 3 1
A SubjectIndex.contains_uri() 0 3 1
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