Understanding natural language

After we have built an index, we can start creating our grammar file. This specifies what natural language the service can understand, and how it can translate into semantic query expressions. Open the academic.xml file to see an example of how a grammar file can look.

The grammar is based on a W3C standard for speech recognition, called SRGS. The top-level element is the grammar element. This requires a root attribute to specify the root rule, which is the starting point of the grammar.

To allow attribute references, we add the import element. This needs to be a child of the grammar element, and should come before anything else. It contains two required attributes: the name of the schema file to import, and a name that elements can use for referencing the schema. Note that the schema file must be in the same folder as the grammar file.

Next in line is the rule element. This defines a structural unit, which specifies what query expressions the service can interpret. A rule element requires an id attribute. Optionally, you can add an example element, which is used to describe phrases that may be accepted by the rule element. In that case, this will be a child element of the rule.

A rule element also contains an item element. This groups a sequence of grammar constructs, and can be used to indicate repetitions of the sequence. Alternatively, it can be used to specify alternatives, together with one-of elements.

One-of elements specify expansions among one of the item elements. The item by may be defined as a one-of element, with written by and authored by as expansions.

Using the ruleref element allows us to create more complex expressions by using simpler rules. It simply references other rules by adding a URI attribute.

The attrref element references an index attribute, which allows us to match against attributes in the index. The attribute URI is required, which must specify the index schema and attribute name to reference. This must match a schema that is imported through the import element.

The tag element defines the path through the grammar. This element allows you to assign variables or execute functions to help the flow of the grammar.

Once the grammar file is completed, we can compile it into binary grammar. This is done by running the following command:

kes.exe build_grammar Academic.xml Academic.grammar

Running this command will produce output similar to the following:

Input XML: ProgramsKESExampleAcademic.xml
Output Grammar: ProgramsKESExampleAcademic.grammar
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.210.205