473,326 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

spell checking

I was just curious if there were any spell checker python modules around
that can guess at what the user meant to type in. I wrote up a quick
function that splices a string up into bigrams and then checks how many
bigrams are identical to a given word, which I think is how google does
it. But support for trigrams etc. could be added, so I'm curious if
anyone out there has done something more. Here's the script:

def StringsSimilarity(str1, str2):
"""Divides the two strings into bigrams and reports
what percentage of them are equal"""
str1 = str1.strip().lower()
str2 = str2.strip().lower()
bigramStr1 = []
bigramStr2 = []
currentList = bigramStr1
i = 0
j = 0

# Empty versus non empty strings are never similar
if not (str1 and str2):
return 0

# 100% match if equal
if str1 == str2:
return 1.0

# Make strings equal length, simplifies things
len1 = len(str1)
len2 = len(str2)

if len1 > len2:
str2 = str2 + " "*(len1-len2)
elif len2 > len1:
str1 = str1 + " "*(len2-len1)

len1 = len(str1)
len2 = len(str2)

currentString = str1

# Generate bigrams
while j < 2:
i = 0
while i < len1:
if i+1 >= len1:
currentList.append(currentString[i])
else:
currentList.append(currentString[i] + currentString[i+1])

i += 2

j += 1
currentList = bigramStr2
currentString = str2

similarity = 0

for i in range(len(bigramStr1)):
if bigramStr1[i] == bigramStr2[i]:
similarity += 1.0

if similarity == 0:
return 0

return similarity/len(bigramStr1)

def StringsSimilar(str1, str2):
"""Using StringSimilarity, decides if the two
strings score is good enough, 50%, to be
considered similar"""
return StringsSimilarity(str1, str2) >= 0.50

Jul 18 '05 #1
0 927

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Leo P. | last post by:
I am trying to write a spelling checker. Specifically the part that suggests words. From what I've read online, it seems like the preferred way to do this, is to find the double metaphone...
1
by: Pater Maximus | last post by:
I want to use the MS Word spell checker from my Python program. I check the spelling a word at a time. It works fine for English but I can not force it to use French when I am using that language....
84
by: Andy Glew | last post by:
I am in search of any rigourous, scientific, academic or industrial studies comparing naming conventions in C++ or similar languages such as Ada: Specifically, are names formed with...
0
by: kk | last post by:
..NET Winforms Control for Spell and grammar check with formatting capabilitie ------------------------------------------------------------------------------------------- Need a control which has...
1
by: Lloyd Dupont | last post by:
I see that outlook express has some spell checking capacity. so I though maybe there is a spell checking feature available in windows. the only thing I found out requires word2003, which is to big...
12
by: Ryan | last post by:
Is there anyway to enable spell-checking for user input in a Text Box? Either auto spell-check or create a spell-check button. Using VB 2005.
6
by: Neil | last post by:
Is there way to have control over the MS-Access spell checking (besides just launching it)? We want to tell it to check all records, but skip certain fields (or, alternatively, ONLY check certain...
5
by: Dean Slindee | last post by:
Anybody got any helpful suggestions on how to implement spell checking in a textbox. Perhaps solutions using Microsoft Word spell checker as a called routine? What has worked for you? Thanks,...
22
by: SmokeWilliams | last post by:
Hi, I am working on a Spell checker for my richtext editor. I cannot use any open source, and must develop everything myself. I need a RegExp pattern to split text into a word array. I have...
4
by: BillE | last post by:
I have found articles on line about using word interop for spell checking with visual studio applications. Most of the articles are several years old, though - VS2003, maybe 2005. I couldn't...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.