summaryrefslogtreecommitdiffhomepage
path: root/libs/trakit/api.py
blob: 286207aa4c5322d6b8b8cc5f6d98e72322cb4cd7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import typing

from trakit.config import Config
from trakit.context import Context
from trakit.patterns import configure


class TrakItApi:

    def __init__(self, config: typing.Optional[typing.Mapping[str, typing.Any]] = None):
        self.rebulk = configure(Config(config))

    def trakit(self, string: str, options: typing.Optional[typing.Mapping[str, typing.Any]] = None):
        """Return a mapping of extracted information."""
        matches = self.rebulk.matches(string, Context(options))
        guess: typing.Mapping[str, typing.Any] = matches.to_dict()
        return guess


default_api = TrakItApi()


def trakit(string: str, options: typing.Optional[typing.Mapping[str, typing.Any]] = None):
    return default_api.trakit(string, options)