#!/usr/bin/perl use constant DB => './irclog.db'; use constant RADIUS => 40; use strict; use Lingua::Concordance; use Text::BarGraph; # sanity check my $query = $ARGV[ 0 ]; if ( ! $query ) { print "Usage: $0 \n"; exit; } # initialize my $corpus = ''; # create corpus open INPUT, ' < ' . DB or die "Can't open " . DB . ": $!\n"; while ( ) { # clean, parse, and build corpus chop; my ( $datestamp, $name, $text ) = split /\t/, $_; $corpus .= $text . ' '; } close INPUT; # initialize concordance my $concordance = Lingua::Concordance->new; $concordance->text( $corpus ); $concordance->query( $query ); $concordance->radius( RADIUS ); # do the work print "Snippets from " . DB . " containing $query:\n"; foreach ( $concordance->lines ) { print " * $_\n" } print "\n"; # graph where the query is located in the text print "A graph illustrating in what percentage of " . DB . " $query is located:\n"; my $barchart = Text::BarGraph->new(); $barchart->autosize( 0 ); $barchart->columns( 40 ); $barchart->sorttype( "numeric" ); $barchart->enable_color( 1 ); print $barchart->graph( $concordance->map ); print "\n"; # done exit;