EOX GitLab Instance

postprocess.py 526 Bytes
Newer Older
1
from abc import ABC, abstractmethod
2
from typing import Dict, Type
3

4
5
from .utils import import_by_path

6
7

class Postprocessor(ABC):
8
9
10
    def __init__(self, **kwargs):
        ...

11
12
13
14
15
    @abstractmethod
    def postprocess(self, item: dict) -> dict:
        pass


16
POSTPROCESSORS: Dict[str, Type[Postprocessor]] = {
17
18
19
20
21

}


def get_postprocessor(config: dict) -> Postprocessor:
22
23
24
25
26
    type_ = config.pop("type")
    try:
        cls = POSTPROCESSORS[type_]
    except KeyError:
        cls = import_by_path(type_)
27
    return cls(**config)