Text::Contraction - Find possible expansions for a contraction.


Text-Contraction documentation  | view source Contained in the Text-Contraction distribution.

Index


NAME

Top

Text::Contraction - Find possible expansions for a contraction.

SYNOPSIS

Top

  use Text::Contraction;
  my $tc = Text::Contraction->new();
  my @matches = $tc->match('flgstff');

  # on my system this produces 'Flagstaff'

ABSTRACT

Top

Text::Contraction finds possible expansions for a contraction. It relies on the system dictionary for the list of candidate words, or the user may supply a dictionary of their own choosing.

DESCRIPTION

Top

This module finds possible expansions for a contraction. By default, the search is performed case-insensitively, at least half of the letters in the expansion must come from the contraction (thus the longest expansion that will be returned will be twice as long as the contraction) and the first letter of the contraction must be the first letter of the expansion.

This default behavior can easily be changed. In addition, although this module will attempt to use your system's dictionary, you can also supply your own dictionary (really just a file of words or phrases, one per line).

CONSTRUCTOR

Top

$tc = Text::Contraction->new(OPTIONS)

Options may be specified as keyword-value pairs. The following options are recognized:

caseless

Perform search case insensitively. DEFAULT: 1

minRatio

Minimum ratio of letters from the contraction to letters in the possible expansions. If minRatio if 0.5 and there are 4 letters in the contraction, the longest word that will be returned will have 8 letters. Apostrophes in the contraction do not count, but apostrophes in the expansions do. This is most likely a bug. minRatio must be between 0 and 1, inclusive. DEFAULT: 0.5

prefix

Prefix that all candidate words must match. Set to empty string to allow for expansions that do not necessarily have the same first letter as the contraction. DEFAULT: ^

words

An array reference of words to use. If not specified, then first the environment variable CONTRACTION_WORDS is checked to see if it points to a dictionary file. Otherwise, various well-known locations are searched for a system dictionary. If your system has a dictionary somewhere that this module cannot find, please let me know.

ACCESSORS

Top

caseless
minRatio
prefix
words

METHODS

Top

$tc->study()

Index the list of words. If study() is not called, it will be automatically called upon the first call to match().

@matches = $tc->match($contraction)

Returns possible expansions for the supplied contraction.

HISTORY

Top

0.01

Original version; created by h2xs 1.22

0.02

Documentation tweaks. Added tests.

SEE ALSO

Top

Text::Abbrev

AUTHOR

Top

Benjamin Holzman, <bholzman@earthlink.net>

COPYRIGHT AND LICENSE

Top


Text-Contraction documentation  | view source Contained in the Text-Contraction distribution.