|
Lingua::EN::Sentence - Module for splitting text into sentences. |
Lingua::EN::Sentence - Module for splitting text into sentences.
use Lingua::EN::Sentence qw( get_sentences add_acronyms );
add_acronyms('lt','gen'); ## adding support for 'Lt. Gen.'
my $sentences=get_sentences($text); ## Get the sentences.
foreach my $sentence (@$sentences) {
## do something with $sentence
}
The Lingua::EN::Sentence module contains the function get_sentences, which splits text into its constituent sentences, based on a regular expression and a list of abbreviations (built in and given).
Certain well know exceptions, such as abreviations, may cause incorrect segmentations. But some of them are already integrated into this code and are being taken care of. Still, if you see that there are words causing the get_sentences() to fail, you can add those to the module, so it notices them.
Basically, I use a 'brute' regular expression to split the text into sentences. (Well, nothing is yet split - I just mark the end-of-sentence). Then I look into a set of rules which decide when an end-of-sentence is justified and when it's a mistake. In case of a mistake, the end-of-sentence mark is removed.
What are such mistakes? Cases of abbreviations, for example. I have a list of such abbreviations (Please see `Acronym/Abbreviations list' section), and more general rules (for example, the abbreviations 'i.e.' and '.e.g.' need not to be in the list as a special rule takes care of all single letter abbreviations).
All functions used should be requested in the 'use' clause. None is exported by default.
set_EOS() to alter the end-of-sentence string to whatever you desire.
The following will set the LC_COLLATE behaviour to Argentinian Spanish. NOTE: The naming and avail ability of locales depends on your operating sys tem. Please consult the perllocale manpage for how to find out which locales are available in your system.
$loc = set_locale( ``es_AR.ISO8859-1'' );
This actually does this:
$loc = setlocale( LC_ALL, ``es_AR.ISO8859-1'' );
You can use the get_acronyms() function to get acronyms.
It has become too long to specify in the documentation.
If I come across a good general-purpose list - I'll incorporate it into this module. Feel free to suggest such lists.
Text::Sentence
Shlomo Yona shlomo@cs.haifa.ac.il
Copyright (c) 2001, 2002 Shlomo Yona. All rights reserved.
This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.
|
Lingua::EN::Sentence - Module for splitting text into sentences. |