Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when process regex with group #1358

Open
luisgallineto opened this issue Sep 16, 2023 · 0 comments
Open

Error when process regex with group #1358

luisgallineto opened this issue Sep 16, 2023 · 0 comments

Comments

@luisgallineto
Copy link

luisgallineto commented Sep 16, 2023

Describe the bug
When we process a regex with a group that result of group is undefined, the library return this error: "ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'length')"
The problem occurs on the path "node_modules/@nlpjs/ner/src/extractor-regex.js".
I added some consoles on the file and the problem is on "else", specifically at "match[1].length". When process, the first position is the match and has value, the second position is the group, but, sometimes, the group can be undefined, as soon as I describe below.

if (match.length === 1) {
          result.push({
            start: match.index,
            end: regex.lastIndex - 1,
            accuracy: 1,
            sourceText: match[0],
          });
        } else {
          const index = utterance.indexOf(match[1]);
          result.push({
            start: index,
            end: index + match[1].length - 1,
            accuracy: 1,
            sourceText: match[1],
          });
        }

To Reproduce
Steps to reproduce the behavior:

  1. Add a new regex below and train.
    Exemple: /^[a-zA-ZÀ-ÿ]+ [a-zA-ZÀ-ÿ]+([ ]+[a-zA-ZÀ-ÿ]+)*$/gm

  2. Process a new message per exemple: test test

  3. The error in terminal will be:
    "ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'length')..."

Expected behavior
Process without error. I believe that a simple and working solution is to clear null properties before performing validations on the array.

Desktop (please complete the following information):

  • OS: macOS
  • node-nlp: ^4.26.1
  • Node version: v20.3.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant