-
Notifications
You must be signed in to change notification settings - Fork 471
Extend Entity Recognition Capabilities
Wit.ai is a web service provided by Facebook to provide an NLU entity identification. Wit.ai makes it easy for developers to build applications and devices that you can talk or text to.
External services or libraries can be easily integrated through NLP pipeline technology. We use an example to illustrate the integration of Wit.ai's entity recognition service into BotSharp's NER pipeline.
write a new class which implements the INlpPipeline and INlpNer. INlpPipeline interface allows this class to run in the pipeline architecture. INlpNer interface describes the standard Ontology types that this class can identify for BotSharp definitions.
public class WitAiEntityRecognizer : INlpPipeline, INlpNer
{
public List<OntologyEnum> Ontologies { get; }
public async Task<bool> Train(Agent agent, NlpDoc doc, PipeModel meta)
{
}
public async Task<bool> Predict(Agent agent, NlpDoc doc, PipeModel meta)
{
}
}
For complete code examples, please refer to: WitAiEntityRecognizer
Update bot.json, add WitAiEntityRecognizer to pipeline.
{
"Pipe": "SpaCyTokenizer, CRFsuiteEntityRecognizer, WitAiEntityRecognizer",
"WitAiEntityRecognizer": {
"url": "https://api.wit.ai",
"resource": "message",
"serverAccessToken": "SERVER_ACCESS_TOKEN",
"version": "20180811"
}
}
curl -X GET "http://localhost:3112/v1/Agent/Train/{agentId}" -H "accept: text/plain"
Test in a sentence: "Fly to Chicago tomorrow 9 am.".
curl -X POST "http://localhost:3112/v1/query" -H "accept: text/plain" -H "Authorization: Bearer CLIENT_ACCESS_TOKEN" -H "Content-Type: application/json-patch+json" -d "{ \"lang\": \"en\", \"query\": \"Fly to Chicago tomorrow 9 am.\"}"
Response:
{
"timestamp": "2018-08-12T18:12:34.4820795Z",
"lang": "en",
"result": {
"parameters": {
"datetime": "2018-08-13T09:00:00.000-07:00",
"location": "Chicago"
},
"resolvedQuery": "Fly to Chicago tomorrow 9 am."
}
}
Correctly identified Chicago and tomorrow's time.
It's so excited that you can add new NER capabilities to BotSharp without spending too much effort. The ASP.NET Core-based technology stack also makes enterprise developers more friendly and easy to get started.