drmfinlay / pyjsgf

JSpeech Grammar Format (JSGF) compiler, matcher and parser package for Python.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for jsgf tags?

embie27 opened this issue · comments

Are the JSGF tags supported by your implementation? I couldn't find anything.

Yes, you can set tags for rule expansions using something like:

from jsgf import PublicRule, Grammar
r = PublicRule("hello", "hello world")
r.expansion.tag = "greet"
g = Grammar()
g.add_rule(r)

The strings returned from r.compile() and g.compile() should contain the tagged rule:
'public <hello> = hello world { greet };'

Sorry you couldn't find that, this project needs some documentation work done.

Matching based on tags instead of speech strings could be done by adding alternatives to the Grammar.find_matching_rules and Rule.matches methods. I can add those in if you'd like.

It would be great if you could implement it! 👍

I've added a few commits on this in the develop branch. The example I added shows use of Grammar.find_tagged_rules and Rule.tags.

Let me know if that's what you had in mind, any suggestions on the API, etc :)

First of all, thank you for your fast answers and your great project here.
The idea I had in mind is that you can find matching rules for a sentence and got all used tags back.
For example:

<command> = (open {OPEN} | close {CLOSE}) the file;

And then if you call the method for getting the matched tags with argument "open the file" you get back an array with the element "OPEN". If there are more tags in the rule or in referenced rules which match the argument they should be included in the array.

You're welcome, glad you like it!

Thanks for the example, I get the idea now. This could be integrated into the expansion matching process. A Rule.matched_tags property could be added which will do what you want after Rule.matches is called. A Rule.get_tags_matching(speech) method could also be added that does both.

Do you think tags of referenced rules should be included for the methods and property I added before? Changing that is simple.

Maybe you could add a boolean parameter which says if they should be included or not.

Okay, everything should be working nicely now. I've updated the tag example file using the new Rule.get_tags_matching method. I also used your example above instead of my hello world example.

I went with just using referenced rules every time, mostly because the method names were getting a bit confusing, e.g. get_matched_tags (instead of the property) vs get_tags_matching. I could add something in later on, but there is always the filter function for cases where tags of referenced rules aren't wanted.

Let me know if this works for you and I'll release the recent commits as version 1.3.0.

Everything works as excepted. Nice work!