-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop': v 1.2.0. Support NLU, safe_kwargs for meta an…
…d request (for future API updates compatability)
- Loading branch information
Showing
20 changed files
with
283 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,4 @@ | |
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) | ||
|
||
|
||
__version__ = '1.1.7' | ||
__version__ = '1.2.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
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
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,36 @@ | ||
import logging | ||
from attr import attrs, attrib | ||
|
||
from aioalice.utils import ensure_cls | ||
from aioalice.utils.helper import Helper, HelperMode, Item | ||
from . import AliceObject, EntityTokens, EntityValue | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
@attrs | ||
class Entity(AliceObject): | ||
"""Entity object""" | ||
type = attrib(type=str) | ||
tokens = attrib(convert=ensure_cls(EntityTokens)) | ||
value = attrib(factory=dict) | ||
|
||
@type.validator | ||
def check(self, attribute, value): | ||
"""Report unknown type""" | ||
if value not in EntityType.all(): | ||
log.error('Unknown Entity type! `%r`', value) | ||
|
||
def __attrs_post_init__(self): | ||
"""If entity type not number, convert to EntityValue""" | ||
if self.value and self.type != EntityType.YANDEX_NUMBER: | ||
self.value = EntityValue(**self.value) | ||
|
||
|
||
class EntityType(Helper): | ||
mode = HelperMode.UPPER_DOT_SEPARATED | ||
|
||
YANDEX_GEO = Item() | ||
YANDEX_FIO = Item() | ||
YANDEX_NUMBER = Item() | ||
YANDEX_DATETIME = Item() |
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,9 @@ | ||
from attr import attrs, attrib | ||
from . import AliceObject | ||
|
||
|
||
@attrs | ||
class EntityTokens(AliceObject): | ||
"""EntityTokens object""" | ||
start = attrib(type=int) | ||
end = attrib(type=int) |
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,31 @@ | ||
from attr import attrs, attrib | ||
from . import AliceObject | ||
|
||
|
||
@attrs | ||
class EntityValue(AliceObject): | ||
"""EntityValue object""" | ||
|
||
# YANDEX.FIO | ||
first_name = attrib(default=None, type=str) | ||
patronymic_name = attrib(default=None, type=str) | ||
last_name = attrib(default=None, type=str) | ||
|
||
# YANDEX.GEO | ||
country = attrib(default=None, type=str) | ||
city = attrib(default=None, type=str) | ||
street = attrib(default=None, type=str) | ||
house_number = attrib(default=None, type=str) | ||
airport = attrib(default=None, type=str) | ||
|
||
# YANDEX.DATETIME | ||
year = attrib(default=None, type=str) | ||
year_is_relative = attrib(default=False, type=bool) | ||
month = attrib(default=None, type=str) | ||
month_is_relative = attrib(default=False, type=bool) | ||
day = attrib(default=None, type=str) | ||
day_is_relative = attrib(default=False, type=bool) | ||
hour = attrib(default=None, type=str) | ||
hour_is_relative = attrib(default=False, type=bool) | ||
minute = attrib(default=None, type=str) | ||
minute_is_relative = attrib(default=False, type=bool) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Natural Language Understanding: https://medium.com/@lola.com/nlp-vs-nlu-whats-the-difference-d91c06780992 | ||
from attr import attrs, attrib | ||
from aioalice.utils import ensure_cls | ||
from . import AliceObject, Entity | ||
|
||
|
||
@attrs | ||
class NaturalLanguageUnderstanding(AliceObject): | ||
"""Natural Language Understanding object""" | ||
tokens = attrib(factory=list) | ||
entities = attrib(factory=list, convert=ensure_cls(Entity)) |
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
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# https://gist.github.com/surik00/a6c2804a2d18a2ab75630bb5d93693c8 | ||
|
||
import inspect | ||
import functools | ||
|
||
|
||
def safe_kwargs(func_or_class): | ||
spec = inspect.getfullargspec(func_or_class) | ||
all_args = spec.args | ||
|
||
@functools.wraps(func_or_class) | ||
def wrap(*args, **kwargs): | ||
accepted_kwargs = {k: v for k, v in kwargs.items() if k in all_args} | ||
return func_or_class(*args, **accepted_kwargs) | ||
|
||
return wrap |
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.