Lingua-EN-Sentence-0.34000755000000000000 014444203511 15246 5ustar00unknownunknown000000000000Lingua-EN-Sentence-0.34/Build.PL000444000000000000 104614260712662 16710 0ustar00unknownunknown000000000000use Module::Build; Module::Build -> new ( module_name => 'Lingua::EN::Sentence', license => 'perl', dist_abstract => "Split text into sentences", dist_author => 'Shlomo Yona, Kim Ryan ', build_requires => { Test::More => 0.94, }, configure_requires => { Module::Build => 0.3800, }, requires => { 'perl' => '5.10.0', warnings => '1.06' }, meta_merge => { resources => { repository => 'https://github.com/kimryan/Lingua-EN-Sentence' } } ) -> create_build_script(); Lingua-EN-Sentence-0.34/Changes000444000000000000 1121214444173417 16726 0ustar00unknownunknown000000000000Revision history for Perl extension Lingua::EN::Sentence. 0.01 Thu Feb 22 12:16:17 2001 - original version; 0.02 Fri Feb 23 14:25:01 2001 (Thanks to Itai Nahshon for his comments!!) - Supporting 'no' abbreviation. - Exporting OK set_acronyms(),get_acronyms(). - Don't break on "." and a-like... - Fixed bug causing wrong breaking sentence if abbreviation is the first word. 0.03 Sun Feb 25 18:00:01 2001 (Thanks to Offer Kaye for his comments about the documentation) - Changes in the documentation. - Build package looks different now to support CPAN installer. - EOS changed to something which is \W. - Added get_EOS() set_EOS() to get/set the end-of-sentence mark. - Added a test for the installation. 0.04 Mon Mar 12 15:15:51 2001 - Added word boundary before correcting EOS with abbreviations. (bugfix) 0.05 Mon Mar 26 12:35:31 2001 - fix: "bla bla... yada yada" from being broken to: "bla bla..." and "yada yada" 0.06 Sun Apr 1 09:00:02 2001 - Added PLACES abbreviations (Thanks to Kim Ryan: kimaryan@ozemail.com.au) 0.07 Mon May 14 16:12:12 2001 - bug fix. 0.08 Mon May 21 05:55:23 2001 - Added months abbreviations. 0.09 Tue Aug 21 08:11:07 2001 - More abbreviations - Fixed bug where single letter before '.'/'?'/'!' didn't cause insertion of $EOS 0.10 Tue Aug 28 15:07:47 2001 - Fixed bug when processing stuff like " U.S. " 0.11 Tue Sep 4 15:12:55 2001 - Don't split |John P. Stenbit| into |John P.| and |Stenbit| 0.12 Thu Sep 20 11:28:45 2001 - Should be a final fix for same thing as reported in 0.11 0.13 Thu Oct 4 10:08:12 2001 - Bugfix splitting (wrongly!) after i.e. and e.g. and such - Previously, sentences like "They won the game 0-3. We lost" didn't get split. 0.14 Wed Oct 28 11:19:59 2001 - Added some more abbreviations - added symbol '' as another possibility of end-quote. - Abbreviations added from: http://englishplus.com/grammar/00000057.htm - Abbreviations added from: http://www.nyu.edu/classes/copyXediting/STABBREV.html 0.15 Sun Nov 18 13:12:07 2001 - French use M. for Mr. - Don't split sentences starting with a quote after the quote if the following text is not a capital letter. 0.16 Sun Nov 18 17:00:04 2001 - testbench reduced to "nothing" again... 0.17 Sun Nov 18 18:01:14 2001 - Considering French as well - some french characters are considered as \W - I had to exclude them by literaly writing them. 0.18 Wed Nov 21 19:36:17 2001 - Using locale for allowing usage of iso8859-1. I'm expecting to find English and French (like) text, so I want my \w and \W to match the right things. 0.19 Sun Dec 23 09:26:39 2001 - Added some more abbreviations. - Trying not to break: text . . some more text 0.20 Wed Dec 26 09:43:09 2001 - Break at the dot: concretizar-se-. Astiazaram - Fixed bugs with abbreviation 'no.'. 0.21 Sun Jan 13 08:22:13 2002 - break sentence when: ... - break on: ... Bush's. Bla Bla - Added abbreviation 'Capt.' 0.22 Wed Jan 30 13:15:31 2002 - Added more acronyms. - Hopefully not breaking anymore NY like street addresses. - In general, don't break on single letter followed by a dot. - Special attention to abbreviation 'no.'. - bugfix conserning internal variable $PAP - added set_locale() 0.23 Sun Feb 17 09:00:00 2002 - Break sentence after seeing "a.m." or "p.m." followed by a capital letter. - Added some abbreviations 0.24 Mon Sep 23 12:30:02 2002 - Changing the "rights" notice. 0.25 Tue Sep 24 13:28:33 IDT 2002 - changed the email address. 0.26 Mar 12 2015 - Fixed POD errors - Fixed RT bug 97681, setlocale work around for Android systems - Added Build.PL - Added tests harness and more tests - update to newer Perl idioms such as 'our' variables 0.27 Mar 12 2015 - added main.t to MANIFEST - added more prefixes and suffixes for people's names, such as Mme. , Msgr. 0.28 May 22 2015 Fixed RT bug #104419: [PATCH] make abbreviation processing faster 0.29 May 25 2015 Fixed RT bug #104637 [PATCH]improve documentation on acronym input Removed redundant call that remained after 104419 patch was applied 0.30 Aug 08 2016 used github as repository added more abbreviations set the default character set to en_US.UTF-8 added example/demo.pl script 0.31 Aug 19 2018 Declared min version of Perl. Fix for RT bug #124686 0.32 July 2022 fixed bug causing abbreviation followed by '(' to break sentence, reported in github dot following an abbreviation now explicitly marked up added more acronyms improved documentation improved tests added verbose moe for debugging 0.33 July 05 2022 fixed version numbers in Build.PL and Makefile.PL 0.34 June 20 2023 fixed version numbers in Build.PL and Makefile.PL Lingua-EN-Sentence-0.34/LICENCE000444000000000000 4443113336223472 16425 0ustar00unknownunknown000000000000This software is copyright (c) 2018 by Kim Ryan. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2016 by Kim Ryan. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Suite 500, Boston, MA 02110-1335 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2016 by Kim Ryann. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Lingua-EN-Sentence-0.34/MANIFEST000444000000000000 17414260502412 16514 0ustar00unknownunknown000000000000Changes README MANIFEST LICENCE Makefile.PL Build.PL lib/Lingua/EN/Sentence.pm t/main.t examples/demo.pl META.yml META.json Lingua-EN-Sentence-0.34/META.json000444000000000000 230714444203511 17026 0ustar00unknownunknown000000000000{ "abstract" : "Split text into sentences", "author" : [ "Shlomo Yona, Kim Ryan " ], "dynamic_config" : 1, "generated_by" : "Module::Build version 0.4229", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Lingua-EN-Sentence", "prereqs" : { "build" : { "requires" : { "Test::More" : "0.94" } }, "configure" : { "requires" : { "Module::Build" : "0.38" } }, "runtime" : { "requires" : { "perl" : "v5.10.0", "warnings" : "1.06" } } }, "provides" : { "Lingua::EN::Sentence" : { "file" : "lib/Lingua/EN/Sentence.pm", "version" : "0.34" } }, "release_status" : "stable", "resources" : { "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "url" : "https://github.com/kimryan/Lingua-EN-Sentence" } }, "version" : "0.34", "x_serialization_backend" : "JSON::PP version 4.04" } Lingua-EN-Sentence-0.34/META.yml000444000000000000 137214444203511 16657 0ustar00unknownunknown000000000000--- abstract: 'Split text into sentences' author: - 'Shlomo Yona, Kim Ryan ' build_requires: Test::More: '0.94' configure_requires: Module::Build: '0.38' dynamic_config: 1 generated_by: 'Module::Build version 0.4229, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Lingua-EN-Sentence provides: Lingua::EN::Sentence: file: lib/Lingua/EN/Sentence.pm version: '0.34' requires: perl: v5.10.0 warnings: '1.06' resources: license: http://dev.perl.org/licenses/ repository: https://github.com/kimryan/Lingua-EN-Sentence version: '0.34' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Lingua-EN-Sentence-0.34/Makefile.PL000444000000000000 143214260712577 17372 0ustar00unknownunknown000000000000use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'Lingua::EN::Sentence', 'ABSTRACT' => 'Split text into sentences', 'VERSION_FROM' => 'lib/Lingua/EN/Sentence.pm', # finds $VERSION 'PREREQ_PM' => { 'perl' => '5.10.0', 'warnings' => '1.06' }, 'AUTHOR' => 'Shlomo Yona, Kim Ryan', 'LICENSE' => 'perl', META_MERGE => { 'meta-spec' => { version => 2 }, resources => { repository => { type => 'git', url => 'https://github.com/kimryan/Lingua-EN-Sentence.git', web => 'https://github.com/kimryan/Lingua-EN-Sentence' }, }, } ); Lingua-EN-Sentence-0.34/README000444000000000000 372314260756227 16305 0ustar00unknownunknown000000000000 NAME Lingua::EN::Sentence - split text into sentences SYNOPSIS use Lingua::EN::Sentence qw( get_sentences add_acronyms ); add_acronyms('lt','gen'); ## adding support for 'Lt. Gen.' my $text = q{ A sentence usually ends with a dot, exclamation or question mark optionally followed by a space! A string followed by 2 carriage returns denotes a sentence, even though it doesn't end in a dot Dots after single letters such as U.S.A. or in numbers like -12.34 will not cause a split as well as common abbreviations such as Dr. I. Smith, Ms. A.B. Jones, Apr. Calif. Esq. and (some text) ellipsis such as ... or . . are ignored. Some valid cases canot be deteected, such as the answer is X. It cannot easily be differentiated from the single letter-dot sequence to abbreviate a person's given name. Numbered points within a sentence will not cause a split 1. Like this one. See the code for all the rules that apply. This string has 7 sentences. }; my $sentences=get_sentences($text); # Get the sentences. foreach my $sent (@$sentences) { $i++; print("SENTENCE $i:$sent\n"); } DESCRIPTION The C 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 abbreviations, 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 function to fail, you can add those to the module, so it notices them. Note that abbreviations are case sensitive, so 'Mrs.' is recognised but not 'mrs.' INSTALLATION To install this module, type the following: perl Makefile.PL make make test make install or perl Build.PL build build test build install MAINTAINER This project was originated by Shlomo Yona. Currently maintained by Kim Ryan Lingua-EN-Sentence-0.34/examples000755000000000000 014444203511 17064 5ustar00unknownunknown000000000000Lingua-EN-Sentence-0.34/examples/demo.pl000444000000000000 352114444203275 20512 0ustar00unknownunknown000000000000=head Demo program of CPAN module Lingua::EN::Sentence, sentence splitter =cut use strict; use warnings; use Lingua::EN::Sentence qw( get_sentences add_acronyms get_EOS set_EOS set_locale); print("Started\n"); my $text = q{ A sentence usually ends with a dot, exclamation or question mark optionally followed by a space! A string followed by 2 carriage returns denotes a sentence, even though it doesn't end in a dot Dots after single letters such as U.S.A. or in numbers like -12.34 will not cause a split as well as common abbreviations such as Dr. I. Smith, Ms. A.B. Jones, Apr. Calif. Esq. and (some text) ellipsis such as ... or . . are ignored. Some valid cases canot be deteected, such as the answer is X. It cannot easily be differentiated from the single letter-dot sequence to abbreviate a person's given name. Numbered points within a sentence will not cause a split 1. Like this one. See the code for all the rules that apply. This string has 7 sentences. }; my $sentences=get_sentences($text); if (defined($sentences)) { my $num_sentences = (@$sentences); my $i; print("There are: $num_sentences sentences\n" ); foreach my $sent (@$sentences) { $i++; print("SENTENCE $i:$sent\n"); } } $text = q{First sentence. 12. point 12 Some numbers 12.46, -.123,3:. Some ‘utf quotes wrap this’ “And more”}; # Filter out common multi byte characters, such as the utf symbols for curly quotes # These will cause wide character warnings to be issued $text =~ s/‘/'/g; $text =~ s/’/'/g; $text =~ s/“/"/g; $text =~ s/”/"/g; # Change lines starting with numbered points from x. to x) to avoid confusion with dots $text =~ s/\n(\d{1,})./\n$1\)/g; $sentences=get_sentences($text); ## Get the sentences. my $num_sentences = (@$sentences); foreach my $sent (@$sentences) { print("$sent\n"); } Lingua-EN-Sentence-0.34/lib000755000000000000 014444203511 16014 5ustar00unknownunknown000000000000Lingua-EN-Sentence-0.34/lib/Lingua000755000000000000 014444203511 17233 5ustar00unknownunknown000000000000Lingua-EN-Sentence-0.34/lib/Lingua/EN000755000000000000 014444203511 17535 5ustar00unknownunknown000000000000Lingua-EN-Sentence-0.34/lib/Lingua/EN/Sentence.pm000444000000000000 3605014444173465 22036 0ustar00unknownunknown000000000000package Lingua::EN::Sentence; =head1 NAME Lingua::EN::Sentence - split text into sentences =head1 SYNOPSIS use Lingua::EN::Sentence qw( get_sentences add_acronyms ); add_acronyms('lt','gen'); ## adding support for 'Lt. Gen.' my $text = q{ A sentence usually ends with a dot, exclamation or question mark optionally followed by a space! A string followed by 2 carriage returns denotes a sentence, even though it doesn't end in a dot Dots after single letters such as U.S.A. or in numbers like -12.34 will not cause a split as well as common abbreviations such as Dr. I. Smith, Ms. A.B. Jones, Apr. Calif. Esq. and (some text) ellipsis such as ... or . . are ignored. Some valid cases canot be deteected, such as the answer is X. It cannot easily be differentiated from the single letter-dot sequence to abbreviate a person's given name. Numbered points within a sentence will not cause a split 1. Like this one. See the code for all the rules that apply. This string has 7 sentences. }; if (defined($sentences)) { my $sentences = get_sentences($text); foreach my $sent (@$sentences) { $i++; print("SENTENCE $i:$sent\n"); } } =head1 DESCRIPTION The C 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 abbreviations, 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 function to fail, you can add those to the module, so it notices them. Note that abbreviations are case sensitive, so 'Mrs.' is recognised but not 'mrs.' =head1 ALGORITHM The first step is to mark the dot ending an abbreviation by changing it to a special character. Now it won't cause a sentence split. The original dot is restored after the sentences are split 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? Letter-dot sequences: U.S.A. , i.e. , e.g. Dot sequences: '..' or '...' or 'text . . more text' Two carriage returns denote the end of a sentence even if it doesn't end with a dot =head1 LIMITATIONS 1) John F. Kennedy was a former president 2) The answer is F. That ends the quiz In the first sentence, F. is detected as a persons initial and not the end of a sentence. But this means we cannot detect the true end of sentence 2, which is after the 'F'. This case is not common though. =head1 FUNCTIONS All functions used should be requested in the 'use' clause. None is exported by default. =over 4 =item get_sentences( $text ) The get_sentences function takes a scalar containing ascii text as an argument and returns a reference to an array of sentences that the text has been split into. Returned sentences will be trimmed (beginning and end of sentence) of white space. Strings with no alpha-numeric characters in them, won't be returned as sentences. If no text is supplied, a reference to an empty array is returned. =item add_acronyms( @acronyms ) This function is used for adding acronyms not supported by this code. The input should be regular expressions for matching the desired acronyms, but should not include the final period (C<.>). So, for example, C matches C and C. C will match C. You do not need to bother with acronyms consisting of single letters and dots (e.g. "U.S.A."), as these are found automatically. Note also that acronyms are searched for on a case insensitive basis. Please see 'Acronym/Abbreviations list' section for the abbreviations already supported by this module. =item get_acronyms( ) This function will return the defined list of acronyms. =item set_acronyms( @my_acronyms ) This function replaces the predefined acronym list with the given list. See L for details on the input specifications. =item get_EOS( ) This function returns the value of the string used to mark the end of sentence. You might want to see what it is, and to make sure your text doesn't contain it. You can use set_EOS() to alter the end-of-sentence string to whatever you desire. =item set_EOS( $new_EOS_string ) This function alters the end-of-sentence string used to mark the end of sentences. =item set_locale( $new_locale ) Receives language locale in the form language.country.character-set for example: "fr_CA.ISO8859-1" for Canadian French using character set ISO8859-1. Returns a reference to a hash containing the current locale formatting values. Returns undef if got undef. The following will set the LC_COLLATE behaviour to Argentinian Spanish. NOTE: The naming and availability of locales depends on your operating sysem. 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" ); =back =head1 Acronym/Abbreviations list 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. =head1 FUTURE WORK [1] Object Oriented like usage [2] Supporting more than just English/French [3] Code optimization. Currently everything is RE based and not so optimized RE [4] Possibly use more semantic heuristics for detecting a beginning of a sentence =head1 SEE ALSO Text::Sentence Lingua::Sentence Raku port of Lingua::EN::Sentence =head1 REPOSITORY L =head1 AUTHOR Shlomo Yona shlomo@cs.haifa.ac.il Currently being maintained by Kim Ryan, kimryan at CPAN d o t org =head1 COPYRIGHT AND LICENSE Copyright (c) 2001-2016 Shlomo Yona. All rights reserved. Copyright (c) 2022 Kim Ryan. All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut #============================================================================== # # Pragmas # #============================================================================== use strict; use warnings; use POSIX qw(locale_h setlocale); #============================================================================== # # Modules # #============================================================================== use Exporter; #============================================================================== # # Public globals # #============================================================================== use vars qw/$VERSION @ISA @EXPORT_OK $EOS $LOC $AP $P $PAP @ABBREVIATIONS/; use Carp qw/cluck/; use English; our $VERSION = '0.34'; our $LOC; if ($OSNAME ne 'android') { # Call POSIX function $LOC= setlocale(LC_CTYPE, "en_US.UTF-8"); } use locale; @ISA = qw( Exporter ); @EXPORT_OK = qw( get_sentences add_acronyms get_acronyms set_acronyms get_EOS set_EOS set_locale); our $VERBOSE = 0; # echo intermediate data transforms, useful for debugging our $EOS = "\001"; our $EOA = '__EOA__'; our $P = q/[\.!?]/; # PUNCTUATION $AP = q/(?:'|"|\?|\)|\]|\})?/; # AFTER PUNCTUATION our $PAP = $P.$AP; # ACRONYMS AND ABBREVIATIONS my @PEOPLE = qw( Mr Mrs Ms Dr Prof Mme Ms?gr Sens? Reps? Gov Attys? Supt Insp Const Det Revd? Ald Rt Hon); my @TITLE_SUFFIXES = qw(PhD Jn?r Sn?r Esq MD LLB); my @MILITARY = qw( Col Gen Lt Cm?dr Adm Capt Sgt Cpl Maj Pte); my @INSTITUTES = qw( Dept Univ Assn Bros); my @COMPANIES = qw( Inc Pty Ltd Co Corp); my @PLACES = qw( Arc Al Ave Blv?d Cl Ct Cres Dr Expy? Fw?y Hwa?y La Pde? Pl Plz Rd St Tce dist mt km in ft Ala Ariz Ark Cal Calif Col Colo Conn Del Fed Fla Ga Ida Id Ill Ind Ia Kan Kans Ken Ky La Me Md Is Mass Mich Minn Miss Mo Mont Neb Nebr Nev Mex Okla Ok Ore Penna Penn Pa Dak Tenn Tex Ut Vt Va Wash Wis Wisc Wy Wyo USAFA Alta Man Ont Qu? Sask Yuk Aust Vic Qld Tas ); my @MONTHS = qw(Jan Feb Mar Apr May Jun Jul Aug Sept? Oct Nov Dec); my @MISC = qw(no esp est); # Established my @LATIN = qw(vs etc al ibid sic); my @MATH = qw(fig eq sec cf Thm Def Conj resp); our @ABBREVIATIONS = (@PEOPLE, @TITLE_SUFFIXES, @MILITARY, @INSTITUTES, @COMPANIES, @PLACES, @MONTHS, @MISC,@LATIN, @MATH); #============================================================================== # # Public methods # #============================================================================== #------------------------------------------------------------------------------ # get_sentences - takes text input and splits it into sentences. # A regular expression viciously cuts the text into sentences, # and then a list of rules (some of them consist of a list of abbreviations) # are applied on the marked text in order to fix end-of-sentence markings in # places which are not indeed end-of-sentence. #------------------------------------------------------------------------------ sub get_sentences { my ($text) = @_; unless (defined($text)) { return []; } $VERBOSE and print("ORIGINAL\n$text\n"); $text = mark_up_abbreviations($text); $VERBOSE and print("mark_up_abbreviations\n$text\n"); $text = first_sentence_breaking($text); $VERBOSE and print("first_sentence_breaking\n$text\n"); $text = remove_false_end_of_sentence($text); $VERBOSE and print("remove_false_end_of_sentence\n$text\n"); $text = split_unsplit_stuff($text); $VERBOSE and print("split_unsplit_stuff\n$text\n"); my @sentences = split(/$EOS/,$text); my $cleaned_sentences = clean_sentences(\@sentences); if ($VERBOSE) { my $i; foreach my $sent (@$cleaned_sentences) { $i++; print("SENTENCE $i >>>$sent<<<\n"); } } return $cleaned_sentences; } #------------------------------------------------------------------------------ # add_acronyms - user can add a list of acronyms/abbreviations. #------------------------------------------------------------------------------ sub add_acronyms { push @ABBREVIATIONS, @_; } #------------------------------------------------------------------------------ # get_acronyms - get list of defined acronyms. #------------------------------------------------------------------------------ sub get_acronyms { return @ABBREVIATIONS; } #------------------------------------------------------------------------------ # set_acronyms - replace the predefined acronyms list with your own list. #------------------------------------------------------------------------------ sub set_acronyms { @ABBREVIATIONS=@_; } #------------------------------------------------------------------------------ # get_EOS - get the value of the $EOS variable (end-of-sentence mark). #------------------------------------------------------------------------------ sub get_EOS { return $EOS; } #------------------------------------------------------------------------------ # set_EOS - set the value of the $EOS variable (end-of-sentence mark). #------------------------------------------------------------------------------ sub set_EOS { my ($new_EOS) = @_; if (not defined $new_EOS) { cluck "Won't set \$EOS to undefined value!\n"; return $EOS; } $EOS = $new_EOS; return $EOS; } #------------------------------------------------------------------------------ # set_locale - set the value of the locale. # # Receieves language locale in the form # language.country.character-set # for example: # "fr_CA.ISO8859-1" # for Canadian French using character set ISO8859-1. # # Returns a reference to a hash containing the current locale formatting values. # Returns undef if got undef. # # The following will set the LC_ALL behaviour to Argentinian Spanish. # NOTE: The naming and availability of locales depends on your operating system. # 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" ); # NOTE, but actually does LC_CTYPE, should be LC_COLLATE? #------------------------------------------------------------------------------ sub set_locale { my ($new_locale) = @_; if (not defined $new_locale) { cluck "Won't set locale to undefined value!\n"; return undef; } if ($OSNAME ne 'android') { # Call POSIX function $LOC = setlocale(LC_CTYPE, $new_locale); return $LOC; } else { return undef; } } #============================================================================== # # Private methods # #============================================================================== sub remove_false_end_of_sentence { my ($marked_segment) = @_; # don't split U.S.A., U.K. $marked_segment=~s/([^-\w]\w$PAP\s)$EOS/$1/sg; $marked_segment=~s/([^-\w]\w$P)$EOS/$1/sg; # don't split after a white-space followed by a single letter or number followed # by a dot followed by another whitespace., such as "Something. 1. point one" # Note: will fail for 12. Point 12 $marked_segment=~s/(\s[\w\d]\.\s+)$EOS/$1/sg; # fix ellipsis: bla bla... yada yada $marked_segment=~s/(\.\.\. )$EOS([[:lower:]])/$1$2/sg; # fix quoted EOS such as "." "?" "!" $marked_segment=~s/(['"]$P['"]\s+)$EOS/$1/sg; # don't break after quote unless its a capital letter. $marked_segment=~s/(["']\s*)$EOS(\s*[[:lower:]])/$1$2/sg; # don't break: text . . some more text. $marked_segment=~s/(\s\.\s)$EOS(\s*)/$1$2/sg; $marked_segment=~s/(["']\s*)$EOS(\s*[[:lower:]])/$1$2/sg; $marked_segment=~s/(\s$PAP\s)$EOS/$1/sg; return $marked_segment; } sub split_unsplit_stuff { my ($text) = @_; # breaks numbered points, such as {EOL}1. point one $text=~s/([\w $P]\d)($P)(\s+)/$1$2$EOS$3/sg; # eg 'end. (' -> 'end. $EOS (' $text=~s/($PAP\s)(\s*\()/$1$EOS$2/gs; # open bracket $text=~s/('\w$P)(\s)/$1$EOS$2/gs; $text=~s/(\sno\.)(\s+)(?!\d)/$1$EOS$2/gis; # add EOS when you see "a.m." or "p.m." followed by a capital letter. $text=~s/([ap]\.m\.\s+)([[:upper:]])/$1$EOS$2/gs; return $text; } sub clean_sentences { my ($sentences) = @_; my $cleaned_sentences; foreach my $s (@$sentences) { next if not defined $s; next if $s!~m/\w+/; $s=~s/^\s*//; $s=~s/\s*$//; ## $s=~s/\s+/ /g; # replace end of abbrev marker with a dot $s=~s/$EOA/\./g; push @$cleaned_sentences,$s; } return $cleaned_sentences; } # Replace sequence such as Mr. A. Smith Jnr. with Mr__EOA__ A__EOA__ etc # This simplifies the code that detects end of sentnees. The marker is # replaced with the original dot adter sentence slitting sub mark_up_abbreviations { my ($text) = @_; my %found_abbrevs; foreach my $abbrev (@ABBREVIATIONS) { if ($text=~/\b($abbrev)\./i) { $found_abbrevs{$abbrev} = 1; } } foreach my $abbrev (keys %found_abbrevs) { $text=~s/($abbrev)\./$1$EOA/gs; } return $text; } sub first_sentence_breaking { my ($text) = @_; $text=~s/\n\s*\n/$EOS/gs; ## double new-line means a different sentence. $text=~s/($PAP\s)/$1$EOS/gs; $text=~s/(\s\w$P)/$1$EOS/gs; # break also when single letter comes before punc. return $text; } 1; Lingua-EN-Sentence-0.34/t000755000000000000 014444203511 15511 5ustar00unknownunknown000000000000Lingua-EN-Sentence-0.34/t/main.t000444000000000000 266214260501674 16774 0ustar00unknownunknown000000000000#------------------------------------------------------------------------------ # Test script for Lingua::EN::Sentence.pm # # Author : Kim Ryan, # Last update : 2015-03-10 #------------------------------------------------------------------------------ use warnings; use strict; use Test::More tests => 3; BEGIN { # does it load properly? require_ok('Lingua::EN::Sentence'); } use Lingua::EN::Sentence qw( get_sentences add_acronyms get_acronyms); my $par = q{ A sentence usually ends with a dot, exclamation or question mark optionally followed by a space! A string followed by 2 carriage returns denotes a sentence, even though it doesn't end in a dot Dots after single letters such as U.S.A. or in numbers like -12.34 will not cause a split as well as common abbreviations such as Dr. I. Smith, Ms. A.B. Jones, Apr. Calif. Esq. and (some text) ellipsis such as ... or . . are ignored. Some valid cases canot be deteected, such as the answer is X. It cannot easily be differentiated from the single letter-dot sequence to abbreviate a person's given name. Numbered points within a sentence will not cause a split 1. Like this one. See the code for all the rules that apply. This string has 7 sentences. }; my $sentences=get_sentences($par); is( @$sentences, 7,'sub sentence_count'); $par .= 'Now add an acronym, such as Ret. for retired.'; add_acronyms('Ret'); $sentences=get_sentences($par); is( @$sentences, 8,'sub add_acronyms');