Rust-based Python wrapper for duckling library in Haskell.
Project description
PyDuckling
Copyright © 2020– Treble.ai
Overview
This package provides native bindings for Facebook's Duckling in Python. This package supports all dimensions and languages available on the original library, and it does not require to spawn a Haskell server and does not use HTTP to call the Duckling API.
Note: This package is completely Haskell-less
Installing
To install pyduckling, you can use both conda and pip package managers:
# Using pip
pip install pyduckling-native-phihos
Notes: Right now, we only provide package distributions for Linux (x86_64). We will provide Windows and Mac distributions on the next release
Dependencies
To compile pyduckling, you will require the latest nightly release of Rust, alongside Cargo. Also, it requires a Python distribution with its corresponding development headers. Finally, this project depends on the following Cargo crates:
- PyO3: Library used to produce Python bindings from Rust code.
- Maturin: Build system to build and publish Rust-based Python packages
Additionally, this package depends on Duckling-FFI, used to compile the native interface to Duckling on Haskell. In order to compile Duckling-FFI, you will require the Stack Haskell manager.
Installing locally
Besides Rust and Stack, you will require the latest version of maturin installed to compile this project locally:
pip install maturin toml
First, you will need to compile Duckling-FFI in order to produce the shared library libducklingffi
, to do so, you can use the git submodule found at the root of this repository:
cd duckling-ffi
stack build
Then, you will need to move the resulting binary libducklingffi.so
to the ext_lib
folder:
cp duckling-ffi/libducklingffi.so ext_lib
After completing this procedure, it is possible to execute the following command to compile pyduckling:
maturin develop
In order to produce wheels, maturin build
can be used instead. This project supports PEP517, thus pip can be used to install this package as well:
pip install -U .
Running tests
We use pytest to run tests as it follows (after calling maturin develop
):
pytest -v duckling/tests
Package usage
PyDuckling provides access to the parsing capabilities of Duckling used to extract structured data from text.
# Core imports
from duckling import (load_time_zones, parse_ref_time,
parse_lang, default_locale_lang, parse_locale,
parse_dimensions, parse, Context)
# Install with pip install pendulum
import pendulum
# Load reference time for time parsing
time_zones = load_time_zones("/usr/share/zoneinfo")
bog_now = pendulum.now('America/Bogota').replace(microsecond=0)
ref_time = parse_ref_time(
time_zones, 'America/Bogota', bog_now.int_timestamp)
# Load language/locale information
lang_es = parse_lang('ES')
default_locale = default_locale_lang(lang_es)
locale = parse_locale('ES_CO', default_locale)
# Create parsing context with time and language information
context = Context(ref_time, locale)
# Define dimensions to look-up for
valid_dimensions = ["amount-of-money", "credit-card-number", "distance",
"duration", "email", "number", "ordinal",
"phone-number", "quantity", "temperature",
"time", "time-grain", "url", "volume"]
# Parse dimensions to use
output_dims = parse_dimensions(valid_dimensions)
# Parse a phrase
result = parse('En dos semanas', context, output_dims, False)
This wrapper allows access to all the dimensions and languages available on Duckling:
Dimension | Example input | Example value output |
---|---|---|
amount-of-money |
"42€" | {"value":42,"type":"value","unit":"EUR"} |
credit-card-number |
"4111-1111-1111-1111" | {"value":"4111111111111111","issuer":"visa"} |
distance |
"6 miles" | {"value":6,"type":"value","unit":"mile"} |
duration |
"3 mins" | {"value":3,"minute":3,"unit":"minute","normalized":{"value":180,"unit":"second"}} |
email |
"duckling-team@fb.com" | {"value":"duckling-team@fb.com"} |
number |
"eighty eight" | {"value":88,"type":"value"} |
ordinal |
"33rd" | {"value":33,"type":"value"} |
phone-number |
"+1 (650) 123-4567" | {"value":"(+1) 6501234567"} |
quantity |
"3 cups of sugar" | {"value":3,"type":"value","product":"sugar","unit":"cup"} |
temperature |
"80F" | {"value":80,"type":"value","unit":"fahrenheit"} |
time |
"today at 9am" | {"values":[{"value":"2016-12-14T09:00:00.000-08:00","grain":"hour","type":"value"}],"value":"2016-12-14T09:00:00.000-08:00","grain":"hour","type":"value"} |
url |
"https://api.wit.ai/message?q=hi" | {"value":"https://api.wit.ai/message?q=hi","domain":"api.wit.ai"} |
volume |
"4 gallons" | {"value":4,"type":"value","unit":"gallon"} |
Changelog
Please see our CHANGELOG file to learn more about our new features and improvements.
Contribution guidelines
We follow PEP8 and PEP257 for pure python packages and Rust to compile extensions. We use MyPy type annotations for all functions and classes declared on this package. Feel free to send a PR or create an issue if you have any problem/question.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file pyduckling_native_phihos-0.1.1.dev2-cp312-cp312-musllinux_1_2_x86_64.whl
.
File metadata
- Download URL: pyduckling_native_phihos-0.1.1.dev2-cp312-cp312-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 8.7 MB
- Tags: CPython 3.12, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e941c6fb09130d64aa63a93ec4df6ca2fbf3592b1fbe72166dbf2f42a44c1a6 |
|
MD5 | 3a248f8bb19253aac977cfb4f4d8552e |
|
BLAKE2b-256 | 88c07507a7bb222ae09e30053d62007d718156da4e6af8dddd46ac18c5e95f28 |
Provenance
File details
Details for the file pyduckling_native_phihos-0.1.1.dev2-cp312-cp312-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: pyduckling_native_phihos-0.1.1.dev2-cp312-cp312-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 8.8 MB
- Tags: CPython 3.12, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 384dd1c411dc2caacc7669dc008fbd97f506bdc28f530a872273ad0fa9331595 |
|
MD5 | 574708659cfadf5ff1eb134b85c47571 |
|
BLAKE2b-256 | 0384b39862c7a70551d2d3a578fafb335ba707118b42f845dd45ee9fdc0d4c0b |
Provenance
File details
Details for the file pyduckling_native_phihos-0.1.1.dev2-cp311-cp311-musllinux_1_2_x86_64.whl
.
File metadata
- Download URL: pyduckling_native_phihos-0.1.1.dev2-cp311-cp311-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 8.7 MB
- Tags: CPython 3.11, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6b2528d987809019889de8e451da280bfd0c816b24d445a3dd29529d05e5212 |
|
MD5 | 424da7cbd77caf7b75a427905384a828 |
|
BLAKE2b-256 | 5af203f2829511ce3f7e1f584a3ab810935a178810a34693fbdb58da67ee4c43 |
Provenance
File details
Details for the file pyduckling_native_phihos-0.1.1.dev2-cp311-cp311-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: pyduckling_native_phihos-0.1.1.dev2-cp311-cp311-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 8.8 MB
- Tags: CPython 3.11, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93c4b492ab46e33f152090f32d10ff7d1e7e8e0861effdd1033c02971b11064e |
|
MD5 | 9a44ccbadb771293cec4888f7a96d0ef |
|
BLAKE2b-256 | b131455de041958b3bdb87b55859ce48cafebdef03de0ba4620d7c9b72d575df |
Provenance
File details
Details for the file pyduckling_native_phihos-0.1.1.dev2-cp310-cp310-musllinux_1_2_x86_64.whl
.
File metadata
- Download URL: pyduckling_native_phihos-0.1.1.dev2-cp310-cp310-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 8.7 MB
- Tags: CPython 3.10, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25ba928445eb38d7c49fffb623a75e293cd87e6343253b50003c48e17bd9738b |
|
MD5 | 79d48a3b890438f6e69063fa4ae80b3b |
|
BLAKE2b-256 | 5ae947eaf7461e2c2881fac5dae9ca029d9c3ca8f3301a2d6df5aabdc9429a41 |
Provenance
File details
Details for the file pyduckling_native_phihos-0.1.1.dev2-cp310-cp310-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: pyduckling_native_phihos-0.1.1.dev2-cp310-cp310-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 8.8 MB
- Tags: CPython 3.10, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90927718280b66f46dbc0221610ab7d570fa53f3efcb94a46587bbe43334e712 |
|
MD5 | 9a64fb89265459dc86616a9d1b17d03b |
|
BLAKE2b-256 | ab2e9ea833e7da2209d66593a9b15120e313da808b222e68c1dddbd9d0e8b670 |
Provenance
File details
Details for the file pyduckling_native_phihos-0.1.1.dev2-cp39-cp39-musllinux_1_2_x86_64.whl
.
File metadata
- Download URL: pyduckling_native_phihos-0.1.1.dev2-cp39-cp39-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 8.7 MB
- Tags: CPython 3.9, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22037b0a54084b1e738091c651f15f16d8994c75ef6d24d5b230784d0ab13edd |
|
MD5 | 438b479da6193e086bbd77c5b0b91a63 |
|
BLAKE2b-256 | 64c7b225ff74272317e5dab529e02de990a44f8e2c22d92bfc88dee5a608dd6e |
Provenance
File details
Details for the file pyduckling_native_phihos-0.1.1.dev2-cp39-cp39-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: pyduckling_native_phihos-0.1.1.dev2-cp39-cp39-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 8.8 MB
- Tags: CPython 3.9, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbb9819e1ca68c4f3cbaa43b3fdec60e957de67b208e91023a5b5d8c1feb7937 |
|
MD5 | 8d7ab7aa6a8542bea4ab4fa28d71b0a7 |
|
BLAKE2b-256 | b7357e34c9a7c5c342daf8dbbf9e77cc78695032a03a44b2d7dd493919fdb972 |
Provenance
File details
Details for the file pyduckling_native_phihos-0.1.1.dev2-cp38-cp38-musllinux_1_2_x86_64.whl
.
File metadata
- Download URL: pyduckling_native_phihos-0.1.1.dev2-cp38-cp38-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 8.7 MB
- Tags: CPython 3.8, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34e7e0f3c245cce92f4f22b9f38b8f7a21e618c553a888c43ffd36a78c49e6d0 |
|
MD5 | 5a9832f888390b092796fc125baea778 |
|
BLAKE2b-256 | 3d40099dbb13ac1ef3567fd506d9fcf63219081cf21e149cbf51813cefe90d22 |
Provenance
File details
Details for the file pyduckling_native_phihos-0.1.1.dev2-cp38-cp38-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: pyduckling_native_phihos-0.1.1.dev2-cp38-cp38-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 8.8 MB
- Tags: CPython 3.8, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f14465c3635216648e0506048a81aabe371c5ee0c386ed2c1cf6f60fb78e1dce |
|
MD5 | decc31cf1690d24b2c202d64fa6e86a1 |
|
BLAKE2b-256 | 37524be9eaa51e2c381094decb2d06822bde3369f4db32dcc7e13a1ba4fa7ba9 |