Regex for repeat words

split sentence by empty space, and find the ones with “-”

can you elaborate?

I’ll suggest 2 different ideas from Uzo’s.

Use OpenAI:

  1. Use OpenAI’s playground to determine the correct regex formula/code. It would require testing of course, you might need to experiment with various models (text, codex, …), but you might be able to guide GPT well enough that it’ll be able to do it.

  2. Use OpenAI’s playground to determine a prompt that could return the ouput you want based on a user input:

Dunia Anak-anak Masa Kini. //true
Dunia Ibu-Ibu Masa Kini. //false

… and then use the OpenAI integration, specifically the Complete Prompt feature, as a computed column within a table.

Idea 2 might be a poor idea. OpenAI’s GPT is not deterministic, so I don’t think we can trust a consistent true/false format of the output (I could be mistaken).

1 Like

Thank you @nathanaelb

I have tried OpenAI many times before, with no luck.
I need to rest my brain for a moment. :face_with_spiral_eyes:

Don’t use AI to write codes, LOL. It rarely comes up well.

Here is human-written code :wink:

split = p1.split(' ');
dash = split.filter(word => word.includes("-"));
splitDash = dash[0].split('-');
if(splitDash[0].toLowerCase()==splitDash[1] .toLowerCase()){
if(splitDash[1].toLowerCase()==splitDash[1]){
return 'TRUE'
}
}
return 'FALSE'

This is for one word with a dash… for more… loop the script or repeat the column with the next array index.

Thanks, Uzo, you’ve come close. Here I found the side effect, which returns true:

  1. Berbagai Alasan Penerbitan Undang - Undang secara Tidak Transparan. (“-” with spaces)
  2. Pritzker Prize Winning Architect, Alejandro Aravena - 2016. (“-” for non-repeating words)

It’s better if the ‘-’ sign with spaces is ignored (false or empty).

I made the script acording to your specifications, you did not metion, that it can be separated… Plus i do not get the concept of what you doing, so i couldn’t predict all outcomes

Yes, I know. Sometimes we also don’t know user behavior. Therefore it should be considered false because it is beyond the truth/validation requirement.

Now you have a base script to add more conditions, it should be easy for you… :wink:

1 Like

I will try to modify it. Very grateful.

1 Like

try this:

string = p1.replace(/\s*-\s*/g, "-");
split = string.split(' ');
dash = split.filter(word => word.includes("-"));
splitDash = dash[0].split('-');
if(splitDash[0].toLowerCase()==splitDash[1] .toLowerCase()){
if(splitDash[1].toLowerCase()==splitDash[1]){
return 'yes'
}
}
return 'no'

Nice to see you again, people who don’t give up. :stuck_out_tongue_winking_eye:
I got the script as follows, maybe you can give your opinion:

const split = p1.split(' ');
const dash = split.filter(word => word.includes("-") && word.indexOf("-") !== 0 && word.indexOf("-") !== word.length - 1);
const splitDash = dash[0].split('-');

if (splitDash.length == 2 && splitDash[0].toLowerCase() === splitDash[1].toLowerCase()) {
  if (splitDash[0].toLowerCase() === splitDash[1].toLowerCase() && splitDash[1] === splitDash[1].toLowerCase()) {
    return 'true';
  }
}

return 'false';

This is thanks to openAI, even though it is very annoying to explain what we mean and never give up on to answer, even though the answer is the same as before. :grin:

no, your script will not work if you have more than 1 space:

 a  -a           a - a     a- a
1 Like

Yes, I think your last script is useful too. Since you ignore spaces, this means I can allow the user to write with or without spaces.

A little more if it is able to detect a lot of repeated words then this script will be perfect.
Like the following example sentence: Dunia Anak-Anak, Bapak-bapak dan Ibu-ibu Masa Kini.

NB: There’s something I need to ask too, why doesn’t the javascript column seem to accept the new function anymore?

1 Like

I don’t know what you mean…

What would be the output for multiple matches?

Sorry, I wanted to fix the thread before your rushed answer. For example, writing in front using the function similarWord { …

there is no function like that

Never mind, forget it.

Hey @Uzo, give your opinion with the following script:

string = p1.replace(/\s*-\s*/g, "-");
split = string.split(' ');
dash = split.filter(word => word.includes("-"));
for (let i = 0; i < dash.length; i++) {
  splitDash = dash[i].split('-');
  if(splitDash[0].toLowerCase() === splitDash[1].toLowerCase()){
    if(splitDash[1].toLowerCase() === splitDash[1]){
      return 'true';
    }
  }
}
return 'false';

:wink:

res=0

string = p1.replace(/\s*-\s*/g, “-”);
split = string.split(’ ‘);
dash = split.filter(word => word.includes(“-”));
for (let i = 0; i < dash.length; i++) {
splitDash = dash[i].split(’-');
if(splitDash[0].toLowerCase() === splitDash[1].toLowerCase()){
if(splitDash[1].toLowerCase() === splitDash[1]){
res=res+1;
}
}
}
return res;