#!/usr/bin/perl -w
use strict;
use Data::Dumper;
use DB_File;
use Lingua::TokenParse;

# Grab a word from the command line, or just use a sample.
my $word = shift @ARGV || 'partition';

# The filename of the lexicon to use.
my $lexicon_file = 'lexicon';

# Use a dict server and save the results, if we are not providing the
# lexicon on the command line, do not already have a lexicon dbm file,
# and are on the 'net.
do 'dict_fetch' unless @ARGV or -e $lexicon_file;

# Okay, get our lexicon.
my %lexicon;

if (@ARGV) {
    # We want to manually define it with bogus definitions.
    @lexicon{@ARGV} = ('x') x @ARGV;
}
elsif (-e $lexicon_file) {
    # Tie to a dbm for if it's present.
    print "* Tie to existing lexicon dbm.\n";
    tie %lexicon, 'DB_File', $lexicon_file;
    # Define our lexicon with bogus definitions.
    @lexicon{ keys %lexicon } = ('x') x keys %lexicon;
}
else {
    # Use made up fragments by default.
    print "* Using made up fragments.\n";
    @lexicon{qw(part- -tion -on)} = qw(foo bar baz);
}

# Dump stuff.
#print "$word\n";
#print Dumper \%lexicon;
#print scalar keys %lexicon;

# Make a token parse object.
my $obj = Lingua::TokenParse->new(
    word => $word,
    lexicon => \%lexicon,
);

# Close our lexicon dbm, if we are using one.
untie %lexicon if -e $lexicon_file;

# Output the results.
print scalar $obj->output_knowns;
