-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from snipsco/release/0.9.0
Release 0.9.0
- Loading branch information
Showing
35 changed files
with
801 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,7 @@ celerybeat-schedule | |
# virtualenv | ||
.venv | ||
venv/ | ||
venv2/ | ||
venv3/ | ||
venv36/ | ||
venv37/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
#!/usr/bin/env bash | ||
source .travis/common.sh | ||
|
||
export PATH="/usr/local/bin:$HOME/.cargo/bin:$PATH" | ||
perl -p -i -e "s/^snips-nlu-utils = .*\$/snips-nlu-utils = { path = \"..\/..\" \}/g" */**/Cargo.toml | ||
|
||
if [ "${RUST_TESTS}" == "true" ]; then | ||
if [[ "${RUST_TESTS}" == "true" ]]; then | ||
echo "Rust tests..." | ||
cargo test --all || die "Rust tests failed" | ||
cargo test --all | ||
fi | ||
|
||
if [ "${PYTHON_TESTS}" == "true" ]; then | ||
if [[ "${PYTHON_TESTS}" == "true" ]]; then | ||
echo "Python tests..." | ||
cd python | ||
python -m pip install tox | ||
tox || die "Python tests failed" | ||
tox | ||
cd .. | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
[package] | ||
name = "snips-nlu-utils" | ||
version = "0.8.0" | ||
version = "0.9.0" | ||
authors = ["Adrien Ball <[email protected]>"] | ||
edition = "2018" | ||
|
||
[workspace] | ||
members = [ | ||
"python/ffi" | ||
] | ||
|
||
[dependencies] | ||
itertools = "0.8" | ||
lazy_static = "1.2" | ||
libc = "0.2" | ||
regex = "1.1" | ||
unicode-normalization = "0.1.5" | ||
failure = "0.1" | ||
fnv = "1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/sh | ||
|
||
set -ex | ||
|
||
VERSION=$1 | ||
|
||
if [[ -z "$VERSION" ]] | ||
then | ||
echo "Usage: $0 <version>" | ||
exit 1 | ||
fi | ||
|
||
|
||
./update_version.sh ${VERSION} | ||
|
||
git commit . -m "Set post-release version to $VERSION" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
include snips_nlu_utils/__version__ | ||
include README.rst requirements.txt | ||
recursive-include snips_nlu_utils *.so | ||
include snips_nlu_utils_py/Cargo.toml | ||
recursive-include snips_nlu_utils_py/src *.rs | ||
include ffi/Cargo.toml | ||
recursive-include ffi/src *.rs | ||
global-exclude __pycache__ *.py[cod] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "snips-nlu-utils-python-ffi" | ||
version = "0.9.0" | ||
authors = ["Adrien Ball <[email protected]>"] | ||
edition = "2018" | ||
|
||
[lib] | ||
name = "snips_nlu_utils_python_ffi" | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
failure = "0.1" | ||
libc = "0.2" | ||
ffi-utils = { git = "https://github.com/snipsco/snips-utils-rs", rev = "291ce1d" } | ||
snips-nlu-utils = { git = "https://github.com/snipsco/snips-nlu-utils", tag = "0.9.0" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Foreign Function Interface | ||
-- | ||
|
||
This package provides ffi bindings to the utils crate. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use crate::types::CNgramArray; | ||
use crate::types::CTokenArray; | ||
use crate::Result; | ||
use ffi_utils::{take_back_c_string, take_back_c_string_array, CStringArray, RawPointerConverter}; | ||
|
||
pub fn destroy_string_c(ptr: *mut libc::c_char) -> Result<()> { | ||
take_back_c_string!(ptr); | ||
Ok(()) | ||
} | ||
|
||
pub fn destroy_string_array_c(ptr: *mut CStringArray) -> Result<()> { | ||
take_back_c_string_array!(ptr); | ||
Ok(()) | ||
} | ||
|
||
pub fn destroy_token_array_c(ptr: *mut CTokenArray) -> Result<()> { | ||
let _ = unsafe { CTokenArray::from_raw_pointer(ptr) }; | ||
Ok(()) | ||
} | ||
|
||
pub fn destroy_ngram_array_c(ptr: *mut CNgramArray) -> Result<()> { | ||
let _ = unsafe { CNgramArray::from_raw_pointer(ptr) }; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
mod destroy; | ||
mod string; | ||
mod token; | ||
mod types; | ||
|
||
use crate::types::CNgramArray; | ||
use ffi_utils::*; | ||
|
||
type Result<T> = ::std::result::Result<T, ::failure::Error>; | ||
|
||
generate_error_handling!(snips_nlu_utils_get_last_error); | ||
|
||
#[no_mangle] | ||
pub extern "C" fn snips_nlu_utils_destroy_string(ptr: *mut libc::c_char) -> SNIPS_RESULT { | ||
wrap!(destroy::destroy_string_c(ptr)) | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn snips_nlu_utils_destroy_string_array( | ||
ptr: *mut ::ffi_utils::CStringArray, | ||
) -> SNIPS_RESULT { | ||
wrap!(destroy::destroy_string_array_c(ptr)) | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn snips_nlu_utils_destroy_ngram_array( | ||
ptr: *mut types::CNgramArray, | ||
) -> SNIPS_RESULT { | ||
wrap!(destroy::destroy_ngram_array_c(ptr)) | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn snips_nlu_utils_destroy_token_array( | ||
ptr: *mut types::CTokenArray, | ||
) -> SNIPS_RESULT { | ||
wrap!(destroy::destroy_token_array_c(ptr)) | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn snips_nlu_utils_remove_diacritics( | ||
input: *const ::libc::c_char, | ||
result: *mut *const ::libc::c_char, | ||
) -> SNIPS_RESULT { | ||
wrap!(string::remove_diacritics_c(input, result)) | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn snips_nlu_utils_normalize( | ||
input: *const ::libc::c_char, | ||
result: *mut *const ::libc::c_char, | ||
) -> SNIPS_RESULT { | ||
wrap!(string::normalize_c(input, result)) | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn snips_nlu_utils_get_shape( | ||
input: *const ::libc::c_char, | ||
result: *mut *const ::libc::c_char, | ||
) -> SNIPS_RESULT { | ||
wrap!(string::get_shape_c(input, result)) | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn snips_nlu_utils_hash_str_to_i32( | ||
input: *const ::libc::c_char, | ||
result: *mut ::libc::c_int, | ||
) -> SNIPS_RESULT { | ||
wrap!(string::hash_str_to_i32_c(input, result)) | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn snips_nlu_utils_tokenize( | ||
input: *const ::libc::c_char, | ||
language: *const ::libc::c_char, | ||
result: *mut *const types::CTokenArray, | ||
) -> SNIPS_RESULT { | ||
wrap!(token::tokenize_c(input, language, result)) | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn snips_nlu_utils_tokenize_light( | ||
input: *const ::libc::c_char, | ||
language: *const ::libc::c_char, | ||
result: *mut *const ::ffi_utils::CStringArray, | ||
) -> SNIPS_RESULT { | ||
wrap!(token::tokenize_light_c(input, language, result)) | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn snips_nlu_utils_compute_all_ngrams( | ||
tokens: *const CStringArray, | ||
max_ngram_size: libc::c_uint, | ||
result: *mut *const CNgramArray, | ||
) -> SNIPS_RESULT { | ||
wrap!(token::compute_all_ngrams_c(tokens, max_ngram_size, result)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use crate::Result; | ||
use ffi_utils::{convert_to_c_string, CReprOf, RawPointerConverter}; | ||
use snips_nlu_utils::string::*; | ||
use std::ffi::CStr; | ||
|
||
pub fn remove_diacritics_c( | ||
input: *const ::libc::c_char, | ||
result: *mut *const ::libc::c_char, | ||
) -> Result<()> { | ||
let str_input = unsafe { CStr::from_ptr(input) }.to_str()?; | ||
let cleaned_string = remove_diacritics(str_input); | ||
let cs = convert_to_c_string!(cleaned_string); | ||
unsafe { *result = cs }; | ||
Ok(()) | ||
} | ||
|
||
pub fn normalize_c(input: *const ::libc::c_char, result: *mut *const ::libc::c_char) -> Result<()> { | ||
let str_input = unsafe { CStr::from_ptr(input) }.to_str()?; | ||
let cleaned_string = normalize(str_input); | ||
let cs = convert_to_c_string!(cleaned_string); | ||
unsafe { *result = cs }; | ||
Ok(()) | ||
} | ||
|
||
pub fn get_shape_c(input: *const ::libc::c_char, result: *mut *const ::libc::c_char) -> Result<()> { | ||
let str_input = unsafe { CStr::from_ptr(input) }.to_str()?; | ||
let shape = get_shape(str_input).to_string(); | ||
let cs = convert_to_c_string!(shape); | ||
unsafe { *result = cs }; | ||
Ok(()) | ||
} | ||
|
||
pub fn hash_str_to_i32_c(input: *const ::libc::c_char, result: *mut ::libc::c_int) -> Result<()> { | ||
let str_input = unsafe { CStr::from_ptr(input) }.to_str()?; | ||
let hash = hash_str_to_i32(str_input); | ||
unsafe { *result = hash }; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use crate::types::CNgramArray; | ||
use crate::types::CTokenArray; | ||
use crate::Result; | ||
use ffi_utils::{convert_to_c_string_array, AsRust, CReprOf, CStringArray, RawPointerConverter}; | ||
use snips_nlu_utils::language::Language; | ||
use snips_nlu_utils::token::*; | ||
use std::ffi::CStr; | ||
use std::str::FromStr; | ||
|
||
pub fn tokenize_c( | ||
input: *const libc::c_char, | ||
language: *const libc::c_char, | ||
result: *mut *const CTokenArray, | ||
) -> Result<()> { | ||
let str_input = unsafe { CStr::from_ptr(input) }.to_str()?; | ||
let str_lang = unsafe { CStr::from_ptr(language) }.to_str()?; | ||
let language = Language::from_str(str_lang)?; | ||
let tokens = tokenize(str_input, language); | ||
let c_token_array = CTokenArray::c_repr_of(tokens)?.into_raw_pointer(); | ||
unsafe { *result = c_token_array }; | ||
Ok(()) | ||
} | ||
|
||
pub fn tokenize_light_c( | ||
input: *const libc::c_char, | ||
language: *const libc::c_char, | ||
result: *mut *const CStringArray, | ||
) -> Result<()> { | ||
let str_input = unsafe { CStr::from_ptr(input) }.to_str()?; | ||
let str_lang = unsafe { CStr::from_ptr(language) }.to_str()?; | ||
let language = Language::from_str(str_lang)?; | ||
let tokens = tokenize_light(str_input, language); | ||
let cs = convert_to_c_string_array!(tokens); | ||
unsafe { *result = cs }; | ||
Ok(()) | ||
} | ||
|
||
pub fn compute_all_ngrams_c( | ||
tokens: *const CStringArray, | ||
max_ngram_size: libc::c_uint, | ||
result: *mut *const CNgramArray, | ||
) -> Result<()> { | ||
let tokens_vec = unsafe { (*tokens).as_rust()? }; | ||
let tokens_slice: Vec<&str> = tokens_vec.iter().map(|token| &**token).collect(); | ||
let ngrams = compute_all_ngrams(&tokens_slice, max_ngram_size as usize); | ||
let c_ngrams = CNgramArray::c_repr_of(ngrams)?.into_raw_pointer(); | ||
unsafe { *result = c_ngrams }; | ||
Ok(()) | ||
} |
Oops, something went wrong.