Skip to content

Commit

Permalink
add dataset mixins (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneBinder authored Nov 26, 2023
1 parent f898da6 commit 563b93d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/pytorch_ie/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from .document import Annotation, AnnotationLayer, Document, annotation_field
from .metric import DocumentMetric
from .model import PyTorchIEModel
from .module_mixins import WithDocumentTypeMixin
from .module_mixins import (
EnterDatasetDictMixin,
EnterDatasetMixin,
ExitDatasetDictMixin,
ExitDatasetMixin,
PreparableMixin,
WithDocumentTypeMixin,
)
from .statistic import DocumentStatistic
from .taskmodule import TaskEncoding, TaskModule

Expand Down
33 changes: 33 additions & 0 deletions src/pytorch_ie/core/module_mixins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from abc import ABC, abstractmethod
from typing import List, Optional, Type

from pytorch_ie.core.document import Document
Expand Down Expand Up @@ -97,3 +98,35 @@ def prepare(self, *args, **kwargs) -> None:
)
self._post_prepare()
return None


class EnterDatasetMixin(ABC):
"""Mixin for processors that enter a dataset context."""

@abstractmethod
def enter_dataset(self, dataset, name: Optional[str] = None) -> None:
"""Enter dataset context."""


class ExitDatasetMixin(ABC):
"""Mixin for processors that exit a dataset context."""

@abstractmethod
def exit_dataset(self, dataset, name: Optional[str] = None) -> None:
"""Exit dataset context."""


class EnterDatasetDictMixin(ABC):
"""Mixin for processors that enter a dataset dict context."""

@abstractmethod
def enter_dataset_dict(self, dataset_dict) -> None:
"""Enter dataset dict context."""


class ExitDatasetDictMixin(ABC):
"""Mixin for processors that exit a dataset dict context."""

@abstractmethod
def exit_dataset_dict(self, dataset_dict) -> None:
"""Exit dataset dict context."""

0 comments on commit 563b93d

Please sign in to comment.