drmfinlay / pyjsgf

JSpeech Grammar Format (JSGF) compiler, matcher and parser package for Python.
MIT License
53 stars 22 forks source link

Properly implement weights #11

Closed drmfinlay closed 5 years ago

drmfinlay commented 6 years ago

Weights for alternatives (defined under JSGF spec. section 4.3.3) are not properly implemented at the moment. They can be compiled, but the parser doesn't recognise them and the matching process ignores them.

Some changes can be made to AlternativeSet to implement them properly, such as a set_weight(self, weight, child) method. The matching process could use weights as an optimisation for matching more likely alternatives first or skipping alternatives with weights of zero.

It should be possible to change the parser to check for an optional weight value.

drmfinlay commented 5 years ago

Weights for alternatives are implemented for the AlternativeSet class and the parser now. I've added documentation for the new AlternativeSet.set_weight method and updated the parser's documentation. The matching process optimisations I mentioned above have also been implemented.

I've tested using weights with CMU Pocket Sphinx and they seem to work nicely.

These changes will be released in the next version (v1.6.0) soon!