Date post: | 20-Aug-2015 |
Category: |
Technology |
Upload: | nu-echo-inc |
View: | 5,705 times |
Download: | 0 times |
An ABNF Primer
Concepts, structure, syntax
Introduction
• W3C standard– http://www.w3.org/TR/speech-grammar– W3C recommandation:
• March 16th, 2004– Defines both the XML form and the Augmented BNF (ABNF)
form • They are equivalent
• Supported by a complete development environment• NuGram IDE
Copyright © 2010 Nu Echo Inc.
Structure of an ABNF Grammar
#ABNF 1.0 ISO-8859-1;language en-US;mode voice;root $yesOrNo;
private $yesOrNo = yes {out.value = 'yes'} | no {out.value = 'no'};
Rules
Headers
Copyright © 2010 Nu Echo Inc.
Comments
• C/C++/Java Comments– // to end of line– /* ... */
• Documentation comments– /** ... */– @example to document sample sentences– Can appear before rule definitions, root header, and language
header.
Copyright © 2010 Nu Echo Inc.
GRAMMAR HEADERS
Copyright © 2010 Nu Echo Inc.
Grammar Headers
• Self-identifying header– Mandatory– Encoding is optional– Can be preceded by byte order mask (BOM)
Ex:#ABNF 1.0;#ABNF 1.0 UTF-8;
Copyright © 2010 Nu Echo Inc.
Grammar Headers
• Language– Identifies the language of the document– Required for voice grammars– Languages codes defined by RFC 3066
Ex:language en;language fr-CA;
Copyright © 2010 Nu Echo Inc.
Grammar Headers
• Mode– Indicates the type of input– Optional header– 'dtmf' or 'voice' (default)
Ex:mode voice;mode dtmf;
Copyright © 2010 Nu Echo Inc.
Grammar Headers
• Root– Defines the grammar's top-level rule– Optional– Root rule can be either public or private
Ex:root $rootRule;
Copyright © 2010 Nu Echo Inc.
Grammar Headers
• Tag-format– Declares content type for the semantic tags (actions)– Value is a URI– Recognition-engine specific
Ex:tag-format <semantics/1.0>; (SISR)tag-format <Nuance>; (Nuance)tag-format <swi-semantics/1.0>; (Nuance)tag-format <semantics-ms/1.0>; (Microsoft)tag-format <semantics/1.0.2006>; (LumenVox)
Copyright © 2010 Nu Echo Inc.
Grammar Headers
• Lexicon– Specifies a pronunciation lexicon to use (a URI)– One or more occurrences – Format is engine-specific
Ex:lexicon <../lex/names.pls>;
Copyright © 2010 Nu Echo Inc.
Grammar Headers
• Base URI– Base URI for all relative URIs in the document– Optional– Has precedence over the meta header
Ex:base <http://localhost:8080/>;
Copyright © 2010 Nu Echo Inc.
Grammar Headers
• Meta and Http-Equiv– Metadata attached to the grammar– Properties taking precedence over HTTP headers– One or more occurrences
Ex:meta “Author” is “J. Doe”;http-equiv “Expires” is “0”;
Copyright © 2010 Nu Echo Inc.
Relative URI Resolving
• Base URI :– base header– meta “base” header – metadata from protocol interaction (ex. HTTP header)– base URI of the current document
Ex:meta “base” is “http://example.com/grammars/date.abnf”;
meta “base” is “http://example.com/grammars/”;
base “http://example.com/grammars/date.abnf”;
Copyright © 2010 Nu Echo Inc.
Relative URI Resolving
• ASR Engines behave differently
• OSR / Nuance 9 • Full conformance to RFC 2396 (now obsoleted by RFC 3986)
• Loquendo ASR• Base URI must not contain the document’s name
• Best practice: always end the URI with a “/”
Copyright © 2010 Nu Echo Inc.
GRAMMAR RULES
Copyright © 2010 Nu Echo Inc.
Grammar Rules
• A rule is an association between a name and an expansion– Rule names are unique in a grammar– Rules can be either public or private
• A public rule is visible outside the scope of the grammar document• A rule is private by default
• An expansion describes a set of word sequences (sentences)
Copyright © 2010 Nu Echo Inc.
Grammar Rules
• Syntax of a rule definition:
public $name = expansion;or
private $name = expansion;or
$name = expansion;
Copyright © 2010 Nu Echo Inc.
Rule names
• A rule name must be a valid XML Name– http://www.w3.org/TR/2000/REC-xml-20001006#NT-Name
• But:– Cannot be NULL, VOID, GARBAGE– Must not contain '.', ':', '-'
• Rule names begin with '$'– Ex: $number $names $digits
Copyright © 2010 Nu Echo Inc.
BASIC EXPANSIONS
Copyright © 2010 Nu Echo Inc.
Expansions
• Words (aka tokens)– A string that the recognizer can convert to a phonetic
representation– Typically a word in the specified language– Words are delimited by whitespaces, and
$, <, >, (, ), /, |, [, ], {, }, !– Can be enclosed in “”
Copyright © 2010 Nu Echo Inc.
Expansions
• Words (cont'd)– Examples:
• hello• Montréal• trente-deux• “San Francisco”
Copyright © 2010 Nu Echo Inc.
Expansions
• Words (cont'd)– Tips:
• Avoid acronyms, like “IBM” (unless word is in the dictionary)Separate each letter with a “.” or “_”.
– Good: “I.B.M.”, “I triple E”– Bad: “IBM”, “IEEE”
• Don't use abbreviations. – Replace “Dr.” with “Doctor”, “St.” with “street"
• Use spelled forms for numbers– Use “One hundred” instead of “100”
Copyright © 2010 Nu Echo Inc.
Expansions
• Sequences– Whitespace-separated expansions– Each expansion must match in turn
Ex: I would like to $day $month $year
Copyright © 2010 Nu Echo Inc.
Expansions
• Choices– To match one of a number of choices– Expansions separated by '|'
Ex: one | two | three | four
$yes | $no {answer = 'no'}
Copyright © 2010 Nu Echo Inc.
Expansions
• Grouping– Parentheses group expansions (as do square brackets)– Enables encapsulation– Useful to ensure correct precedence in parsing a group of
expansions
Ex:no (it's | it is) not(oh | zero) { out = '0'}
Copyright © 2010 Nu Echo Inc.
Expansions
• Rule References– References to named expansions– Three types:
• Local references• External references• Special rule names
Copyright © 2010 Nu Echo Inc.
Expansions
• Local rule references– References to rules declared in the same document
Ex: $date $civicNumber $digit
Copyright © 2010 Nu Echo Inc.
Expansions
• External rule references– Implicit
• Uses root rule• Root rule can be either public or private$<documentURI>
– Explicit• Rule must be declared public$<documentURI#ruleName>
– Media type can be specified:$<documentURI#ruleName>~<mediatype>
Copyright © 2010 Nu Echo Inc.
Expansions
• External rule references (cont'd)
Ex:$<../common/numbers.abnf>
$<../common/numbers.abnf#oneToNine>
$<http://localhost:8800/names.abnf?id=45>
$<names.abnf?id=45>~<application/srgs+xml>
Copyright © 2010 Nu Echo Inc.
Expansions
• Special rule references– $NULL
• matches automatically• equivalent to ()
– $VOID• matches nothing
– $GARBAGE• matches anything• implementation-specific behavior
Copyright © 2010 Nu Echo Inc.
ADVANCED EXPANSIONS
Copyright © 2010 Nu Echo Inc.
Expansions
• Repeats– Force the repetition of an expansion– Bounded: <n-m> or <n>– Unbounded: <n->
Ex:$digit <7> | $digit <10>$topping <1->
Copyright © 2010 Nu Echo Inc.
Expansions
• Repeats (cont'd)– Special case: [ E ]
– Equivalent to E <0-1>– Or to ( E | $NULL )
Ex:$hesitation = [euh] ok [euh];$date = $month [$year];
Copyright © 2010 Nu Echo Inc.
Expansions
• Repeats (cont'd)– The probability of the repetition can be specified– Syntax: <n-m /prob/>– prob is value between 0.0 and 1.0
Ex: $digit <2-4 /0.8/> $topping <1- /0.785/>
Copyright © 2010 Nu Echo Inc.
Expansions
• Choices – Weighting– Multiplying factor attached to a choice
• Positively biased when weight > 1.0• Negatively biased when weight < 1.0
– Default weight is 1.0– Syntax: /n./ or /n.n/ or /.n/ or /n/
Ex:(/1.7/ New York | /0.4/ Newark)
Copyright © 2010 Nu Echo Inc.
Expansions
• Language– Overrides the default language– Applies to all words of the target expansion– Syntax: E!code
Ex:yes | oui!fr-CA(Michel Tremblay|André Roy)!fr-CA
Copyright © 2010 Nu Echo Inc.
Expansions
• Tags– To attach “meaning” to a sentence– Arbritrary strings enclosed in {}– Content depends on value of the tag-format header
Ex: (two | second) {out.day = 1} $number {val = number.val}
Copyright © 2010 Nu Echo Inc.
Expansions
• Tags (cont'd)– Use {!{ ... }!} when tag must contain '}'.– Can appear as grammar header
• must be followed by ';‘• Ideal for defining global functions or data structures
Copyright © 2010 Nu Echo Inc.
Precedence
Priority Expansions
1 Rule reference, token (quoted or unquoted), tag
2 Parentheses and square brackets
3 Repeat operator and language attachment
4 Sequence
5 Choices
Copyright © 2010 Nu Echo Inc.