Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Rhyme generator

by Brovnik (Hermit)
on May 31, 2001 at 03:29 UTC ( [id://84410]=note: print w/replies, xml ) Need Help??


in reply to Rhyme generator

I just had some fun playing with this.

A couple of comments :

  1. The code to read in the dictionary is a bit inefficient. The folloing in Dictionary.pm speeds things up by removing surplus split/join code :
    our %dict; our %reversedict; sub read_dict { while (<DATA>) { chomp; if (/^([^\s]+)\s\s(.*)$/) { my ($key,$value) = ($1,$2); $dict{$key} = $value; $reversedict{$value} = $key; } } return; }
    This speeds up the initial read from 10+ seconds to 6.5 seconds on my machine.
  2. I also played with using Storable to speed up subsequent accesses.
    my $dict = "/tmp/Lingua::EN::Rhyme::Dictionary::DICT"; my $reversedict = "/tmp/Lingua::EN::Rhyme::Dictionary::REVDICT"; my $loaded = retrieve_dict(); sub store_dict { read_dict(); store(\%dict,$dict); store(\%reversedict,$reversedict); } sub retrieve_dict { my $ref = retrieve("DICT"); if ($ref) { %dict = %$ref; $ref = retrieve("REVDICT"); %reversedict = %$ref; } else { # Read in normal way and store read_dict(); store_dict(); } return 1; }
    This uses Storable to store and retrieve the dictionaries. It saves some time, but not a lot and leves the extra files around.

    I also started playing with storing this in a mysql DB, but haven't got that clean yet (it really needs a rewrite of all of Rhyme.pl.

  3. Hope that is of help.
    --
    Brovnik

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://84410]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-12-09 09:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which IDE have you been most impressed by?













    Results (53 votes). Check out past polls.