Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Tocaro · Feb 28, 2014 at 04:48 AM · stringcharwords

Comparing words in dictionaries

So I've got a text file with most of the English words in it, and I'm putting it into a dictionary (Called 'words') as so:

 words = textFile.text.Split('\n').Select(s=>s.Trim()).Distinct().ToDictionary(s=>s,s=>true);

What I'm trying to do is take a Chosen Word and look in the dictionary for a word LIKE the Chosen Word. I capitalize 'LIKE' because I'm not looking to check if the Chosen Word is within the text file, what I want to do is find a word that is similar.

For example, if the Chosen Word was 'Cake' then the Dictionary might return 'Case'. Basically it should check that the first few letters are similar, and perhaps that it shares some other common letters, BUT it should not be the exact same word.

I should admit, I'm not that knowledgeable about dictionaries, so hopefully this isn't a dumb question and feel free to point me towards any relevant resources.

So, in conclusion, I want to figure out how to give the dictionary a random word and for it to return a similar (BUT not identical) word.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by whydoidoit · Feb 28, 2014 at 05:57 AM

Ok for that you are not going to want to use a dictionary exactly the way you are. Unfortunately what you are looking for is not going to be doable in anything apart from O(N) time I fear. Not unless you have restrictions like "the first letter" must be the same for instance or the words must sound alike.

So you could do a "sounds like" by using Soundex which might be what you are after.

Let's say you do that and write a Soundex(someString) function - what you would then do is:

  1. Create a Dictionary of Lists of words with the same soundex value

  2. When looking up, calculate the Soundex of the word you are searching for - then iterate that list from the dictionary ignoring the word itself and choose a random value.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Tocaro · Feb 28, 2014 at 06:08 AM 0
Share

Wow, never heard of Soundex before but that's a brilliant solution, thanks. Still trying to wrap my head around it, but it sounds like it'll work.

avatar image whydoidoit · Feb 28, 2014 at 06:10 AM 0
Share

Yeah it's used for fixing people typing names wrong in data deduplication.

You would end up with something like this as a Linq function:

   Dictionary<string, List<string>> lookup = someStringArray.GroupBy(s=>Soundex(s)).ToDictionary(s=>s.$$anonymous$$ey, s=>s.ToList());
avatar image whydoidoit · Feb 28, 2014 at 06:15 AM 0
Share

And here's an implementation of Soundex in C#: http://seesharpdeveloper.blogspot.sg/2013/07/soundex-algorithm-in-c.html

avatar image Tocaro · Feb 28, 2014 at 06:19 AM 0
Share

If I was to limit it by saying the first two letters of the word must be the same as the word replacing it, how would I start off on that?

avatar image whydoidoit · Feb 28, 2014 at 06:22 AM 0
Share

Just make your soundex function use the first character and then soundex the substring of everything but the first character.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to implement Text Mesh text wrapping? 2 Answers

Android 4.2 strings bugs. 1 Answer

Finding a character unicode in C# 0 Answers

Error CS0029 fix 1 Answer

Replace chars in String with a Dictionary and avoid order-sensitive problems 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges