#!/usr/bin/perl use constant IDEAS => '/var/www/html/main/sandbox/great-books/etc/ideas.txt'; use strict; use Lingua::Wordnet; my $wn = Lingua::Wordnet->new; my @ideas = &slurp_words( IDEAS ); foreach my $idea ( @ideas ) { my @synsets = $wn->lookup_synset( $idea, 'n' ); my %synonyms = (); foreach my $synset ( @synsets ) { foreach my $synonym ( sort $synset->synonyms ) { $synonym =~ s/%\d+//; $synonym =~ s/_/ /g; $synonym = lc( $synonym ); $synonyms{ $synonym } = 1; } } print "$idea\n"; foreach ( sort keys %synonyms ) { print "\t$_\n" } print "\n"; } # done exit; sub slurp_words { my $file = shift; my @words = (); open ( S, " < $file" ) or die "Can't open $file ($!)\n"; while ( ) { chop; next if ( ! $_ ); # blank line next if ( /^#/ ); # comments push @words, $_; } close S; return @words; }