Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor code and add German negation #11

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions negate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from .negate import Negator
from .tokens import Token
from .utils.tokens import Token

# Don't expose the following submodules.
del globals()["negate"]
del globals()["tokens"]
63 changes: 63 additions & 0 deletions negate/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""Base negator."""

from abc import ABC, abstractmethod
from typing import Any, Dict, List, Optional


class BaseNegator(ABC):
"""Base negator.

Specific negators for different languages must inherit from this class.
"""

@abstractmethod
def __init__(
self,
use_transformers: Optional[bool] = None,
use_gpu: Optional[bool] = None,
fail_on_unsupported: Optional[bool] = None,
log_level: Optional[int] = None,
**kwargs,
):
"""Instanciate a :obj:`Negator`.

Args:
use_transformers (:obj:`Optional[bool]`, defaults to :obj:`False`):
Whether to use a Transformer model for POS tagging and
dependency parsing.
use_gpu (:obj:`Optional[bool]`, defaults to :obj:`False`):
Whether to use the GPU, if available. This parameter is ignored
when :param:`use_transformers` is set to :obj:`False`.
fail_on_unsupported (:obj:`Optional[bool]`, defaults to :obj:`False`):
Whether to fail upon non-supported sentences. If set to
:obj:`False`, a warning will be printed, and the sentence will
try to be negated in a best-effort fashion.
log_level (:obj:`Optional[int]`, defaults to ``logging.INFO``):
The level of the logger.

Raises:
:obj:`RuntimeError`: If the sentence is not supported and
:arg:`fail_on_unsupported` is set to :obj:`True`.
"""
pass

@abstractmethod
def negate_sentence(
self,
sentence: str,
**kwargs: Dict[str, Any],
) -> List[str]:
"""Negate a sentence.

Affirmative sentences will be turned into negative ones and vice versa.

Args:
sentence (:obj:`str`):
The sentence to negate.
**kwargs (:obj:`Dict[str, Any]`):
Additional parameters to pass to the concrete language negator.

Returns:
:obj:`List[str]`: The negated sentence(s).
"""
pass
Loading
Loading