cancel
Showing results for 
Search instead for 
Did you mean: 

Logic to separate sentence into word

NayanaH_P
Level 4
Take input as any sentence. Use logic to separate out each word in the sentence and fill each word in different rows of collection. The code should work for any sentence we take (may it be of any number of words)

------------------------------
Nayana H P
------------------------------
1 BEST ANSWER

Helpful Answers

PabloSarabia
Level 11
Hi @NayanaH_P

The easy way to achieve this is using the split function that you found in the "Utility - Strings" VBO.

But, if you are asking for the logic behind , let's think how can we build our own "Split" function in Blue Prism.

First you need is to implement a loop. When we talk about loops, they don't necessarily have to be loops made with the Loop Stage. A circular path is also a loop. 

We need a circular path, because we don't have any collection to iterate with the Loop stage. But, what need to put inside? Usually, when we talk about separate "things", we have a full list of this "things" (a full sentence with words), and this "things" are separated from each other by a separator.

Understanding this, you have a sentence with words, and this words are separate by an space. The first word start in the position 0 of the sentence until the first separator, the second one start in the first separator until the second separator....

19473.png
So far so clear.

To know the position of a character inside the text you need to use the function "InStr". Of course, our text have 3 separators, this functions returns only the first separator that it founds.

Then you can use the function "Mid" to get the "sub text" from the entry text. The Mid function take 3 parameters, the original text, the start position, and the length. Allways the start position that we want is 1. And the length? Easy, the length is the char index of the first separator (Using the InStr function). And you get the first word!!!

But... where is the loop? 

We have the method to get only the first word in the sentence... how can we make to get the second one? Easy, delete the first word from the setence and repeat the previous logic (Take the sub string using the Mid function...). There is no "delete" function, but exists "Replace" this function replace from one original text, one text for another.

In our example.... I get the first word "This" and I will replace "This " (adding an space at the end) from "This is the sentence". And I get returned "is the sentence."

My loop stop when I have no more text inside the original string (Or in other words, when the length of the text is equal to 0)

And this is all. Is clear all the logic?


Hope this helps you! And if this solves the problem, remember mark this as the best answer 😄

See you in the Community, bye 🙂

------------------------------
Pablo Sarabia
Solution Manager & Architect
Altamira Assets Management
Madrid
------------------------------

View answer in original post

2 REPLIES 2

PabloSarabia
Level 11
Hi @NayanaH_P

The easy way to achieve this is using the split function that you found in the "Utility - Strings" VBO.

But, if you are asking for the logic behind , let's think how can we build our own "Split" function in Blue Prism.

First you need is to implement a loop. When we talk about loops, they don't necessarily have to be loops made with the Loop Stage. A circular path is also a loop. 

We need a circular path, because we don't have any collection to iterate with the Loop stage. But, what need to put inside? Usually, when we talk about separate "things", we have a full list of this "things" (a full sentence with words), and this "things" are separated from each other by a separator.

Understanding this, you have a sentence with words, and this words are separate by an space. The first word start in the position 0 of the sentence until the first separator, the second one start in the first separator until the second separator....

19473.png
So far so clear.

To know the position of a character inside the text you need to use the function "InStr". Of course, our text have 3 separators, this functions returns only the first separator that it founds.

Then you can use the function "Mid" to get the "sub text" from the entry text. The Mid function take 3 parameters, the original text, the start position, and the length. Allways the start position that we want is 1. And the length? Easy, the length is the char index of the first separator (Using the InStr function). And you get the first word!!!

But... where is the loop? 

We have the method to get only the first word in the sentence... how can we make to get the second one? Easy, delete the first word from the setence and repeat the previous logic (Take the sub string using the Mid function...). There is no "delete" function, but exists "Replace" this function replace from one original text, one text for another.

In our example.... I get the first word "This" and I will replace "This " (adding an space at the end) from "This is the sentence". And I get returned "is the sentence."

My loop stop when I have no more text inside the original string (Or in other words, when the length of the text is equal to 0)

And this is all. Is clear all the logic?


Hope this helps you! And if this solves the problem, remember mark this as the best answer 😄

See you in the Community, bye 🙂

------------------------------
Pablo Sarabia
Solution Manager & Architect
Altamira Assets Management
Madrid
------------------------------

MichealCharron
Level 8
@NayanaH_P

You can achieve this with two actions in the Blue Prism "Utility - Strings" VBO:
19474.png
Taking the following sentence:
19475.png

We can perform the following steps on it:

  1. Use the "Regex Replace" action to remove all punctuation in the sentence with the regex pattern "[^\w\s\-']" which tells the action to ignore word characters, spaces, apostrophes and hyphens. Anything else will be replaced by an empty string.   
19476.png

  1. Use the "Split Text" action to take anything left over from the previous action and separate them, by space, into a collection:
19477.png


Then you end up with a collection like this:

19478.png


------------------------------
Micheal Charron
Senior Manager
RBC
America/Toronto
------------------------------
Micheal Charron
RBC
Toronto, Ontario
Canada