samedi 22 août 2020

Generating String and ids depending on array content

My problem is too specific. I have an array containing the following types: intents, actions, start, next, end.

I will demonstrate the needed output string with 2 following examples:

Basic:
[intent,
action] 

Output => {id:1,path:[{action:'intent'}, {checkpoints:[{id: 2}]}]},
{id:2,start:false,path:[{action: 'action'}]}.

Advanced:
[
intent0,
action0,
  start,
     intent1,
     action1,
        start,
          intent2,
          action2
         next,
           intent3,
           action3
         end,
   next,
     intent4,
     action4
   end]

output =>
{id:1,path:[{action:'intent0'} , {checkpoints:[{id: 2} ] } ] },
{id:2,start:false,path:[{action: 'action0'},{checkpoints:[{id: 3}, {id:4}]}]},
{id:3,start:false,path:[{action:'intent1'},{action:'action1'},{checkpoints:[{id: 5}, {id: 6, }]}]},

    {id:5, start:false,path:[{action:'intent2'}, {checkpoints:[{id: 7}]}]},

    {id:6,start:false,path:[{action:'intent3' },{checkpoints:[{id: 8}]}]},

    {id:4,start:false,path:[{action:'intent4'}, {action:'bot_sad'}]},

{id:8,start:false,path:[{action: 'action2’}]},
{id:8,start:false,path:[{action: 'action3’}]},

If you got the way the format should be executed, you notice that you need to assign ids depending on the number of cases present in each "start". I have an idea on figuring out how many cases there is in each "start" by looping and starting a count when a start is obtained, but I stop the count if another "start" is seen inside that first one and resume whenever the end is met until I find the original "end". My problem isn't with figuring out cases as much as assigning ids. since if there is 2 cases 2 ids are to be assigned and then each of these ids should be re-written in order to specify their content. I can't seem to know how to keep track of the ids. since the first start could have 3 cases, ex: ids 1-2-3 and case 2 could have a start with 2 cases: 4-5 and so on...

Aucun commentaire:

Enregistrer un commentaire