Use a Lua Scripts to Retrieve Facts
You can configure a Fact Bank system in Answer Server that calls a Lua script to get facts. Answer Server calls out to this script whenever it processes an Ask
action that includes the Lua Fact Bank system, and returns the response as an answer.
For example, you might have an external data source or API that contains the factual information. Rather than convert the information into a Fact Store database format, you can use a Lua script to retrieve the information directly.
NOTE: When Answer Server processes a question in an Ask
action, it might find multiple ways to parse the question. This might mean that Answer Server calls your script multiple times for a single Ask
action, although some of the parsings might not match any available facts.
To use a Lua script, you must ensure that the Fact Bank configuration has the BackendType
configuration parameter set to Lua
. See Configure a Fact Bank to Call a Lua Script.
Create a Fact Retrieval Script
The Lua script must implement a script function that Answer Server can call. By default, Answer Server calls the fetch
function, but you can use a different name and set the ScriptFunction
configuration parameter to the appropriate function name.
The script function must accept a single LuaIncompleteFact
object, and return an array of LuaCodifiedFact
objects.
For example, the following fetch function always returns an empty array:
function fetch(incomplete) return {} end
The LuaIncompleteFact
object represents the question that has been asked. It has at most one target element missing, which the Lua script must attempt to find the information for.
The LuaIncompleteFact
object also includes:
-
an entity, which is the object of the question (unless the question target is the entity itself, in which case the entity value is empty).
-
zero or more
LuaIncompleteFactProperty
objects, which define a property of the question. Properties might be negated (that is, you want to find facts that do not match the property).Each
LuaIncompleteFactProperty
object can also contain zero or moreLuaIncompleteFactQualifier
objects, which define a qualifier for the property. Qualifiers might be negated (that is, you want to find facts where the property does not match the qualifier).
You initialize the LuaCodifiedFact
object from a LuaIncompleteFact
object by using the initToCodifiedFact
method. The LuaCodifiedFact
object must not have any missing elements (for example, it must have an entity value).
The LuaCodifiedFact
can also include zero or more LuaCodifiedFactProperty
objects, which specify a property of the fact. Each LuaCodifiedFactProperty
object can also have zero or more LuaCodifiedFactQualifier
objects.
Entities, properties, and qualifiers are all coded on entry into the function, and decoded before Answer Server returns the information to the end user.
The Lua script has access to Lua functions and methods that are included in many IDOL products, as well as functions and methods that are specific to Answer Server. For full details and examples of the available functions, refer to the Answer Server Reference.