Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / String Similarity

Author
Message
hank
13
Years of Service
User Offline
Joined: 10th Feb 2013
Location: Kentucky, USA
Posted: 7th Apr 2014 15:59
Wondering if anyone could help me with comparing two strings in dbpro. I am trying to take two strings and return how similar they are in a percentage.
ex.
My name is John
John is my name

this would be 100% similar because they both have an equal amount of the same words. They don't have to be similar in meaning. Seems pretty simple but I just can't get my head around how to code this. I have tried using cosine similarity but have failed to get the math correct.
hank
13
Years of Service
User Offline
Joined: 10th Feb 2013
Location: Kentucky, USA
Posted: 7th Apr 2014 16:50
After posting I worked a bit on figuring this out. I actually think I got it but not sure if it works the best as it should. Sorry it's a little messy.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Apr 2014 17:27
I suggest you replace every float that is a count with an integer - then convert to floats when you need float arithmetic. Otherwise you might get misleading results in things like for/next loops (because a stored float might not be exactly equal to the intended integer).

Also, you only need to do comparisons once. For example, replace these two comparisons:



with this single comparison:





Powered by Free Banners
hank
13
Years of Service
User Offline
Joined: 10th Feb 2013
Location: Kentucky, USA
Posted: 7th Apr 2014 17:43
Thanks GG, glad to get this sorted out. Was actually more simple than I was thinking this would be. I will probably merge this with my cosine similarity code so that I can search for misspellings.
hank
13
Years of Service
User Offline
Joined: 10th Feb 2013
Location: Kentucky, USA
Posted: 8th Apr 2014 00:05
Still doesn't seem to be working correctly. I am getting 100% with the two strings - What is a dog. What is a cat.
What I am trying to achieve is checking to see if my inputted string will fit in another string.
What is google?
What is google.com? - these should return 100% because I can put the first string in the second string.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 9th Apr 2014 23:15
Here's my attempt at your request (from your first post):



All it does at the moment is to generate a list & count of the words that appear in each of a$ and b$ - you can use that to calculate the similarity in whatever way you choose. If you also want to use other symbols as word separators (eg comma or full-stop), then just add those to the SPLIT STRING commands in both places.

hank
13
Years of Service
User Offline
Joined: 10th Feb 2013
Location: Kentucky, USA
Posted: 11th Apr 2014 16:29
Thanks IanM, this works perfect. I now just gotta figure out some of these commands that I have never used before.
hank
13
Years of Service
User Offline
Joined: 10th Feb 2013
Location: Kentucky, USA
Posted: 20th May 2014 19:03 Edited at: 20th May 2014 19:04
I know this post is a little old. I just now got around to working on this again. Attached is a little plugin I made with three commands.


hank
13
Years of Service
User Offline
Joined: 10th Feb 2013
Location: Kentucky, USA
Posted: 21st May 2014 04:11 Edited at: 21st May 2014 04:12
I figured I would take the time to learn how to make string tables for my plugins. The attached file has the plugin and keyword file. Pretty much the same plugin but without having to go through the trouble of calling the dll manually.

Login to post a reply

Server time is: 2026-07-06 04:28:22
Your offset time is: 2026-07-06 04:28:22