summaryrefslogtreecommitdiffhomepage
path: root/libs/trakit/api.py
diff options
context:
space:
mode:
Diffstat (limited to 'libs/trakit/api.py')
-rw-r--r--libs/trakit/api.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/libs/trakit/api.py b/libs/trakit/api.py
new file mode 100644
index 000000000..286207aa4
--- /dev/null
+++ b/libs/trakit/api.py
@@ -0,0 +1,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)