Levenshtein Threaded/Multiprocess !

This is the place for queries that don't fit in any of the other categories.

Levenshtein Threaded/Multiprocess !

Postby Chameleon00 » Sat Jun 15, 2013 12:16 pm

I have written this code that finds out the Levenshtein Distance between two words.

Code: Select all
import random


def ld(w1, w2):
    if not w1:
        return len(w2)
    if not w2:
        return len(w1)
    if w1[0] == w2[0]:
        return ld(w1[1:], w2[1:])
    l1 = ld(w1, w2[1:])
    l2 = ld(w1[1:], w2)
    l3 = ld(w1[1:], w2[1:])
    return 1 + min(l1, l2, l3)

a = ["truesilver", "miner", "rocks", "gold", "silver", "bronze"]
b = ["Troll", "Orc", "undead", "human", "gnome", "elf"]

print (random.choice(a))
print (random.choice(b))
print(ld(random.choice(a), random.choice(b)))



I want to try it with a threaded and a multiprocess approach too though,but can't figure out where to start exactly !
Last edited by Yoriz on Sat Jun 15, 2013 12:56 pm, edited 1 time in total.
Reason: Added code tags and re-indented the code
Chameleon00
 
Posts: 3
Joined: Sat Jun 15, 2013 12:13 pm

Re: Levenshtein Threaded/Multiprocess !

Postby Yoriz » Sat Jun 15, 2013 1:06 pm

Don't know why you would want to thread/multiprocess that code but take a look at the following.
https://pypi.python.org/pypi/futures/2.1.3 python2.7
http://docs.python.org/3/library/concurrent.futures.html python3
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 871
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: Levenshtein Threaded/Multiprocess !

Postby Chameleon00 » Sat Jun 15, 2013 1:14 pm

I want to thread it/multiprocess it so that I prove that the normal approach is faster than the threaded and slower than the multiprocess one !
Chameleon00
 
Posts: 3
Joined: Sat Jun 15, 2013 12:13 pm

Re: Levenshtein Threaded/Multiprocess !

Postby Yoriz » Sat Jun 15, 2013 1:18 pm

If you want fast use a Python C extension version
https://pypi.python.org/pypi/python-Levenshtein/
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 871
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: Levenshtein Threaded/Multiprocess !

Postby Chameleon00 » Sat Jun 15, 2013 1:19 pm

thanks a lot for the help ! Will check them out immediately
Chameleon00
 
Posts: 3
Joined: Sat Jun 15, 2013 12:13 pm

Re: Levenshtein Threaded/Multiprocess !

Postby micseydel » Sat Jun 15, 2013 1:58 pm

Multiprocessing this probably won't make it faster. I don't believe it does enough for the overhead to be worth it. I could be wrong, and I'm no expert, but there are probably better things to parallelize.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1390
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to General Coding Help

Who is online

Users browsing this forum: conor100, Crimson King, Google [Bot], Larz60+, W3C [Linkcheck] and 1 guest