I am working with a user input that has to be processed based on the set of rules. Using nools but its a pain in the back when comes to javascript ES6 operations like IIFE, map-reduce, nested sort.

Talking about RETE algo in 2022 might sound overwhelming but its really handy and makes sense. I've been using nools(which is deprecated and no more supported, Duh!) and it works just fine when you define straight forward when-> then.

But if I want to do some JS operation on the output, sometimes it runs and fails sometimes. This behavior makes me think if I am doing something wrong OR its not stable anymore(as not actively supported now)

What I am trying to do: My data has a very bad DS pattern with nested array objects and strings together.

Data->

const matchOutput = [
  {
    X: ['None'],
    Y: ['None'],
    Z: ['1 mg/m3 STEL'],
    A: ['None'],
    name: 'AMER'
  },
  {
    X: [
      '2 mg/m3 TWA (as Sn) Inhalable fraction.',
      '0.2 mg/m3 STEL (as Sn)',
      '0.1 mg/m3 TWA (as Sn)'
    ],
    Y: ['0.1 mg/m3 PEL (as Sn)', '0.1 mg/m3 TWA (as Sn)'],
    Z: ['None'],
    A: ['0.1 mg/m3 REL (as Sn)'],
    name: '2-ethylhexanoate;tin(2+)'
  },
  {
    X: ['0.5 mg/m3 TWA (as Hf)'],
    Y: ['None'],
    Z: ['None'],
    A: ['0.5 mg/m3 REL (as Hf)'],
    name: 'Hafnium dioxide'
  },
  {
    X: ['300 ppm STEL', '200 ppm STEL'],
    Y: ['200 ppm PEL', '300 ppm PEL-STEL', '200 ppm TWA'],
    Z: ['None'],
    A: ['200 ppm REL', '300 ppm REL'],
    name: 'MEK'
  }
];

Inside my nools rule, I am doing a sort operation once it matches.

matchOutput.sort(()=>{
            exposureControlList.forEach(obj => {
                for (let key in obj) {
                    if (key !== 'name'){
                        obj[key].sort((a, b) => b.localeCompare(a, 'en', { numeric: true }))});
                    } 
                }
            exposureControlList.sort((a, b) => a.name.localeCompare(b.name, 'en'));
            return exposureControlList;
        });

Which should sort the inner array into desc numeric values and outer array on key name.

This sort function is working fine if in a JS file you put the data and do above sort function, but in .nools file it fails.

I am relatively new to nools, so few queries:

  1. I could not find any extension in VS Code to see .nools file properly (not in plain text)
  2. If the function is wrong, is there any way to debug the .nools file?
  3. Can you independently test a .nools file?

Thanks for your time.

0

There are 0 answers