#!/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 (created by the eg/dict_fetch
# program).
my $lexicon_file = 'lexicon';
my %lexicon;

# Define our lexicon.
if (@ARGV) {
    # We want to manually define it with bogus definitions.
    @lexicon{@ARGV} = ('x') x @ARGV;
}
elsif (-e $lexicon_file) {
    print "* Tie to existing dbm.\n";
    tie %lexicon, 'DB_File', $lexicon_file;
    # Define our lexicon with bogus definitions.
    @lexicon{ keys %lexicon } = ('x') x keys %lexicon;
}
else {
    print "* Use 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,
);

untie %lexicon if -e $lexicon_file;

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