An ABNF Primer
Upcoming SlideShare
Loading in...5
×
 

An ABNF Primer

on

  • 5,625 views

An introduction to W3C's ABNF grammar syntax.

An introduction to W3C's ABNF grammar syntax.

Statistics

Views

Total Views
5,625
Views on SlideShare
3,311
Embed Views
2,314

Actions

Likes
0
Downloads
31
Comments
0

10 Embeds 2,314

http://nugram.nuecho.com 990
http://blog.nuecho.com 652
http://www.grammarserver.com 535
http://grammarserver.com 83
https://www.grammarserver.com 45
http://translate.googleusercontent.com 3
http://translate.googleusercontent.com 3
http://centos:8104 1
http://lelouch.nuecho.ad:8104 1
http://www.docshut.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Note that Nuance GSL grammars support mixed-mode grammars. This is not possible with SRGS grammars.
  • Note that in GSL grammars, if no rule is declared public, all rules are assumed public.
  • Note that some engines will accept numbers (e.g., “100”). This, however, is a bad idea to rely on this because we don’t know how it will be rendered.
  • Note that square brackets also group expansions
  • Note that some engines have limits on the number of repeats. For instance, Loquendo has a maximum of 30.
  • Note that the form “(E | $NULL)” is preferable when computing grammar weights based on data since we can have a weight computed for both branches.
  • Note that this may not be supported by all engines. Even if it is, it should be tested carefully. For instance, this does not work well with OSR 3.0 (don’t know about Nuance 9).

An ABNF Primer An ABNF Primer Presentation Transcript

  • An ABNF PrimerConcepts, 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
    Headers
    #ABNF 1.0 ISO-8859-1;
    language en-US;
    mode voice;
    root$yesOrNo;
    private$yesOrNo =
    yes {out.value = 'yes'}
    | no {out.value = 'no'}
    ;
    Rules
    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
    Copyright © 2010 Nu Echo Inc.