namstery 3 Posted January 2, 2018 Report Share Posted January 2, 2018 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.. Quote Link to post Share on other sites
HelloInsomnia 1103 Posted January 2, 2018 Report Share Posted January 2, 2018 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") } } 1 Quote Link to post Share on other sites
bestmacros 60 Posted January 2, 2018 Report Share Posted January 2, 2018 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. 1 Quote Link to post Share on other sites
iamddr 12 Posted January 3, 2018 Report Share Posted January 3, 2018 seq = difflib.SequenceMatcher(lambda x:x=" ", a, ratio = seq.ratio()use python standard library - difflib 1 Quote Link to post Share on other sites
HelloInsomnia 1103 Posted January 3, 2018 Report Share Posted January 3, 2018 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") 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.