This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#26 2012-03-07 07:00:17

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: chocolate? Did you mean Bristol?

If anyone is interested, I was busy converting the Scratch script above to PHP today, when I realised that PHP actually has a function called levenshtein($str1, $str2) that compares the similarity of two strings for you! With the following function I was able to guess what a user meant by their search and even add sensitivity! ($words has to be an array, by the way, the array can store a list of allowed words.)

Code:

function wordMatch($words, $input, $sensitivity){
        $shortest = -1;
        foreach ($words as $word) {
            $lev = levenshtein($input, $word);
            if ($lev == 0) {
                $closest = $word;
                $shortest = 0;
                break;
            }
            if ($lev <= $shortest || $shortest < 0) {
                $closest  = $word;
                $shortest = $lev;
            }
        }
        if($shortest <= $sensitivity){
            return $closest;
        } else {
            return 0;
        }
    }

Last edited by sparks (2012-03-07 07:01:21)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#27 2012-03-07 08:29:12

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: chocolate? Did you mean Bristol?

And you sent me to Wikipedia again.  tongue

That's pretty cool: you're checking similarity based on number of edits needed to turn one string into another.

PS. $words looked like swords to me.  tongue  I think that'$ one reason I don't like PHP, having to add dollar $ign$ before each of the variable$. Don't you agree, $parks?


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#28 2012-03-07 08:50:30

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: chocolate? Did you mean Bristol?

tongue  I like it because it's clear what a variable is over a php constant. For example, someone might name a variable var and then wonder why it wouldn't set or echo, it is a constant. Of course, constants should be CAPITALISED to follow common practice, but PHP constants seem to work in lowercase too. I always add a $ before my javascript variables and then have to take it away again  tongue


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#29 2012-03-07 09:02:20

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: chocolate? Did you mean Bristol?

I use a smart (hey, it's from Apple) editor, Xcode, which highlights constants, so I have it easy.  big_smile


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#30 2012-03-07 09:07:20

technoboy10
Scratcher
Registered: 2007-08-25
Posts: 1000+

Re: chocolate? Did you mean Bristol?

Did you post the Scratch script? I'm working on a historical document search engine on Scratch and that would be helpful. Thanks!


So long, 1.4.
http://goo.gl/3JEV9

Offline

 

#31 2012-03-07 09:30:22

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: chocolate? Did you mean Bristol?

Yes, the Scratch script is linked in the first post. You can see the script image here: http://dl.dropbox.com/u/22935223/scriptWithCap.gif
(url to image of script)

Last edited by sparks (2012-03-07 09:31:11)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#32 2012-03-07 09:40:04

technoboy10
Scratcher
Registered: 2007-08-25
Posts: 1000+

Re: chocolate? Did you mean Bristol?

sparks wrote:

Yes, the Scratch script is linked in the first post. You can see the script image here: http://dl.dropbox.com/u/22935223/scriptWithCap.gif
(url to image of script)

Cool, thanks.


So long, 1.4.
http://goo.gl/3JEV9

Offline

 

#33 2012-03-07 09:48:16

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: chocolate? Did you mean Bristol?

No problem  smile

The new search system is now implemented on course my website


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#34 2012-03-07 09:52:23

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: chocolate? Did you mean Bristol?

Hardmath123 wrote:

I use a smart (hey, it's from Apple) editor, Xcode, which highlights constants, so I have it easy.  big_smile

Notepad++.  wink
I like the $s too. And Sparks, that happens to me with JS after I've been doing a bunch of PHP, but I forget them when I haven't done PHP in a few hours.  tongue

Offline

 

#35 2012-03-07 10:10:46

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: chocolate? Did you mean Bristol?

Yeah, I use notepad++ too, it highlights constants for me. However, my point still stands that it acts as a differentiator. I usually find I'm javascripting and PHPing at the same time  tongue


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#36 2012-03-07 10:16:01

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: chocolate? Did you mean Bristol?

Speaking of which, I see a lot of JS potential on your site. I see no spammy popups behind my window like I would on a real booking site!  tongue

Also, before we get Apple-bashing, I'd like to point out: Xcode can read, run, analyze with breakpoints, auto-complete, code-fold, smart syntax highlight (more languages than I thought existed, though I guess FORTRAN may have been overkill; JS nested in HTML is JS highlighted; imported file upvars and classes are highlighted) and partially debug my code. No, I wouldn't survive on a text editor, thank you very much.  big_smile

Last edited by Hardmath123 (2012-03-07 10:24:12)


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#37 2012-03-07 10:35:31

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: chocolate? Did you mean Bristol?

http://i.imgur.com/VVqJx.png

Yay!

I really do love the awesomeness of the site design, it's so pretty!

Last edited by rookwood101 (2012-03-07 10:38:00)


http://i.imgur.com/zeIZW.png

Offline

 

#38 2012-03-07 11:16:50

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: chocolate? Did you mean Bristol?

Glad you like, and I'm not apple bashing  tongue

I don't think I'll get many marks from my University lecturer if I spam his computer when he tries to mark the finished site  big_smile


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#39 2012-03-07 11:18:28

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: chocolate? Did you mean Bristol?

sparks wrote:

Glad you like, and I'm not apple bashing  tongue

I don't think I'll get many marks from my University lecturer if I spam his computer when he tries to mark the finished site  big_smile

Just kidding!

I meant Sci about the Apple bashing.


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#40 2012-03-07 14:31:36

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: chocolate? Did you mean Bristol?

Huh? I wasn't. Just saying what I use...
Site looking nice.  smile

Offline

 

#41 2012-03-07 17:50:12

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: chocolate? Did you mean Bristol?

You have lowecase suggested results--I think you want "Manchester", not "manchester".   wink

Offline

 

#42 2012-03-07 18:08:37

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: chocolate? Did you mean Bristol?

That is true. I hadn't bothered to PHP it since for simplicity's sake, names are stored all lowercase. I guess to caputalise the first letter I would have to

Code:

$result = strtoupper(substr($result, 0, 1)) . substr($result, 1, strlen($result) - 1);

That's off the top of my head. For all  I know there's a function for it  tongue

Does php cap lengths for substr? could I just do substr($result, 1, 100)? All this would mean me looking it up  tongue

Last edited by sparks (2012-03-07 18:10:44)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#43 2012-03-07 18:40:25

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: chocolate? Did you mean Bristol?

ucfirst($str);


http://i.imgur.com/zeIZW.png

Offline

 

#44 2012-03-07 19:15:26

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: chocolate? Did you mean Bristol?

well there we are then.

Woah, I'm 9 posts away from my 4000th post! I might have to do something extra-special for that.

Last edited by sparks (2012-03-07 19:16:41)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#45 2012-03-07 20:33:51

LiquidMetal
Scratcher
Registered: 2011-06-15
Posts: 500+

Re: chocolate? Did you mean Bristol?

sparks wrote:

Search correction method 3

This will now cut off unruly searches but set the cap too high and sensible searches will still not get through! For example, "Brizzle", a slang word for Bristol would still return Bristol without the cap, but at only 57% match it can easily be filtered out.

My suggestion is to go with method 3, and set it at 85% or higher.  But first, check for number or errors, not percentage.  If you check for 4 errors, Brizzle could become Bristol.  If you had, for example, Brozzle, then the code would go on to check the percentages.  Also, professional airlines probably would not cater to slang.  (right?)

Another thing you could do would be to check for simple keypress errors (simple to press, not to program  tongue ). For example, in place of a "B", check for V, G, H, N, and space, possibly including multiple errors. That might be too hard, especially since some keyboards have a different layout. 

Anyway, good luck!

Last edited by LiquidMetal (2012-03-07 20:35:05)

Offline

 

#46 2012-03-08 05:50:51

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: chocolate? Did you mean Bristol?

LiquidMetal wrote:

sparks wrote:

Search correction method 3

This will now cut off unruly searches but set the cap too high and sensible searches will still not get through! For example, "Brizzle", a slang word for Bristol would still return Bristol without the cap, but at only 57% match it can easily be filtered out.

My suggestion is to go with method 3, and set it at 85% or higher.  But first, check for number or errors, not percentage.  If you check for 4 errors, Brizzle could become Bristol.  If you had, for example, Brozzle, then the code would go on to check the percentages.  Also, professional airlines probably would not cater to slang.  (right?)

Another thing you could do would be to check for simple keypress errors (simple to press, not to program  tongue ). For example, in place of a "B", check for V, G, H, N, and space, possibly including multiple errors. That might be too hard, especially since some keyboards have a different layout. 

Anyway, good luck!

Thanks for the suggestions, but I've already implemented a system from above, as I posted  tongue  I like the idea of a program that can use close-key sensing to determine actual suggestions, but I think it would take a LOT of work and I still have to HTML the rest of the site and build the flight-booking system by mid-march.

I also added the ucfirst() function to the search suggestions, thanks for the idea! I have now replaced that with a similar function I found called ucwords() which will work better if the airline should ever decided to fly to a place with a two-word name.

Would people who have been following this thread be interested in testing out the booking feature when it is done to suggest improvements?

Last edited by sparks (2012-03-08 06:19:44)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#47 2012-03-08 07:41:41

PullJosh
Scratcher
Registered: 2011-08-01
Posts: 500+

Re: chocolate? Did you mean Bristol?

What if you did this?

#3's scripts
if that returns no results...
#1's scripts
if that returns no results...
if best one from #3 is > 50%
Then say "Did you mean (best one from #3)?"
otherwise...
Say "Did you mean (best from #1)?" // Use the one php thing you found to see what misspelling is closest

That would make it always show a result but always show the best one.

Last edited by PullJosh (2012-03-08 07:42:03)


http://www.blocks.scratchr.org/API.php?action=text&amp;string=I'm_on_vacation!&amp;xpos=155&amp;ypos=90&amp;font_size=30&amp;bgimage=http://imageshack.us/a/img339/7215/sspeechsigapiforwords.png

Offline

 

#48 2012-03-08 07:43:38

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: chocolate? Did you mean Bristol?

Hey Pulljosh, you're the third person to suggest something like that, and my answer is that it's good, but I've already implemented it now!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#49 2012-03-08 08:02:27

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: chocolate? Did you mean Bristol?

sparks wrote:

LiquidMetal wrote:

sparks wrote:

Search correction method 3

This will now cut off unruly searches but set the cap too high and sensible searches will still not get through! For example, "Brizzle", a slang word for Bristol would still return Bristol without the cap, but at only 57% match it can easily be filtered out.

My suggestion is to go with method 3, and set it at 85% or higher.  But first, check for number or errors, not percentage.  If you check for 4 errors, Brizzle could become Bristol.  If you had, for example, Brozzle, then the code would go on to check the percentages.  Also, professional airlines probably would not cater to slang.  (right?)

Another thing you could do would be to check for simple keypress errors (simple to press, not to program  tongue ). For example, in place of a "B", check for V, G, H, N, and space, possibly including multiple errors. That might be too hard, especially since some keyboards have a different layout. 

Anyway, good luck!

Thanks for the suggestions, but I've already implemented a system from above, as I posted  tongue  I like the idea of a program that can use close-key sensing to determine actual suggestions, but I think it would take a LOT of work and I still have to HTML the rest of the site and build the flight-booking system by mid-march.

I also added the ucfirst() function to the search suggestions, thanks for the idea! I have now replaced that with a similar function I found called ucwords() which will work better if the airline should ever decided to fly to a place with a two-word name.

Would people who have been following this thread be interested in testing out the booking feature when it is done to suggest improvements?

Yeah, sure!


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#50 2012-03-08 10:42:05

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: chocolate? Did you mean Bristol?

Hardmath123 wrote:

sparks wrote:

LiquidMetal wrote:


My suggestion is to go with method 3, and set it at 85% or higher.  But first, check for number or errors, not percentage.  If you check for 4 errors, Brizzle could become Bristol.  If you had, for example, Brozzle, then the code would go on to check the percentages.  Also, professional airlines probably would not cater to slang.  (right?)

Another thing you could do would be to check for simple keypress errors (simple to press, not to program  tongue ). For example, in place of a "B", check for V, G, H, N, and space, possibly including multiple errors. That might be too hard, especially since some keyboards have a different layout. 

Anyway, good luck!

Thanks for the suggestions, but I've already implemented a system from above, as I posted  tongue  I like the idea of a program that can use close-key sensing to determine actual suggestions, but I think it would take a LOT of work and I still have to HTML the rest of the site and build the flight-booking system by mid-march.

I also added the ucfirst() function to the search suggestions, thanks for the idea! I have now replaced that with a similar function I found called ucwords() which will work better if the airline should ever decided to fly to a place with a two-word name.

Would people who have been following this thread be interested in testing out the booking feature when it is done to suggest improvements?

Yeah, sure!

I also  smile


http://i.imgur.com/zeIZW.png

Offline

 

Board footer