Use a Lua Scripts to Retrieve Facts

You can configure a Fact Bank system in HPE Answer Server that calls a Lua script to get facts. HPE 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 the standard Fact Store formats, you can use a Lua script to retrieve the information directly.

NOTE:

When HPE Answer Server processes a question in an Ask action, it might find multiple ways to parse the question. This might mean that HPE 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 HPE Answer Server can call. By default, HPE 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:

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 HPE Answer Server returns the information to the end user.

The Lua script has access to Lua functions and methods that are included in many HPE IDOL products, as well as functions and methods that are specific to HPE Answer Server. For full details and examples of the available functions, refer to the HPE Answer Server Reference.


_HP_HTML5_bannerTitle.htm