docs: Add docstrings

This commit is contained in:
Marty Oehme 2023-09-19 17:52:45 +02:00
parent 4eb983d9e3
commit 07d4de9a46
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A
3 changed files with 17 additions and 1 deletions

View file

@ -22,7 +22,10 @@ COLORS = {
@dataclass
class Annotation:
"""A PDF annotation object"""
"""A PDF annotation object.
Contains all information necessary for the annotation itself, content and metadata.
"""
file: str
colors: tuple[float, float, float] = field(default_factory=lambda: (0.0, 0.0, 0.0))
@ -83,6 +86,10 @@ class Annotation:
@dataclass
class AnnotatedDocument:
"""Contains all annotations belonging to a single papis document.
Combines a document with a list of annotations which belong to it."""
document: Document
annotations: list[Annotation]
# TODO could implement a from_doc() static method to generate annotation list?

View file

@ -115,6 +115,14 @@ def _add_annots_to_note(
def _drop_existing_annotations(
formatted_annotations: list[str], file_lines: list[str]
) -> list[str]:
"""Returns the input annotations dropping any existing.
Takes a list of formatted annotations and a list of strings
(most probably existing lines in a file). If anny annotations
match an existing line closely enough, they will be dropped.
Returns list of annotations without duplicates.
"""
minimum_similarity = (
papis.config.getfloat("minimum_similarity", "plugins.extract") or 1.0
)

View file

@ -83,6 +83,7 @@ def extract(filename: Path) -> list[Annotation]:
def is_pdf(fname: Path) -> bool:
"""Check if file is a pdf, using mime type."""
return magic.from_file(fname, mime=True) == "application/pdf"