Copyright © 2009, 2010 Nu Echo Inc. All Rights Reserved.

com.nuecho.api.grammar
Interface ContextInitializer

All Known Implementing Classes:
DefaultContextInitializer, MultiJsonContextInitializer, SingleJsonContextInitializer

public interface ContextInitializer

A ContextInitializer is an object used to programmatically create an instantiation context that will be merged with a dynamic grammar to produce a static grammar.

An instantiation context is a mapping between variable (strings) and arbitrary values. The variables correspond to the top-level variables of a dynamic grammar that are not defined in the grammar document (using @for or @var directives, macro parameters, etc.).

Instantiation contexts are used by both NuGram Server and NuGram IDE.

Grammar fragments

In some situations, it is more practical to create some parts of the generated grammar programmatically. In these cases, the supplied grammar fragment factory object is used to create these grammar expansions. The expansions are then put in the instantiation context and inserted in the dynamic grammar using the @fragment directive).

Cache control

The context initializer is also responsible for providing fine-grained control of the grammar caching strategy. The CacheControl object provides several methods to give hints to the ASR engine on how to cache the generated grammar.

Version:
1.0.0
See Also:
GrammarFragmentFactory, CacheControl

Method Summary
 java.util.Map getContext(java.util.Map parameters, GrammarFragmentFactory factory, CacheControl cacheControl)
          Computes an instantiation context from a map of parameters.
 

Method Detail

getContext

java.util.Map getContext(java.util.Map parameters,
                         GrammarFragmentFactory factory,
                         CacheControl cacheControl)
                         throws ContextInitializationException,
                                NotModifiedException
Computes an instantiation context from a map of parameters. Each parameter name (a string) is bound to an array of values (an array of Java strings).

Parameters:
parameters - the input parameters
factory - a grammar fragment factory object
cacheControl - a cache control object
Returns:
the instantiation context that maps strings to objects.
Throws:
ContextInitializationException - when an error occurs during the building of the instantiation context
NotModifiedException - if the generated grammar need not be recomputed because it is already cached by the ASR engine

Copyright © 2009, 2010 Nu Echo Inc. All Rights Reserved.