Oratio
Emergent natural language processing
Getting started
Create a new HiveMind with the HiveMindBuilder:
const mind = HiveMindBuilder.createEmpty()
.registerModule(CoreHiveMindModule.CORE_HIVE_MIND_MODULE)
.registerModule(MathHiveMindModule.MATH_HIVE_MIND_MODULE)
.build();
Give it user input:
const response: Promise<IHiveResponse> = mind.process(input, locale, clientModel)
Show any applicable output to the user in any desired way, the response has the following fields:
{
responses(): SingleResponse[],
single(): SingleResponse,
response(): string
}
Where a SingleResponse
contains the following:
{
// message key of the response, the application can translate to any language
response: string,
// possible parameters for the output / translation
params: string[],
// the certainty, if too low handle accordingly
certainty: number,
// a possible action the user wanted to perform, this is especially useful for application specific neurons
action: () => void,
// the scope to perform the action on, to allow using injected services in the action
context: any
}
Adding custom neurons
Create a neuron which implements the following interface:
public process(words: string[], locale: string, context: RequestContext): Promise<INeuronResponse>
Add the neuron in the builder:
const mind = HiveMindBuilder.createEmpty()
.registerModule(CoreHiveMindModule.CORE_HIVE_MIND_MODULE)
.registerModule(MathHiveMindModule.MATH_HIVE_MIND_MODULE)
.registerNeurons([new YourNeuronHere()])
.build();
The array can obviously contain more neurons, as more custom neurons are created simply add them to the array.
Emergent system
There is no single major intelligence responsible for the system, instead every neuron processes every input and determines whether it can do anything with it. All neurons are collected in the hive, the hive makes sure all neurons receive user input until a response is found.
Neurons
A neuron can easily be added to the hive, all it has to do is implement the following function:
export interface IHiveMindNeuron {
process(userInput: UserInput,
context: RequestContext): Promise<INeuronResponse>;
}
then it has to be registered with the hive that manages all neurons.
Hive
The Hive processes all user input, it favors neurons who succesfully process user-input. The hive is constantly changing the order of the neurons to make sure the hive adjusts to what the user is currently doing.
Response
The response always contains a response, which is a code that can be localized by other applications. The response can also include an action (function: () => void) which the neuron thought the user intended. The action can be executed on a certain context, allowing the calling-party to use injected services in the action.