dansk
|
  |
| Joined: 24 Dec 2008 |
| Total Posts: 548 |
|
|
| 06 May 2015 12:00 PM |
| Alright so first of all believe it or not I have a script in my workspace that globalized an array encoded with the entire english language. What I'm trying to make is an autocorrect script. First of all, I realize just looping through this normal using a for loop would take way too many iterations. My first step is to find a word in the array using a binary search algorithm. I can write it in java using integers but strings I'm not so comfortable with. Anybody know how I would accomplish this? |
|
|
| Report Abuse |
|
|
dansk
|
  |
| Joined: 24 Dec 2008 |
| Total Posts: 548 |
|
| |
|
Intern33t
|
  |
| Joined: 19 Nov 2010 |
| Total Posts: 1530 |
|
|
| 06 May 2015 12:17 PM |
according to lua-usersputadothereorg/wiki/BinarySearch there is "table.binsearch"
|
|
|
| Report Abuse |
|
|
dansk
|
  |
| Joined: 24 Dec 2008 |
| Total Posts: 548 |
|
| |
|
|
| 06 May 2015 01:05 PM |
| http://lua-users.org/wiki/BinarySearch |
|
|
| Report Abuse |
|
|
dansk
|
  |
| Joined: 24 Dec 2008 |
| Total Posts: 548 |
|
|
| 06 May 2015 01:25 PM |
| So I checked the link but wouldn't that work with Integers? How would I use it to compare strings alphabetically? |
|
|
| Report Abuse |
|
|
|
| 06 May 2015 02:30 PM |
You could've organised everything alphabetically:
Dictionary = { A={"All letters beginning with A"}, B = {"You get the idea"} }
Then, for _,a in pairs(Dictionary[string:sub(1,1):Upper()]) do -- Do stuff end
---------------
Dictionary[string:sub(1,1):Upper()]
"Dictionary" is the "main" table. "string" is the word :sub(1,1) gets the first letter. :Upper() turns it upper-case.
So, it's the same as this (str == string):
str = "Hello" Dictionary["H":Upper()] |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 06 May 2015 02:48 PM |
table.concat(yourArray, '||'):find("wordyou'relookingfor")
If you're looking for something that finds the correction based on a search, I'd suggest you either start making a dictionary of common mispellings and searching each typed word as a key, or use a fuzzy match for the words in your array. It could help if you did organise them into letters, though
Thing = { A = { A = { "Aa lava" } }; B = { A = { N = { A = { -- Yeah you get the idea dude } } } } }
That can totally help you by cutting out large amounts of things. |
|
|
| Report Abuse |
|
|
dansk
|
  |
| Joined: 24 Dec 2008 |
| Total Posts: 548 |
|
|
| 06 May 2015 02:57 PM |
| Thanks guys. (Btw the dictionary is already organized alphabetically) |
|
|
| Report Abuse |
|
|
darkwisp
|
  |
| Joined: 07 Apr 2010 |
| Total Posts: 22653 |
|
|
| 06 May 2015 03:34 PM |
| I think what the mean by alphabetically is separating each set of words into tables of alphabets. |
|
|
| Report Abuse |
|
|
dansk
|
  |
| Joined: 24 Dec 2008 |
| Total Posts: 548 |
|
|
| 06 May 2015 03:45 PM |
| Well Instead of that I just took the indexs of where each letter starts and ends so I can jump to them quicker |
|
|
| Report Abuse |
|
|