axa-group / nlp.js

An NLP library for building bots, with entity extraction, sentiment analysis, automatic language identify, and so more
MIT License
6.27k stars 620 forks source link

Unable to recognize intent #934

Closed obaid closed 1 year ago

obaid commented 3 years ago

Describe the bug When having a built-in entity as the only input for an intent, the result comes back as 'None'

To Reproduce

Run this example:


const { NlpManager } = require('node-nlp');

const locale = "en";

const manager = new NlpManager({ autoSave: false, languages: [locale], forceNER: false, nlu: { useNoneFeature: false, log: false, spellCheck: true }, ner: { threshold: 0.9 }, log: true }); 

manager.addDocument(locale, "%phonenumber% here", "phone.intent");
manager.addDocument(locale, "%phonenumber%", "phone.intent");
manager.addDocument(locale, "it is %phonenumber%", "phone.intent");
manager.addDocument(locale, "it is %phonenumber%", "phone.intent");

manager.train().then(() => {
    manager.process('8929992222 here').then(result => console.log(result)); //works
    manager.process('8929992222').then(result => console.log(result)); //doesn't work
});```

**Expected behavior**
It should return `phone.intent` 
obaid commented 3 years ago

any ideas on this?

Apollon77 commented 2 years ago

Try with v4 ... at least with my latest PRs (still unmerged) it should work. I just tried it:

{
  "locale": "en",
  "utterance": "8929992222 here",
  "languageGuessed": false,
  "localeIso2": "en",
  "language": "English",
  "nluAnswer": {
    "classifications": [
      {
        "intent": "phone.intent",
        "score": 1
      }
    ]
  },
  "classifications": [
    {
      "intent": "phone.intent",
      "score": 1
    }
  ],
  "intent": "phone.intent",
  "score": 1,
  "domain": "default",
  "sourceEntities": [
    {
      "start": 0,
      "end": 9,
      "resolution": {
        "value": "8929992222"
      },
      "text": "8929992222",
      "typeName": "number"
    },
    {
      "start": 0,
      "end": 9,
      "resolution": {
        "value": "8929992222",
        "score": "0.3"
      },
      "text": "8929992222",
      "typeName": "phonenumber"
    }
  ],
  "entities": [
    {
      "start": 0,
      "end": 9,
      "len": 10,
      "accuracy": 0.95,
      "sourceText": "8929992222",
      "utteranceText": "8929992222",
      "entity": "number",
      "resolution": {
        "strValue": "8929992222",
        "value": 8929992222,
        "subtype": "integer"
      }
    },
    {
      "start": 0,
      "end": 9,
      "len": 10,
      "accuracy": 0.95,
      "sourceText": "8929992222",
      "utteranceText": "8929992222",
      "entity": "phonenumber",
      "resolution": {
        "value": "8929992222",
        "score": "0.3"
      }
    }
  ],
  "actions": [],
  "answers": [],
  "sentiment": {
    "score": 0.25,
    "numWords": 2,
    "numHits": 1,
    "average": 0.125,
    "type": "senticon",
    "locale": "en",
    "vote": "positive"
  }
}