#!/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.
    @lexicon{@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;
}
else {
    # Use made up fragments by default.
    print "* Using made up fragments.\n";
    @lexicon{qw(-ti -art -ion)} = ();
}

# 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.
$obj->output_knowns;
