Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Monastery::Monkify

by Chmrr (Vicar)
on Apr 21, 2001 at 11:18 UTC ( [id://74400]=CUFP: print w/replies, xml ) Need Help??

Following talk in the CB today, I started poking through the latest XML ticker, which shows the list of all monks at the monastery. I was struck by how many of the usernames were similar to real words. Combining that with my wish to play with Text::Soundex gave me..

The wonderful toy of Monastery::Monkify. It changes every word into a link to the home node of a monk with a similar name. Unfortunatly, Text::Soundex isn't picky enough to get really good matches, but it's still fun. Anyways, the code:

use strict; use Text::Soundex; use LWP::Simple; use HTML::Entities; $Text::Soundex::nocode = 'Z000'; $| = 1; print "Loading.."; my @nodes = map {($_)=/"([^"]+)"/;defined($_)?[$_,soundex($_)=~/(.)(.{ +3})/]:['','Z',0]} split /\n/, get 'http://perlmonks.org/?node_id=74291'; print "Done.\n"; s/(\w+)/bestfit($1)/ge, print while <>; sub bestfit { my($word) = @_; my @se = soundex($word)=~ /(.)(.{3})/; return "[nodereaper|$word]" if join('',@se) eq 'Z000'; my @found = sort {abs($se[1]-$a->[2]) <=> $se[1]-$b->[2]} grep {$se[ +0] eq $_->[1]} @nodes; return "[".decode_entities $found[rand(grep {$found[0][2] == $_->[2] +} @found)]->[0]."|$word]"; }

Note: I'm doing a somewhat evil thing here, by processing XML using regexes. I'm forced to do this, however, because the "XML" node in question isn't actually XML -- it has non-XML entities. Ah, well..

 
perl -e 'print "I love $^X$\"$]!$/"#$&V"+@( NO CARRIER'

Replies are listed 'Best First'.
Re: Monastery::Monkify
by Albannach (Monsignor) on Apr 21, 2001 at 21:07 UTC
    I like it, but I sure hope it doesn't get used much or serving nodes will really slow down! You might want to try Text::Metaphone in place of Text::Soundex and see how much different it is (perhaps not much different as there aren't that many monk names).

    --
    I'd like to be able to assign to an luser

(ar0n) Re: Monastery::Monkify
by ar0n (Priest) on Apr 21, 2001 at 21:25 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2024-03-28 21:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found