为亚马逊的Alexa创造话语。

utter-more的Python项目详细描述


Travis

更多

要定制亚马逊的Alexa,你需要一种所谓的技能。在技巧上做点什么,你就有了意图。为了达到目的,你必须说出一句话。当这句话被说出时,意图就跑了因为语言是复杂的,可能有很多不同的方式说同一件事,你可能想让亚历克斯学习所有这些方式此外,您可能有许多语句变量(称为意图槽)。冗长到足以涵盖每一个案例可能会很乏味,所以这就解决了这个问题。

安装软件包

做经典:

pip install utter-more

或者如果你喜欢冒险并使用conda:

conda install -c crumpstrr33 utter-more

创造话语

下面是一些显示其功能的示例。

格式化

目前有两种选择:

  1. 或语句(a|b|c|...)-如果要允许多个可互换的单词,则使用。例如,如果photopicturepainting在你的话语中是可以互换的,那么在它应该在的地方写(photo|picture|painting)。单词的数量是任意的,可以使用单个卷曲的关键字,如{intent_slot}
  2. 条件或语句(a*tag1|b) (c^tag1|d)-如果希望或语句中短语的外观依赖于另一个短语,则使用这里,a是主语,c是从句;只有当它也包含a时,才出现带有c的语句。它的另一个功能如下如果有(It*s|They*p) (is^s|are^p) (close^s|far^p)isclose只在It也显示时显示,反之,arefar只在They显示时显示这就是你如何用这个函数做条件和
  3. 如果你的话语中有一个意图槽是可选的,则使用可选的意图槽。例如,如果你有一个可选副词,你可以写I {adverb} love it,或者只写I love it相反,您可以编写I {{adverb}} love it来捕获两者。

运行代码

现在,随着格式的降低,让我们为话语创建一些模板。例如:

"What is that {{descriptor}} (photo|picture) (of|from)"

以及

"Download the (photo|picture) {{to_file_path}}"

为此,我们运行以下命令:

frompprintimportpprintfromutter_moreimportUtterMoreum=UtterMore("What (is*s|are*p) (that^s|those^p) {{descriptor}} (photo|picture)(^s|s^p) (of|from)","Download the (photo|picture) {{to_file_path}}")um.iter_build_utterances()pprint(um.utterances)

这将显示:

[['What is that {descriptor} photo of','What is that {descriptor} photo from','What is that {descriptor} picture of','What is that {descriptor} picture from','What is that photo of','What is that photo from','What is that picture of','What is that picture from','What are those {descriptor} photos of','What are those {descriptor} photos from','What are those {descriptor} pictures of','What are those {descriptor} pictures from','What are those photos of','What are those photos from','What are those pictures of','What are those pictures from'],['Download the photo {to_file_path}','Download the photo','Download the picture {to_file_path}','Download the picture']]

在这里我们可以很容易地遵循复数的语法规则如果我们想保存话语,以便将它们上传到我们的Alexa技能中,我们只需要:

um.save_for_alexa(PATH_TO_DIRECTORY,FILE_NAME)

在这里,我们将找到CSV文件的正确格式上传

上传话语

  1. 在进入指定意图的选项卡后,单击页面右上角的“批量编辑”。

  1. 浏览或拖放以前生成的csv,它将填充文本字段。

  1. 按“提交”按钮,将填充“话语”字段。

就这样,不需要手动输入成百上千个令人烦恼的相似短语

其他特点

  • 您可以在将类设置为这样之后添加话语模板:
fromutter_moreimportUtterMoreum=UtterMore()um.add_utterance_template("What (is*s|are*p) (that^s|those^p) {{descriptor}} (photo|picture)(^s|s^p) (of|from)")um.add_utterance_template("Download the (photo|picture) {{to_file_path}}")um.iter_build_utterances()um.save_for_alexa(PATH_TO_DIRECTORY,FILE_NAME)

这将产生与上面相同的csv

  • 继续上面的代码,然后您可以将这些语句通常保存为常规csv或类似这样的文本文件:
# Saves as utterances.txt with new line separatorsum.save_utterances(PATH_TO_DIRECTORY,'utterances','txt')# Saves as utterances.csv as actual comma-separated valuesum.save_utterances(PATH_TO_DIRECTORY,'utterances','csv')
  • 话语可以从模板创建,而无需将其添加到uttermore对象中,因此
frompprintimportpprintfromutter_moreimportUtterMoreum=UtterMore()utterances=um.build_utterance("What (is*s|are*p) (that^s|those^p) {{descriptor}} (photo|picture)(^s|s^p) (of|from)")pprint(utterances)

将输出:

[['What is that {descriptor} photo of','What is that {descriptor} photo from','What is that {descriptor} picture of','What is that {descriptor} picture from','What is that photo of','What is that photo from','What is that picture of','What is that picture from','What are those {descriptor} photos of','What are those {descriptor} photos from','What are those {descriptor} pictures of','What are those {descriptor} pictures from','What are those photos of','What are those photos from','What are those pictures of','What are those pictures from']]

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JavaFX进度条从单独的函数更改而来   jvm使用java服务器选项   java在<li>元素中查找同名的最后一个链接   java问题将参数传递给不同公共类中的构造函数   如何在php中从java函数中获取字符串   java如何在Android中动态显示多个tile   java仅使用Ribbon而不使用任何服务注册表是否可以实现负载平衡?   Jersey 1.19版本的java Swagger JAXRS出现“冲突URI模板”错误   带H2数据库的java Spring boot jpa   从12:00:00到00:00:00的日期转换   Android中的java如何设置文本?   java密钥库“不支持的保护参数”   http使用Java在Java中发送httprequest。净包   SpringJava刷新数据库   java在Spring Boot应用程序中使用嵌入式MongoDb和MongoTemplate失败   java需要什么MatOfMatch对象?   xml使用Java中的合并算法将两个值合并为单个值   java SQLite数据库不保存数据为什么不工作