Jump to content
UBot Underground

How To Compare Sentence..


Recommended Posts

I want to use if command to compare whether scraped sentence is same to proposed sentence..

If two is same. I want to do something..

What command can I use?

I have all of apichai plugin and the others..

Link to post
Share on other sites

There are a lot of ways to do this so I will write out a few that come to mind. The first of course is to literally just use a comparison function on its own like so:

set(#sentence,"Don\'t start from scratch ! Here are several useful pre-made automation solutions for you.","Global")
set(#scrapedSentence,"Don\'t start from scratch ! Here are several useful pre-made automation solutions for you.","Global")
if($comparison(#scrapedSentence,"= Equals",#sentence)) {
    then {
        alert("The same")
    }
    else {
        alert("Different")
    }
}

Another way to do this to the same effect - and the way you would compare say two images or two files is to create an MD5 hash of it and then compare the hashes - this code uses a function from the bot bank but there are free plugins I think which also do the same thing:

set(#sentence,"Don\'t start from scratch ! Here are several useful pre-made automation solutions for you.","Global")
set(#sentenceMD5,$encrypt(#sentence,"md5"),"Global")
set(#scrapedSentence,"Don\'t start from scratch ! Here are several useful pre-made automation solutions for you.","Global")
set(#scrapedSentenceMD5,$encrypt(#scrapedSentence,"md5"),"Global")
if($comparison(#sentenceMD5,"= Equals",#scrapedSentenceMD5)) {
    then {
        alert("The same")
    }
    else {
        alert("Different")
    }
}

You can of course use MD5 as well with this next part if you want..

 

And this is how I would do it unless you care about capitalization. I would trim the ends for white space and then convert all characters to lowercase and then compare it like so:

set(#sentence,"Don\'t start from scratch ! Here are several useful pre-made automation solutions for you.","Global")
set(#scrapedSentence,$trim("Don\'t start from scratch ! Here are several useful pre-made automation solutions for you."),"Global")
if($comparison($change text casing(#sentence,"Lower Case"),"= Equals",$change text casing(#scrapedSentence,"Lower Case"))) {
    then {
        alert("The same")
    }
    else {
        alert("Different")
    }
}
  • Like 1
Link to post
Share on other sites

If you don't care about spaces you can also replace spaces with nothing and compare the text after changing it to low case as stated by HelloInsomnia - this way you will compare two sentences in format of "Hello,howareyou?Whatisyourname?" and it will be same even if you scrape some additional spaces in the middle.

  • Like 1
Link to post
Share on other sites

Here's iamddr's suggestion in Ubot form, this will spit out a percentage of the likeness of the sentences, which I varied slightly so it would be 100 (percent)

set(#sentence,"Don\'t start from scratch ! Here are several useful pre-made automation solutions for you!","Global")
set(#scrapedSentence,$trim("Don\'t start from scratch ! Here are several useful pre-made automation solutions for you."),"Global")
set(#sentenceLikeness,$run python with result("import difflib
seq = difflib.SequenceMatcher(None, \"{#sentence}\", \"{#scrapedSentence}\")
ratio = seq.ratio()
ratio * 100"),"Global")
  • Like 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...