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 Distribution

pyduckling_native_phihos-0.1.1.dev0.tar.gz (31.0 kB view details)

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

pyduckling_native_phihos-0.1.1.dev0-cp312-cp312-manylinux_2_28_x86_64.whl (8.6 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

pyduckling_native_phihos-0.1.1.dev0-cp311-cp311-manylinux_2_28_x86_64.whl (8.6 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

pyduckling_native_phihos-0.1.1.dev0-cp310-cp310-manylinux_2_28_x86_64.whl (8.6 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.9 musllinux: musl 1.2+ x86-64

pyduckling_native_phihos-0.1.1.dev0-cp39-cp39-manylinux_2_28_x86_64.whl (8.6 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.8 musllinux: musl 1.2+ x86-64

pyduckling_native_phihos-0.1.1.dev0-cp38-cp38-manylinux_2_28_x86_64.whl (8.6 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.28+ x86-64

File details

Details for the file pyduckling_native_phihos-0.1.1.dev0.tar.gz.

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.1.1.dev0.tar.gz
Algorithm Hash digest
SHA256 87f8254754c7f09791ffb176e80d945aac48a57ff48ebeb609aa0571be9dfaae
MD5 e2589e2c5984cfb303e4b54a3db1f4d5
BLAKE2b-256 55e1022378bab3b912683f8d25b302684d64f4b30eac26753138ef0026ef6a5a

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.1.1.dev0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 bdebaddef85624ee9e7c82ce8d597ab2b40cbb196f8597b9ccfbb5b4c1c6472d
MD5 ff1125339451264c4a7bcd68e2cf255c
BLAKE2b-256 d53d94bc0b129ff76fcd10bba1ff3333264e5295c9ed792724074b33f18c3f3e

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.1.1.dev0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9c24c3f9dea822cda3609ba4d9098669a87cc063f0f68ed143b0f1d0640e2082
MD5 b1339d96a658c9990a991120607f0435
BLAKE2b-256 71ecbc8e3f80334a439d1451cb789477ad59e029905c3a24e7aca10fda5de813

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.1.1.dev0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ce02c4e44ad45ef21e3e055154570c25524d54bcbb3aa79eb46f7115f1c7f5f6
MD5 59a0fe6c21f08f8042669e0567b19d8b
BLAKE2b-256 a0045824524a880ff5680f29da901c4d4226437c6eec2baf1fc2271dac395d61

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.1.1.dev0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b84c450f406ae0cec0e1d5e42481ee9c05ce6b29fb2816a5b47f781ab3adebe2
MD5 707d43e6b4eaa96990869f41b520bb4c
BLAKE2b-256 f63a8e3c67782df78c2293a284f6cc9ef299afcc3266dc71eecb64bf632ed0e5

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.1.1.dev0-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1691daee3ff05680c299b5ef9a18892e0c8e84b58437c9790df1580457b77533
MD5 afc16570ba91a833118ec54e6ac1280e
BLAKE2b-256 6e39b5e3b25117568ed047ca79bed598eeaca759cb08e8348ec9cdf69bc5fcda

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.1.1.dev0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 db64ad21fa1cf44d3f5c35fa04ed5735293944392d68c71dd92395e5d45a9753
MD5 35c96a252a503cd0ae050e358b906e36
BLAKE2b-256 0905525b8714a54b209f02b741e370f443305e15374502470a24a99b975ce19c

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.1.1.dev0-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d4b5c119423745e0a8cc447aab418b51314946cf0349c595eef40678f3848971
MD5 527ccdca3b30ec767d50b120e5596960
BLAKE2b-256 6fdc68d14e95df87e5c84613f0d905ddc5fd1b7618f1f06198aa2f4ff75a7499

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.1.1.dev0-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 41b9527cedb2587a8dc6f9d6657ada0b24705b6ff898db7caafd445284de41f7
MD5 84fb2d4af7a0259e7362f303904489f7
BLAKE2b-256 81aa5f662a6df9371e8e18bd1796a487f5f57e369c249b936418a25e9560bf6d

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.1.1.dev0-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 89e62ef15686af17ef4f2ed4c7d075f09ead727afcc75fc3390a6e0e871c218f
MD5 bc3806308f1948b9bd805451ba33ee60
BLAKE2b-256 89497ca75e671506f31504590a1ebee03c2800ac3c6f55629d47a2dd4c9696bc

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pyduckling_native_phihos-0.1.1.dev0-cp38-cp38-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c68cb011c5fe5756c96d7649f48ae46282c59677e0b06395dd879f5f805c6c64
MD5 1c37693701901fd80d401214536d5223
BLAKE2b-256 40b18fde2056882c4eb9e9e6e3e4a22386e62f3069aee2f950775c3604de602a

See more details on using hashes here.

Provenance

Supported by

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