what is the equivalent of operator LIKE in CSPro ?

Discussions about editing and cleaning data
mosbi
Posts: 6
Joined: April 8th, 2021, 4:13 am

what is the equivalent of operator LIKE in CSPro ?

Post by mosbi » October 18th, 2021, 4:27 pm

Hello guys,
I want to create a loop which goes through the cases whose variable X for example contains a text like "texteArechercher".
What operator is used to find all of the words that resemble the words to search for ?

thanks advance

htuser
Posts: 527
Joined: December 19th, 2011, 6:26 pm
Location: HAITI

Re: what is the equivalent of operator LIKE in CSPro ?

Post by htuser » October 19th, 2021, 10:04 am

Dear Mosbi,
The nearest functions equivalent to LIKE are
1) https://www.csprousers.org/help/CSPro/pos_function.html
2) https://www.csprousers.org/help/CSPro/s ... ction.html
Hope this help you!

sherrell
Posts: 98
Joined: April 2nd, 2014, 9:16 pm
Location: Washington, DC

Re: what is the equivalent of operator LIKE in CSPro ?

Post by sherrell » October 19th, 2021, 9:02 pm

Hi Mosbi,

>What operator is used to find all of the words that resemble the words to search for ?

I'm not sure what you mean by 'resemble'. Must the similar word be identical except for an extra or missing letter? Or does the similar word just have to contain all or nearly the same letters? If the latter, you could count the # of letters that appear in each string, and see how the counts compare.

Otherwise, in addition to the two functions HTUser mentioned, the poschar function might be of value.

https://www.csprousers.org/help/CSPro/p ... ction.html

Sherrell

mosbi
Posts: 6
Joined: April 8th, 2021, 4:13 am

Re: what is the equivalent of operator LIKE in CSPro ?

Post by mosbi » October 20th, 2021, 4:31 pm

Hello,
Basically I mean, an operator that can search for a string in a column of a table, ignoring upper and lower case letters.
for example:
search word: "Ouedraogo Boureima"
example answer found:
- ouedraogo boureima
- stuffed ouédrago
- ouedraogo Boureima28
- ouedraogoboureima
- etc .....
You see ?
In a web programming language for example, the "LIKE" operator allows you to do this.
But I am wondering with CSPro, what trick can I use to have the same result?

Thank you.

sherrell
Posts: 98
Joined: April 2nd, 2014, 9:16 pm
Location: Washington, DC

Re: what is the equivalent of operator LIKE in CSPro ?

Post by sherrell » October 21st, 2021, 8:57 am

Hi Mosbi,

Sorry, we don't provide functions that delve into string processing to this level. You'd have to find an algorithm and code it in CSPro. Here are two posts that use the Levenshtein Distance algorithm to do this.

https://stackoverflow.com/questions/104 ... -of-likely
https://people.cs.pitt.edu/~kirk/cs1501 ... stance.htm

CSPro does have a regex matching function, but this would require regex skills:
https://www.csprousers.org/help/CSPro/r ... ction.html

Finally, Greg gave me the following code block that he & Josh used a few years back:
// based on https://en.wikipedia.org/wiki/Damerau%E ... n_distance

array d(51, 51);

function dlDistance(string a, string b)

   
numeric i, j, cost, trans;

   
do i = 0 while i <= length(a)
        d(i,
0) = i;
   
enddo;

   
do j = 0 while j <= length(b)
        d(
0 , j) = j;
   
enddo;

   
do i = 1 while i <= length(a)
       
do j = 1 while j <= length(b)
           
if a[i:1] = b[j:1] then
               
cost = 0;
           
else
               
cost = 1;
           
endif;
           
if i > 1 and j > 1 and a[i-1:1] = b[j-2:1] and a[i-2:1] = b[j-1:1] then
               
trans = d(i - 2, j - 2) + cost;
           
else
               
trans = length(a) + length(b);
           
endif;
            d(i, j) =
low(  d(i - 1, j) + 1,
                            d(i,j-
1) + 1,
                            d(i-
1, j-1) + cost,
                            trans);

       
enddo;
   
enddo;

    dlDistance = d(
length(a), length(b));

end;
Sherrell
Last edited by sherrell on October 21st, 2021, 12:11 pm, edited 1 time in total.

htuser
Posts: 527
Joined: December 19th, 2011, 6:26 pm
Location: HAITI

Re: what is the equivalent of operator LIKE in CSPro ?

Post by htuser » October 21st, 2021, 10:04 am

Hi Mosbi,
In addition to responses provided by Sherrell,
1) Please take a look in the CSPro folder in your My Documents: Documents\CSPro\Examples 7.6\1 - Data Entry\Selecting Cases
Selecting Cases seem exactly what you're looking for, mainly, option 5.

2) Autocompletion can also help you. Here's a discussion with Greg, years ago:https://www.csprousers.org/forum/viewto ... lete#p2197 . Greg used the same logic from the Selecting Cases. But, there's a more convenient way to do it using Javascript and future htmlDialog function.

3) Also, it seem that your demand is more concerned by full-text search. In the next version, CSPro will have a Javascrit-CSPro interface. That's mean, you'll be able to run CSPro Logic function inside Javascript and also, return result from Javascript to CSPro.
Please for Javascript full-text search, take a look here:
https://burakkanber.com/blog/machine-le ... e-scoring/
https://stackoverflow.com/questions/113 ... -and-html5
https://github.com/nextapps-de/flexsearch

With the next Javascrit-CSPro interface, it's virtually impossible to have a CSProuser request who can't be fulfilled since JavaScript is the language having the greatest know open libraries.
@ Sherrell, as it's always more convenient to have example and demo in CSPro logic, please can you provide us a small demo app with codes you posted?

Hope this help you

sherrell
Posts: 98
Joined: April 2nd, 2014, 9:16 pm
Location: Washington, DC

Re: what is the equivalent of operator LIKE in CSPro ?

Post by sherrell » October 21st, 2021, 12:56 pm

> Sherrell, as it's always more convenient to have example and demo in CSPro logic, please can you provide us a small demo app with codes you posted?

I'm just the messenger. Greg is off this week, but saw our convo on this and sent me the code snippet. Since it was part of a larger app, he would have to (no doubt) make a lot of edits to isolate just the portion that was relevant to Mosbi's request.

Sherrell

htuser
Posts: 527
Joined: December 19th, 2011, 6:26 pm
Location: HAITI

Re: what is the equivalent of operator LIKE in CSPro ?

Post by htuser » October 21st, 2021, 3:11 pm

Thanks Sherrell.
I'll discuss with Greg once he come back to office.
Best,

mosbi
Posts: 6
Joined: April 8th, 2021, 4:13 am

Re: what is the equivalent of operator LIKE in CSPro ?

Post by mosbi » October 22nd, 2021, 1:35 pm

Hello,
Really happy for the quick reaction from you, it's motivating.
Now I will try the Documents \ CSPro \ Examples 7.6 \ 1 - Data Entry \ Selecting Cases application, while waiting for the arrival of Javascript which will really revolutionize CSPro!
I do the tests and I will come back to you !!!

Thank you.

mosbi
Posts: 6
Joined: April 8th, 2021, 4:13 am

Re: what is the equivalent of operator LIKE in CSPro ?

Post by mosbi » November 9th, 2021, 7:26 am

Hello,
Like I said, I tried the "pos" function but it doesn't seem to work well with the "forcase" function.
In my current situation, I need to loop through data in a table. and in this case I use a "forcase"
in the "forcase", when I add the function "pos" as a criterion, my request does not return a result, whereas there is indeed a line of data which corresponds to the name that I have put in the function " pos ".
Is there really an incompatibility between "forcase" and "pos"?
if no compatibility problem, how can i convert my query to what works?

below my request:
forcase BASE_BENEF_REF_DICT where COM_REF = F66_DRAFT And VILLAGE_REF = F67_DRAFT And strip (SEXE) = "Feminin" And pos (strip (F69_DRAFT), toupper (NOM_PRENOMS_INDIVIDUS)) = 1 do
F69_DRAFT: is a name and firstname entered by the agent
NOM_PRENOMS_INDIVIDUS: is the name and firstname present in the database

Thank you.

Post Reply