Dynamic Grammar Instantiation

To instantiate a dynamic grammar, NuGram Server needs a mapping between the variables used in the grammar template and the actual values. This mapping is called an instantiation context. In NuGram Server, instantiation contexts are created by context initializers, which are Java objects implementing the ContextInitializer interface.

Context Initializers

Context initializers essentially take the HTTP request parameters passed to the servlet and turn them into a Java Map object, the instantiation context. The keys in the map are strings and the values are Java objects. See the Javadoc documentation for more details.

Context initializers are associated with dynamic grammars in the web application's descriptor file "webapp/WEB-INF/web.xml" using servlet initialization parameters.

Common context initializers

NuGram Server comes with a number of predefined context initializers that can be used as is.

com.nuecho.application.grammarserver.servlets.DefaultContextInitializer

This context initializer simply returns a copy of the request parameter map as the instantiation context.

com.nuecho.application.grammarserver.servlets.SingleJsonContextInitializer

This context initializer expects the context parameter, in the HTTP parameters, to be a JSON string. That single string is converted to a JSON value representing the whole instantiation context map, from which keys and values are extracted to get the actual instantiation context.

com.nuecho.application.grammarserver.servlets.MultiJsonContextInitializer

This context initializer expects each HTTP parameter value to be a valid JSON string. Each such string is converted to a JSON value before being put in the instantiation context.

Custom context initializers

Custom, application-specific context initializers can be developed merely by implementing the ContextInitializer interface. These context initializers can be tested against the corresponding ABNF grammar templates directly in NuGram IDE by defining Java Contexts in the Context Editor.



Copyright © 2007,2008,2009,2010,2011 Nu Echo Inc.