Passed
Pull Request — main (#840)
by Osma
06:44 queued 03:36
created

annif.vocab.types   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 27
dl 0
loc 48
rs 10
c 0
b 0
f 0

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
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