Пример #1
0
    def wrapper(*args, **kwargs):  # pylint: disable=unused-argument
        """Wrap inner function."""
        # perform cleanup
        Hook.clear_current_instances()
        exc = None
        ret_values = None

        # run the function
        try:
            ret_values = func(*args, **kwargs)
        except Exception as exc:
            raise exc
        finally:
            # cleanup again
            Hook.clear_current_instances()
Пример #2
0
    def __init__(self,
                 feature_hooks: typing.Union[dict, typing.Iterable] = None,
                 share_hooks=False):
        """Initialize FeatureExtractor."""
        if feature_hooks is None:
            feature_hooks = list()

        elif isinstance(feature_hooks, dict):
            # create hooks from the dictionary
            feature_hooks = [
                Hook(k, v, reuse=share_hooks)
                for k, v in feature_hooks.items()
            ]

        elif not isinstance(feature_hooks, typing.Iterable):
            raise TypeError(
                "Argument `feature_hooks` expected to be of type "
                f"{typing.Union[dict, typing.Iterable]}, got {type(feature_hooks)}"
            )

        self._extractor = _FeatureExtractor(
            share_hooks=share_hooks).update(feature_hooks)

        # prototyped
        self._y = None
        self._skip_unfed_hooks = False
Пример #3
0
    def __init__(self, feature_hooks=None, share_hooks=False):
        if isinstance(feature_hooks, dict):
            # create hooks from the dictionary
            feature_hooks = [
                Hook(k, v, reuse=share_hooks)
                for k, v in feature_hooks.items()
            ]

        self._extractor = _FeatureExtractor(share_hooks=share_hooks).update(
            feature_hooks or [])

        # prototyped
        self._y = None
        self._skip_unfed_hooks = False
Пример #4
0
 def __init__(self, share_hooks=False):
     # default hooks to be called by FeatureExtractor
     self._hooks = [
         Hook('prev-word', self._prev_ngram, reuse=share_hooks, n=1),
         Hook('prev-tag', self._prev_ngram, reuse=share_hooks, n=1),
         Hook('prev-bigram', self._prev_ngram, reuse=share_hooks, n=2),
         Hook('next-bigram', self._next_ngram, reuse=share_hooks, n=2),
         Hook('prev-bigram-tags', self._prev_ngram_tags, reuse=share_hooks, n=2),
         Hook('next-bigram-tags', self._next_ngram_tags, reuse=share_hooks, n=2)
     ]