用于python的jspeech语法格式(jsgf)编译器、匹配器和解析器包。

pyjsgf的Python项目详细描述


Build StatusDocs Status

jspeech语法格式(jsgf)编译器、匹配器和解析器包 Python。

jsgf是一种用于以文本形式表示语音语法的格式。 识别引擎。您可以阅读jsgf规范 here

pyjsgf可以用来构造jsgf规则和语法,并编译它们 在字符串或文件中,找到与语音匹配的语法规则 假设字符串。还支持将语音字符串与标记匹配。 还有语法、规则和规则扩展的解析器。

PyJSGF已经为Python2.7和Python3.5编写和测试过。

这个项目的文档是on readthedocs.org

安装

要安装pyjsgf,请运行以下命令:

$ pip install pyjsgf

如果您是为了developmentpyjsgf而安装,请克隆/下载存储库,移动到根目录并运行:

$ pip install -e .

用法示例

下面是如何创建jsgf语法的使用示例 一个规则,编译它并根据语音字符串找到匹配的规则 “Hello World”:

fromjsgfimportPublicRule,Literal,Grammar# Create a public rule with the name 'hello' and a Literal expansion 'hello world'.rule=PublicRule("hello",Literal("hello world"))# Create a grammar and add the new rule to it.grammar=Grammar()grammar.add_rule(rule)# Compile the grammar using compile()# compile_to_file(file_path) may be used to write a compiled grammar to# a file instead.# Compilation is not required for finding matching rules.print(grammar.compile())# Find rules in the grammar that match 'hello world'.matching=grammar.find_matching_rules("hello world")print("Matching: %s"%matching[0])

运行上述代码将输出:

#JSGF V1.0;
grammar default;
public <hello> = hello world;

Matching: PublicRule(name='hello', expansion=Literal('hello world'))

语法的第一行可以使用jsgf_version更改, charset_name,和language_name成员$ 上课。

pyjsgf/examples中有一些用法示例,可以帮助您入门。

多语言支持

由于python支持unicode,pyjsgf可以与unicode一起使用 用于语法、导入和规则名称以及规则文本的字符。 如果需要,最好使用python 3或更高版本 默认情况下,字符串是Unicode字符串。

如果必须使用Python2.x,则需要将Unicode字符串定义为 不是u"text"就是unicode(text, encoding),这有点 麻烦。如果要在源代码文件中定义Unicode字符串, 您需要定义source code file encoding

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

推荐PyPI第三方库


热门话题
java JTable无法向新创建的列添加值   java如何调整JEditorPane中编辑区域的大小?   Java通过反射确定未知数组中的数组大小   java Intellij Idea有时无法按其预期的方式构建应用程序   java Swing GUI带有IntelliJ错误“contentPane不能设置为null”从终端编译时   如何将这些通用方法调用从C#转换为Java   在null上找不到java属性或字段“index”   从Java HashMap获取整数值时是否需要调用intValue()方法?   java Android谷歌地图获取相机中的图像块   unix无法捕获JAVA中“who m”命令的输出   java,同时将邮件发送到“收件人”标题“我”中的多个收件人   在java中向链表添加未知数量的节点   无法为Heroku上的discord bot设置java端口   java使用Apache HttpClient进行选项请求   与元素类型“ApplicationName”关联的属性“Application Version”需要java Open quote   Android Studio Java中的两个变量求和