axa-group / nlp.js

An NLP library for building bots, with entity extraction, sentiment analysis, automatic language identify, and so more

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to extract date when intent is "What date is today?"

al06825 opened this issue · comments

Software Version
nlp.js 4.27.0
node 18.16.0
npm 9.5.1
Operating System Win 10

I wanna extract date when intent is "What date is today?"
I got answer to be "Today is {{date}}" and it returned "Today is today" per the log below.

I wish to have answer like "Today is 2023-08-14"... but how?

Below is the log I got....

"intent": "inquiry.today",
"score": 0.9992725501954545,
"domain": "default",
"sourceEntities": [
{
"start": 12,
"end": 16,
"resolution": {
"values": [
{
"timex": "2023-08-14",
"type": "date",
"value": "2023-08-14"
}
]
},
"text": "today",
"typeName": "datetimeV2.date",
"entity": "date"
}
],
"entities": [
{
"start": 12,
"end": 16,
"len": 5,
"accuracy": 0.95,
"sourceText": "today",
"utteranceText": "today",
"entity": "date",
"rawEntity": "datetimeV2.date",
"resolution": {
"type": "date",
"timex": "2023-08-14",
"strValue": "2023-08-14",
"date": "2023-08-14T00:00:00.000Z"
}
}
],
"answers": [
{
"answer": "Today is today"
}
],
"answer": "Today is today",

@al06825 - not an official maintainer / nor a contributor. But pretty familiar with this package.

You need to refer to the NER Manager - Built-in Entites & register a entity extractor. Then you can parse the utterance with your chose of entity extractor to do something like this (assuming the extractor you choose has date supports).

Other than that - read the documentation (the page I linked to) & it should answer your question in full.

Hope this helps! 😄

@al06825 I didn't even realize either! Assuming you the date in that log is correct - you can use the entity for the date by grabbing the JSON value / key with corresponding entity.