用于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是否在servlet中检索上一页路径?   Java抱怨在开关的默认情况下未初始化最终字段   Java泛型:为什么编译器不能判断这个类<t>对象与这个类的类型参数的对象的类具有相同的类型?   Java:继承方法中使用的私有变量   HibernateJava。ClassCastException:java。lang.Integer不能强制转换为abc。def。我的项目。奥姆。EmployeeTopMetaData   http java发布和下载文件   java改进条件检查   java如何将2d数组的条目作为键放在地图中   java如何获取传递给运行时的值。getRuntime。JUnit测试用例中的exit(value)   java注释来创建所有可能的构造函数   自动建议列表:java。lang.IllegalArgumentException:在XPath表达式为null时找不到元素   为什么MapAPI在Java中不提供流功能?   gradle不导入本地java库   尽管我使用的是SessionCreationPolicy,java Spring安全性似乎仍在使用会话。无国籍   使用java查找MongoDB中数组元素的平均值