-
Notifications
You must be signed in to change notification settings - Fork 56
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 #51 from snipsco/release/0.57.0
Release 0.57.0
- Loading branch information
Showing
22 changed files
with
1,568 additions
and
1,514 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
2,827 changes: 1,406 additions & 1,421 deletions
2,827
data/tests/configurations/trained_assistant.json
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
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 @@ | ||
[package] | ||
name = "snips-nlu-ffi" | ||
version = "0.56.1" | ||
version = "0.57.0" | ||
authors = [ | ||
"Kevin Lefevre <[email protected]>", | ||
"Thibaut Lorrain <[email protected]>" | ||
|
@@ -9,7 +9,7 @@ authors = [ | |
[dependencies] | ||
ffi-utils = { git = "https://github.com/snipsco/snips-utils-rs", rev = "b1f4af3" } | ||
snips-nlu-lib = { path = "../snips-nlu-lib" } | ||
snips-nlu-ontology-ffi-macros = { git = "https://github.com/snipsco/snips-nlu-ontology", tag = "0.55.0" } | ||
snips-nlu-ontology-ffi-macros = { git = "https://github.com/snipsco/snips-nlu-ontology", tag = "0.57.0" } | ||
failure = "0.1" | ||
lazy_static = "1.0" | ||
libc = "0.2" | ||
|
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,6 +1,6 @@ | ||
[package] | ||
name = "snips-nlu-python-ffi" | ||
version = "0.56.1" | ||
version = "0.57.0" | ||
authors = ["Adrien Ball <[email protected]>"] | ||
|
||
[lib] | ||
|
@@ -10,4 +10,4 @@ crate-type = ["cdylib"] | |
[dependencies] | ||
libc = "0.2" | ||
ffi-utils = { git = "https://github.com/snipsco/snips-utils-rs", rev = "b1f4af3" } | ||
snips-nlu-ffi = { git = "https://github.com/snipsco/snips-nlu-rs", tag = "0.56.1" } | ||
snips-nlu-ffi = { git = "https://github.com/snipsco/snips-nlu-rs", tag = "0.57.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 |
---|---|---|
@@ -1 +1 @@ | ||
0.56.1 | ||
0.57.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
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 @@ | ||
[package] | ||
name = "snips-nlu-lib" | ||
version = "0.56.1" | ||
version = "0.57.0" | ||
authors = [ | ||
"Thibaut Lorrain <[email protected]>", | ||
"Kevin Lefevre <[email protected]>" | ||
|
@@ -11,13 +11,15 @@ description = "Rust implementation of Snips NLU" | |
[dependencies] | ||
snips-nlu-resources-packed = { path = "../snips-nlu-resources-packed" } | ||
crfsuite = { git = "https://github.com/snipsco/crfsuite-rs", rev = "b18d95c" } | ||
snips-nlu-ontology = { git = "https://github.com/snipsco/snips-nlu-ontology", tag = "0.55.0" } | ||
snips-nlu-ontology-parsers = { git = "https://github.com/snipsco/snips-nlu-ontology", tag = "0.55.0" } | ||
snips-nlu-ontology = { git = "https://github.com/snipsco/snips-nlu-ontology", tag = "0.57.0" } | ||
snips-nlu-ontology-parsers = { git = "https://github.com/snipsco/snips-nlu-ontology", tag = "0.57.0" } | ||
snips-nlu-utils = { git = "https://github.com/snipsco/snips-nlu-utils", tag = "0.6.1" } | ||
dinghy-test = "0.3" | ||
failure = "0.1" | ||
base64 = "0.9" | ||
itertools = { version = "0.7", default-features = false } | ||
lazy_static = "1.0" | ||
lru-cache = "0.1.1" | ||
serde = "1.0" | ||
serde_derive = "1.0" | ||
serde_json = "1.0" | ||
|
Large diffs are not rendered by default.
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
use std::collections::HashMap; | ||
use std::sync::{Arc, Mutex}; | ||
|
||
use lru_cache::LruCache; | ||
|
||
use snips_nlu_ontology::{BuiltinEntityKind, BuiltinEntity, Language}; | ||
use snips_nlu_ontology_parsers::BuiltinEntityParser; | ||
|
||
|
||
pub struct CachingBuiltinEntityParser { | ||
parser: BuiltinEntityParser, | ||
cache: Mutex<EntityCache>, | ||
} | ||
|
||
impl CachingBuiltinEntityParser { | ||
pub fn new(lang: Language, cache_capacity: usize) -> Self { | ||
CachingBuiltinEntityParser { | ||
parser: BuiltinEntityParser::new(lang), | ||
cache: Mutex::new(EntityCache::new(cache_capacity)), | ||
} | ||
} | ||
|
||
pub fn extract_entities( | ||
&self, | ||
sentence: &str, | ||
filter_entity_kinds: Option<&[BuiltinEntityKind]>, | ||
use_cache: bool, | ||
) -> Vec<BuiltinEntity> { | ||
let lowercased_sentence = sentence.to_lowercase(); | ||
if !use_cache { | ||
return self.parser.extract_entities(&lowercased_sentence, filter_entity_kinds); | ||
} | ||
let cache_key = CacheKey { | ||
input: lowercased_sentence, | ||
kinds: filter_entity_kinds | ||
.map(|entity_kinds| entity_kinds.to_vec()) | ||
.unwrap_or_else(|| vec![]), | ||
}; | ||
|
||
self.cache | ||
.lock() | ||
.unwrap() | ||
.cache(&cache_key, | ||
|cache_key| self.parser.extract_entities(&cache_key.input, filter_entity_kinds)) | ||
} | ||
} | ||
|
||
struct EntityCache(LruCache<CacheKey, Vec<BuiltinEntity>>); | ||
|
||
impl EntityCache { | ||
fn new(capacity: usize) -> Self { | ||
EntityCache(LruCache::new(capacity)) | ||
} | ||
|
||
fn cache<F: Fn(&CacheKey) -> Vec<BuiltinEntity>>( | ||
&mut self, | ||
key: &CacheKey, | ||
producer: F, | ||
) -> Vec<BuiltinEntity> { | ||
let cached_value = self.0.get_mut(key).map(|a| a.clone()); | ||
if let Some(value) = cached_value { | ||
return value; | ||
} | ||
let value = producer(key); | ||
self.0.insert(key.clone(), value.clone()); | ||
value | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
struct CacheKey { | ||
input: String, | ||
kinds: Vec<BuiltinEntityKind>, | ||
} | ||
|
||
pub struct BuiltinEntityParserFactory; | ||
|
||
impl BuiltinEntityParserFactory { | ||
pub fn get(lang: Language) -> Arc<CachingBuiltinEntityParser> { | ||
lazy_static! { | ||
static ref CACHED_PARSERS: Mutex<HashMap<Language, Arc<CachingBuiltinEntityParser>>> = | ||
Mutex::new(HashMap::new()); | ||
} | ||
|
||
CACHED_PARSERS | ||
.lock() | ||
.unwrap() | ||
.entry(lang) | ||
.or_insert_with(|| Arc::new(CachingBuiltinEntityParser::new(lang, 1000))) | ||
.clone() | ||
} | ||
} |
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
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
Oops, something went wrong.