Skip to main content

Rust-based Python wrapper for duckling library in Haskell.

Project description

PyDuckling

Project License - MIT pypi version conda version download count Downloads PyPI status Linux Tests Mac Tests

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyduckling_native_phihos-0.1.1.dev1-cp312-cp312-musllinux_1_2_x86_64.whl (8.7 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

pyduckling_native_phihos-0.1.1.dev1-cp312-cp312-manylinux_2_28_x86_64.whl (8.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

pyduckling_native_phihos-0.1.1.dev1-cp311-cp311-musllinux_1_2_x86_64.whl (8.7 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

pyduckling_native_phihos-0.1.1.dev1-cp311-cp311-manylinux_2_28_x86_64.whl (8.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

pyduckling_native_phihos-0.1.1.dev1-cp310-cp310-musllinux_1_2_x86_64.whl (8.7 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

pyduckling_native_phihos-0.1.1.dev1-cp310-cp310-manylinux_2_28_x86_64.whl (8.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

pyduckling_native_phihos-0.1.1.dev1-cp39-cp39-musllinux_1_2_x86_64.whl (8.7 MB view details)

Uploaded CPython 3.9musllinux: musl 1.2+ x86-64

pyduckling_native_phihos-0.1.1.dev1-cp39-cp39-manylinux_2_28_x86_64.whl (8.8 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

pyduckling_native_phihos-0.1.1.dev1-cp38-cp38-musllinux_1_2_x86_64.whl (8.7 MB view details)

Uploaded CPython 3.8musllinux: musl 1.2+ x86-64

pyduckling_native_phihos-0.1.1.dev1-cp38-cp38-manylinux_2_28_x86_64.whl (8.8 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.28+ x86-64

File details

Details for the file pyduckling_native_phihos-0.1.1.dev1-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.1.1.dev1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 04c3a5f2ac547c419d2a3afd2e3361c9988bb325dd9aee4cb2b2d6d5f455b177
MD5 23fc3755a88018e2abeed994e917a883
BLAKE2b-256 d9b46228abfa4a8c3f573d14512a589f3adca51b46b2e0789fd209215b973af1

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.1.1.dev1-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.1.1.dev1-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4e3adf2927a6e5a8640e847405ad98fe5f036568d0bcc6c513fdb366d1a3f5d8
MD5 1dc6c7e62161dda1c5b5ccff68f751b3
BLAKE2b-256 739e98d0f79a0bab4d082ca8ed8a92b5d74794a074662e4eb62153a25a5c4f90

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.1.1.dev1-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.1.1.dev1-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 374a5fe5df94da8be05cd7c5158f8e15da1866ca9f8aec4819893f988706a6b2
MD5 a9c3955062fdc91a8ae9311b618c152b
BLAKE2b-256 4ea44593a1e0c4cb70685df424fae14133fd02c8fe2613d15056964ee6d909e0

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.1.1.dev1-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.1.1.dev1-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 14324b1c7acf895c8b34f76043147ee74a724957cf76e64a8bcf26993a026ecd
MD5 131702b58fd82626dc84bbd41e99f963
BLAKE2b-256 4e20836b7d5e4c7008b5a4d1204892c649a90c34414f25a58a8e3843628cf0f7

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.1.1.dev1-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.1.1.dev1-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0fa98907d77f81b8610e9d1773d6d921285b41dd99cbbf76a4c0bb702344cee8
MD5 24163194ae8254f0be59f3971f74833c
BLAKE2b-256 8e64282e35475c4b818746e72eabeb68f51abd947ee475ad2ab5175212ee023e

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.1.1.dev1-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.1.1.dev1-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3bf1b06a646194d6c65ea5356007f138bb5a37347d59ee9b2ce4918142a483b0
MD5 bc2a7ebfb949d2a55baccf6ab3f26ffd
BLAKE2b-256 e179a2212920ef3f2d9b0fafd0a141b3af92e6a6eeb8fd77225699d539ba2a85

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.1.1.dev1-cp39-cp39-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.1.1.dev1-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0c813c150d13258e75d88a30714fc35dca2d559d41ca372133258c8c8a2dd4ec
MD5 098bfaeed692363bb4e6cac2240925d3
BLAKE2b-256 e0b9b5c644850774adb9d4cd9edb0a031a1c2ec5c380e0b1119710a92e68ecc0

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.1.1.dev1-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.1.1.dev1-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cc37883fdceb97ac4ba313c9ea33a23a546d45a881df96a399b58f20a9ecbb11
MD5 d24f51a5f3b72885de8efe839ed68b75
BLAKE2b-256 e82c1c56e67ab2666bc6716abeb9ef8906ad299a749c1c3e3adf4edc694c13f7

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.1.1.dev1-cp38-cp38-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.1.1.dev1-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 21273cd47671a53bfac7f4cc6b41a33cfe9408a7d3845b22f77b143ab0d85962
MD5 cace2463c4f9bfee894042314a4c4da8
BLAKE2b-256 5509dd589a320967f21bd1085b890648d69a3f4affd0b839e8fbf3a1be4771d6

See more details on using hashes here.

File details

Details for the file pyduckling_native_phihos-0.1.1.dev1-cp38-cp38-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.1.1.dev1-cp38-cp38-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0d699658b61fb1b2ede6de5cfd3e50d168cd8ca64af4a14d7abad29ee2eca310
MD5 ec7835d0e526d911983d324f59e52969
BLAKE2b-256 f6d473eb5dffd61e22d6af788ff7f1e5b7cc9c6d05b895fa68bd01848799c431

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page