Lingua::Sentence(3pm)

Lingua::Sentence3pm

Perl extension for breaking text paragraphs into sentences

Usage

        use Lingua::Sentence;
        my $splitter = Lingua::Sentence->new("en");
        my $text = 'This is a paragraph. It contains several sentences. "But why," you ask?';
        print $splitter->split($text);

Overview

This module allows splitting of text paragraphs into sentences. It is based on scripts developed by Philipp Koehn and Josh Schroeder for processing the Europarl corpus (<http://www.statmt.org/europarl/>).

The module uses punctuation and capitalization clues to split paragraphs into an newline-separated string with one sentence per line. For example:

        This is a paragraph. It contains several sentences. "But why," you ask?

goes to:

        This is a paragraph.
        It contains several sentences.
        "But why," you ask?

Languages currently supported by the module are:

Catalan
Czech
Dutch
English
French
German
Greek
Hungarian
Icelandic
Italian
Latvian
Polish
Portuguese
Russian
Spanish
Slovak
Slovenian
Swedish

Nonbreaking Prefixes Files

Nonbreaking prefixes are loosely defined as any word ending in a period that does NOT indicate an end of sentence marker. A basic example is Mr. and Ms. in English.

The sentence splitter module uses the nonbreaking prefix files included in this distribution.

To add a file for other languages, follow the naming convention nonbreaking_prefix.?? and use the two-letter language code you intend to use when creating a Lingua::Sentence object.

The sentence splitter module will first look for a file for the language it is processing, and fall back to English if a file for that language is not found.

For the splitter, normally a period followed by an uppercase word results in a sentence split. If the word preceeding the period is a nonbreaking prefix, this line break is not inserted.

A special case of prefixes, NUMERIC_ONLY, is included for special cases where the prefix should be handled ONLY when before numbers. For example, "Article No. 24 states this." the No. is a nonbreaking prefix. However, in "No. It is not true." No functions as a word.

See the example prefix files included in the distribution for more examples.

CREDITS

Thanks for the following individuals for supplying nonbreaking prefix files: Bas Rozema (Dutch), Hilário Leal Fontes (Portuguese), Jesús Giménez (Catalan & Spanish), Anne-Kathrin Schumann (Russian)

Export

new($lang_id)

Instantiate an object to split sentences in language $lang_id. If the language is not supported, a splitter object for English will be instantiated.

new($lang_id,$nonbreaking_prefix_file)

Instantiate an object to split sentences in language $lang_id and the nonbreaking prefix file $nonbreaking_prefix_file. If the file does not exist, a splitter object for English will be instantiated.

split($text)

Split sentences in $text by inserting newline characters at the sentence breaks. The resulting string is also terminated with a newline.

split_array($text)

Split sentences in $text into an array of sentences.

Support

Bugs should always be submitted via the project hosting bug tracker

<http://code.google.com/p/corpus-tools/issues/list>

For other issues, contact the maintainer.

Releases

6 releases since Debian 8 (Jessie); the text changed 3 times.

  1. 8–9
  2. 10
  3. 11
  4. 12–13

Author

Achim Ruopp, <[email protected]>

From liblingua-sentence-perl 1.100-3 in Debian 13 (Trixie). Parsed by carta from the page's man source.