Lingua-EN-Inflect-Phrase-0.20000755001750001750 013245023070 16645 5ustar00rkitoverrkitover000000000000README100644001750001750 537513245023070 17620 0ustar00rkitoverrkitover000000000000Lingua-EN-Inflect-Phrase-0.20NAME Lingua::EN::Inflect::Phrase - Inflect short English Phrases SYNOPSIS use Lingua::EN::Inflect::Phrase; use Test::More tests => 2; my $plural = Lingua::EN::Inflect::Phrase::to_PL('green egg and ham'); is $plural, 'green eggs and ham'; my $singular = Lingua::EN::Inflect::Phrase::to_S('green eggs and ham'); is $singular, 'green egg and ham'; DESCRIPTION Attempts to pluralize or singularize short English phrases. Does not throw exceptions at present, if you attempt to pluralize an already pluralized phrase, it will leave it unchanged (and vice versa.) The behavior of this module is subject to change as I tweak the heuristics, as some things get fixed others might regress. The processing of natural language is a messy business. If it doesn't work, please email or submit to RT the example you tried, and I'll try to fix it. OPTIONS By default, this module prefers to treat words as nouns (sometimes words can be interpreted as a verb or a noun without context.) This is better for things such as database table/column names, which is what this module is primarily for. This behavior can be switched with the variable $prefer_nouns. The default is 1. For example: { local $Lingua::EN::Inflect::Phrase::prefer_nouns = 0; is Lingua::EN::Inflect::Phrase::to_S('sources split'), 'source splits'; } { local $Lingua::EN::Inflect::Phrase::prefer_nouns = 1; is Lingua::EN::Inflect::Phrase::to_S('source splits'), 'source split'; } OPTIONAL EXPORTS "to_PL", "to_S" SUBROUTINES to_PL Attempts to pluralizes a phrase unless already plural. to_S Attempts to singularize a phrase unless already singular. BUGS Please report any bugs or feature requests to bug-lingua-en-inflect-phrase at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Lingua-EN-Inflect-Phrase. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. REPOSITORY git clone git://github.com/rkitover/lingua-en-inflect-phrase.git lingua-en-inflect-phrase SEE ALSO Lingua::EN::Inflect, Lingua::EN::Inflect::Number, Lingua::EN::Tagger AUTHOR rkitover: Rafael Kitover CONTRIBUTORS zakame: Zak B. Elep LICENSE AND COPYRIGHT Copyright (c) 2018 Rafael Kitover (rkitover@cpan.org). This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. Changes100644001750001750 404413245023070 20223 0ustar00rkitoverrkitover000000000000Lingua-EN-Inflect-Phrase-0.20Revision history for Lingua-EN-Inflect-Phrase 0.20 2018-02-26 10:22:28 - fix for CPANTS Kwalitee issues by Zak B. Elep (zakame): add MetaProvides::Package and MinimumPerl to dist.ini 0.19 2018-01-31 13:59:53 - fix for tagged proper nouns and -ity/-ities nouns by Zak B. Elep (zakame) (RT#118767) 0.18 2012-12-27 00:09:43 - fix meta repository info (RT#82274) 0.17 2012-12-25 14:09:56 - fix for ordinal number phrases, 'first release' was singularizing to 'first releases' (RT#82242) 0.16 2012-11-05 02:43:34 - bump up Lingua::EN::Tagger dep again due to unescaped braces in regexes 0.15 2012-09-27 22:17:00 - fix uninitialized warnings on older perls 0.14 2012-09-24 03:56:10 - add $prefer_nouns config variable, defaulting to 1, which allows the recognition of phrases such as 'source splits' - much better number handling, in both number and word form 0.13 2012-08-30 05:30:04 - bump Lingua::EN::Tagger dep to 0.20 due to unescaped braces in regexes 0.12 2012-01-10 22:44:02 - fix "statuses" -> "status" 0.11 2011-12-18 06:25:33 - fix "aliases" and "referral logs" (RT#73242) 0.10 2011-10-15 17:17:03 - special case "people" and "heroes" 0.09 2011-10-15 14:32:04 - fix inflection of "a" to "some" 0.08 2011-10-11 22:31:58 - special case the verb "belongs", as the new fallback to verbs was breaking DBIx::Class::Schema::Loader tests. 0.07 2011-10-10 22:07:35 - remove special case for "single", as it was wrong 0.06 2011-10-10 22:01:14 - handle "negative acknowledges" 0.05 2011-10-10 21:37:57 - fix some bugs discovered in String::ToIdentifier::EN - better support for numbers and number words 0.04 2010-03-17 21:30:04 - POD improvements 0.03 2010-03-16 20:09:31 - clean up code 0.02 2010-03-16 16:28:39 - some improvements and fixes for DBIx::Class::Schema::Loader 0.01 2010-03-16 15:16:16 - first release LICENSE100644001750001750 4366313245023070 17767 0ustar00rkitoverrkitover000000000000Lingua-EN-Inflect-Phrase-0.20This software is copyright (c) 2018 by Rafael Kitover. 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) 2018 by Rafael Kitover. 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, Fifth Floor, Boston, MA 02110-1301 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) 2018 by Rafael Kitover. 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 dist.ini100644001750001750 52713245023070 20356 0ustar00rkitoverrkitover000000000000Lingua-EN-Inflect-Phrase-0.20name = Lingua-EN-Inflect-Phrase author = Rafael Kitover license = Perl_5 copyright_holder = Rafael Kitover copyright_year = 2018 [@AVAR] dist = Lingua-EN-Inflect-Phrase bugtracker = rt github_user = rkitover install_command = cpanm . [MinimumPerl] [MetaProvides::Package] [ContributorsFromPod]t000755001750001750 013245023070 17031 5ustar00rkitoverrkitover000000000000Lingua-EN-Inflect-Phrase-0.20bugs.t100644001750001750 235313245023070 20321 0ustar00rkitoverrkitover000000000000Lingua-EN-Inflect-Phrase-0.20/tuse strict; use warnings; use Test::More; use Test::NoWarnings (); use Lingua::EN::Inflect::Phrase qw/to_S to_PL/; use lib 't/lib'; use TestPhrase 'test_phrase'; # Some bugs I found while working on String::ToIdentifier::EN. test_phrase '2 dots', '2 dots'; test_phrase '2 at signs', '2 at signs'; test_phrase '2 left braces', '2 left braces'; test_phrase '2 right braces', '2 right braces'; is to_PL('right brace'), 'right braces', '"right brace" pluralizes to "right braces"'; test_phrase '2 single quotes', '2 single quotes'; # Here's one oliver found, "a" singularizes and pluralizes to "some" test_phrase 'a', 'as'; # Some bugs people found while using Schema::Loader test_phrase 'person', 'people'; test_phrase 'hero', 'heroes'; test_phrase 'referal log', 'referal logs'; # sic test_phrase 'referral log', 'referral logs'; test_phrase 'alias', 'aliases'; # this one's from haarg test_phrase 'status', 'statuses'; # this one's from jhanna # $prefer_nouns defaults to 1 test_phrase 'source split', 'source splits', 'prefer_nouns=1'; { local $Lingua::EN::Inflect::Phrase::prefer_nouns = 0; test_phrase 'source splits', 'sources split', 'prefer_nouns=0'; } Test::NoWarnings::had_no_warnings; done_testing; # vim:et sts=2 sw=2 tw=0: META.yml100644001750001750 244113245023070 20200 0ustar00rkitoverrkitover000000000000Lingua-EN-Inflect-Phrase-0.20--- abstract: 'Inflect short English Phrases' author: - 'Rafael Kitover ' build_requires: File::Spec: '0' IO::Handle: '0' IPC::Open3: '0' Test::More: '0' Test::NoWarnings: '0' lib: '0' perl: '5.006' configure_requires: ExtUtils::MakeMaker: '0' perl: '5.006' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.010, 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-Inflect-Phrase no_index: directory: - t provides: Lingua::EN::Inflect::Phrase: file: lib/Lingua/EN/Inflect/Phrase.pm version: '0.20' requires: Exporter: '0' Lingua::EN::FindNumber: '0' Lingua::EN::Inflect: '0' Lingua::EN::Inflect::Number: '0' Lingua::EN::Number::IsOrdinal: '0' Lingua::EN::Tagger: '0' perl: '5.006' strict: '0' warnings: '0' resources: bugtracker: https://rt.cpan.org/Public/Dist/Display.html?Name=Lingua-EN-Inflect-Phrase homepage: http://metacpan.org/release/Lingua-EN-Inflect-Phrase license: http://dev.perl.org/licenses/ repository: git://github.com/rkitover/lingua-en-inflect-phrase.git version: '0.20' x_authority: cpan:AVAR x_contributors: - 'Zak B. Elep ' x_serialization_backend: 'YAML::Tiny version 1.70' MANIFEST100644001750001750 44313245023070 20040 0ustar00rkitoverrkitover000000000000Lingua-EN-Inflect-Phrase-0.20# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.010. Changes LICENSE MANIFEST META.json META.yml Makefile.PL README dist.ini lib/Lingua/EN/Inflect/Phrase.pm t/00-compile.t t/author-pod-syntax.t t/basic.t t/bugs.t t/lib/TestPhrase.pm t/numbers.t t/schema-loader.t basic.t100644001750001750 170113245023070 20436 0ustar00rkitoverrkitover000000000000Lingua-EN-Inflect-Phrase-0.20/t#!perl use strict; use warnings; use Test::More; use Test::NoWarnings (); use lib 't/lib'; use TestPhrase 'test_phrase'; # noun conjunction noun test_phrase 'green egg and ham', 'green eggs and ham'; # noun preposition test_phrase 'email from', 'emails from'; test_phrase 'email to', 'emails to'; # noun preposition noun test_phrase 'mother in law', 'mothers in law'; test_phrase 'prisoner of war', 'prisoners of war'; # noun noun test_phrase 'book binding', 'book bindings'; test_phrase 'cable tie', 'cable ties'; # noun x2 test_phrase 'book book', 'book books'; # noun verb test_phrase 'station visited', 'stations visited'; # adjective noun that's the same singular and plural test_phrase 'swedish fish', 'swedish fish'; # fallback test_phrase 'green', 'greens'; # RT#118767 test_phrase 'functionality', 'functionalities'; test_phrase 'Functionality', 'Functionalities'; Test::NoWarnings::had_no_warnings; done_testing; # vim:et sts=2 sw=2 tw=0: META.json100644001750001750 447713245023070 20363 0ustar00rkitoverrkitover000000000000Lingua-EN-Inflect-Phrase-0.20{ "abstract" : "Inflect short English Phrases", "author" : [ "Rafael Kitover " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.010, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Lingua-EN-Inflect-Phrase", "no_index" : { "directory" : [ "t" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0", "perl" : "5.006" } }, "develop" : { "requires" : { "Test::Pod" : "1.41" } }, "runtime" : { "requires" : { "Exporter" : "0", "Lingua::EN::FindNumber" : "0", "Lingua::EN::Inflect" : "0", "Lingua::EN::Inflect::Number" : "0", "Lingua::EN::Number::IsOrdinal" : "0", "Lingua::EN::Tagger" : "0", "perl" : "5.006", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "File::Spec" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "Test::More" : "0", "Test::NoWarnings" : "0", "lib" : "0", "perl" : "5.006" } } }, "provides" : { "Lingua::EN::Inflect::Phrase" : { "file" : "lib/Lingua/EN/Inflect/Phrase.pm", "version" : "0.20" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "bug-Lingua-EN-Inflect-Phrase@rt.cpan.org", "web" : "https://rt.cpan.org/Public/Dist/Display.html?Name=Lingua-EN-Inflect-Phrase" }, "homepage" : "http://metacpan.org/release/Lingua-EN-Inflect-Phrase", "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "type" : "git", "url" : "git://github.com/rkitover/lingua-en-inflect-phrase.git", "web" : "http://github.com/rkitover/lingua-en-inflect-phrase" } }, "version" : "0.20", "x_authority" : "cpan:AVAR", "x_contributors" : [ "Zak B. Elep " ], "x_serialization_backend" : "Cpanel::JSON::XS version 3.0239" } numbers.t100644001750001750 632413245023070 21036 0ustar00rkitoverrkitover000000000000Lingua-EN-Inflect-Phrase-0.20/t#!perl use strict; use warnings; use Test::More; use Test::NoWarnings (); use lib 't/lib'; use TestPhrase 'test_phrase'; # number noun test_phrase '0 eggs', '0 eggs'; test_phrase '1 egg', '1 egg'; test_phrase '2 eggs', '2 eggs'; test_phrase '1.5 joules', '1.5 joules'; test_phrase '2.4E4 electron-volts', '2.4E4 electron-volts'; # all other combinations with numbers test_phrase '1 email from', '1 email from'; test_phrase '2 emails from', '2 emails from'; test_phrase '1 mother in law', '1 mother in law'; test_phrase '2 mothers in law', '2 mothers in law'; test_phrase '1 book binding', '1 book binding'; test_phrase '2 book bindings', '2 book bindings'; test_phrase '1 book book', '1 book book'; test_phrase '2 book books', '2 book books'; test_phrase '1 station visited', '1 station visited'; test_phrase '2 stations visited', '2 stations visited'; test_phrase '1 swedish fish', '1 swedish fish'; test_phrase '2 swedish fish', '2 swedish fish'; test_phrase '1 green', '1 green'; test_phrase '2 greens', '2 greens'; # ASCII fractions test_phrase '1 1/2 joules', '1 1/2 joules'; test_phrase '1 and 1/2 joules', '1 and 1/2 joules'; test_phrase '1 and a half joules', '1 and a half joules'; test_phrase '1 and one half joules', '1 and one half joules'; test_phrase 'one and one half joules', 'one and one half joules'; # TODO Unicode fractions # numbers as words test_phrase 'zero eggs', 'zero eggs'; test_phrase 'one egg', 'one egg'; test_phrase 'the one egg', 'the one egg'; test_phrase 'two eggs', 'two eggs'; test_phrase 'the two eggs', 'the two eggs'; test_phrase 'the twenty two eggs', 'the twenty two eggs'; test_phrase 'one email from', 'one email from'; test_phrase 'the one email from', 'the one email from'; test_phrase 'two emails from', 'two emails from'; test_phrase 'one mother in law', 'one mother in law'; test_phrase 'the one mother in law', 'the one mother in law'; test_phrase 'two mothers in law', 'two mothers in law'; test_phrase 'one book binding', 'one book binding'; test_phrase 'the one book binding', 'the one book binding'; test_phrase 'two book bindings', 'two book bindings'; test_phrase 'one book book', 'one book book'; test_phrase 'the one book book', 'the one book book'; test_phrase 'two book books', 'two book books'; test_phrase 'one station visited', 'one station visited'; test_phrase 'the one station visited', 'the one station visited'; test_phrase 'two stations visited', 'two stations visited'; test_phrase 'one swedish fish', 'one swedish fish'; test_phrase 'the one swedish fish', 'the one swedish fish'; test_phrase 'two swedish fish', 'two swedish fish'; test_phrase 'one green', 'one green'; test_phrase 'the one green', 'the one green'; test_phrase 'two greens', 'two greens'; # numbers by themselves test_phrase 'the 1', 'the 1s'; test_phrase 'the 2', 'the 2s'; test_phrase '1', '1s'; test_phrase '2', '2s'; test_phrase 'the one', 'the ones'; test_phrase 'the two', 'the twos'; test_phrase 'one', 'ones'; test_phrase 'two', 'twos'; # ordinal numbers test_phrase '1st release', '1st releases'; test_phrase 'first release', 'first releases'; test_phrase 'second trip', 'second trips'; test_phrase 'twenty third egg', 'twenty third eggs'; test_phrase '2nd car', '2nd cars'; Test::NoWarnings::had_no_warnings; done_testing; Makefile.PL100644001750001750 324213245023070 20701 0ustar00rkitoverrkitover000000000000Lingua-EN-Inflect-Phrase-0.20# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.010. use strict; use warnings; use 5.006; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "Inflect short English Phrases", "AUTHOR" => "Rafael Kitover ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "Lingua-EN-Inflect-Phrase", "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.006", "NAME" => "Lingua::EN::Inflect::Phrase", "PREREQ_PM" => { "Exporter" => 0, "Lingua::EN::FindNumber" => 0, "Lingua::EN::Inflect" => 0, "Lingua::EN::Inflect::Number" => 0, "Lingua::EN::Number::IsOrdinal" => 0, "Lingua::EN::Tagger" => 0, "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "File::Spec" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, "Test::More" => 0, "Test::NoWarnings" => 0, "lib" => 0 }, "VERSION" => "0.20", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Exporter" => 0, "File::Spec" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, "Lingua::EN::FindNumber" => 0, "Lingua::EN::Inflect" => 0, "Lingua::EN::Inflect::Number" => 0, "Lingua::EN::Number::IsOrdinal" => 0, "Lingua::EN::Tagger" => 0, "Test::More" => 0, "Test::NoWarnings" => 0, "lib" => 0, "strict" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); 00-compile.t100644001750001750 265113245023070 21227 0ustar00rkitoverrkitover000000000000Lingua-EN-Inflect-Phrase-0.20/tuse 5.006; use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.058 use Test::More; plan tests => 1 + ($ENV{AUTHOR_TESTING} ? 1 : 0); my @module_files = ( 'Lingua/EN/Inflect/Phrase.pm' ); # no fake home requested my @switches = ( -d 'blib' ? '-Mblib' : '-Ilib', ); use File::Spec; use IPC::Open3; use IO::Handle; open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!"; my @warnings; for my $lib (@module_files) { # see L my $stderr = IO::Handle->new; diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} } $^X, @switches, '-e', "require q[$lib]")) if $ENV{PERL_COMPILE_TEST_DEBUG}; my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]"); binmode $stderr, ':crlf' if $^O eq 'MSWin32'; my @_warnings = <$stderr>; waitpid($pid, 0); is($?, 0, "$lib loaded ok"); shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/ and not eval { +require blib; blib->VERSION('1.01') }; if (@_warnings) { warn @_warnings; push @warnings, @_warnings; } } is(scalar(@warnings), 0, 'no warnings found') or diag 'got warnings: ', ( Test::More->can('explain') ? Test::More::explain(\@warnings) : join("\n", '', @warnings) ) if $ENV{AUTHOR_TESTING}; schema-loader.t100644001750001750 53613245023070 22046 0ustar00rkitoverrkitover000000000000Lingua-EN-Inflect-Phrase-0.20/tuse strict; use warnings; use Test::More; use Test::NoWarnings (); use lib 't/lib'; use TestPhrase 'test_phrase'; # some tests for odd cases in DBIx::Class::Schema::Loader test_phrase 'loader test25 from', 'loader test25s from'; test_phrase 'belongs to', 'belongs to'; Test::NoWarnings::had_no_warnings; done_testing; # vim:et sts=2 sw=2 tw=0: lib000755001750001750 013245023070 17577 5ustar00rkitoverrkitover000000000000Lingua-EN-Inflect-Phrase-0.20/tTestPhrase.pm100644001750001750 134713245023070 22364 0ustar00rkitoverrkitover000000000000Lingua-EN-Inflect-Phrase-0.20/t/libpackage TestPhrase; use strict; use warnings; use Exporter 'import'; use Test::More; use Lingua::EN::Inflect::Phrase qw/to_PL to_S/; our @EXPORT_OK = 'test_phrase'; sub test_phrase { my ($singular, $plural, $addendum) = @_; if ($addendum) { $addendum = ": $addendum"; } else { $addendum = ''; } local $Test::Builder::Level = $Test::Builder::Level + 1; is to_PL($singular), $plural, "'$singular' pluralizes to '$plural'$addendum"; is to_S($plural), $singular, "'$plural' singularizes to '$singular'$addendum"; is to_PL($plural), $plural, "'$plural' unchanged when pluralized$addendum"; is to_S($singular), $singular, "'$singular' unchanged when singularized$addendum"; } 1; # vim:et sts=2 sw=2 tw=0: author-pod-syntax.t100644001750001750 45413245023070 22747 0ustar00rkitoverrkitover000000000000Lingua-EN-Inflect-Phrase-0.20/t#!perl BEGIN { unless ($ENV{AUTHOR_TESTING}) { print qq{1..0 # SKIP these tests are for testing by the author\n}; exit } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); Inflect000755001750001750 013245023070 22441 5ustar00rkitoverrkitover000000000000Lingua-EN-Inflect-Phrase-0.20/lib/Lingua/ENPhrase.pm100644001750001750 2442313245023070 24406 0ustar00rkitoverrkitover000000000000Lingua-EN-Inflect-Phrase-0.20/lib/Lingua/EN/Inflectpackage Lingua::EN::Inflect::Phrase; our $AUTHORITY = 'cpan:AVAR'; $Lingua::EN::Inflect::Phrase::VERSION = '0.20'; use strict; use warnings; use Exporter 'import'; use Lingua::EN::Inflect; use Lingua::EN::Inflect::Number; use Lingua::EN::Tagger; use Lingua::EN::FindNumber '$number_re'; use Lingua::EN::Number::IsOrdinal 'is_ordinal'; =head1 NAME Lingua::EN::Inflect::Phrase - Inflect short English Phrases =cut =head1 SYNOPSIS use Lingua::EN::Inflect::Phrase; use Test::More tests => 2; my $plural = Lingua::EN::Inflect::Phrase::to_PL('green egg and ham'); is $plural, 'green eggs and ham'; my $singular = Lingua::EN::Inflect::Phrase::to_S('green eggs and ham'); is $singular, 'green egg and ham'; =head1 DESCRIPTION Attempts to pluralize or singularize short English phrases. Does not throw exceptions at present, if you attempt to pluralize an already pluralized phrase, it will leave it unchanged (and vice versa.) The behavior of this module is subject to change as I tweak the heuristics, as some things get fixed others might regress. The processing of natural language is a messy business. If it doesn't work, please email or submit to RT the example you tried, and I'll try to fix it. =head1 OPTIONS By default, this module prefers to treat words as nouns (sometimes words can be interpreted as a verb or a noun without context.) This is better for things such as database table/column names, which is what this module is primarily for. This behavior can be switched with the variable C<$prefer_nouns>. The default is C<1>. For example: { local $Lingua::EN::Inflect::Phrase::prefer_nouns = 0; is Lingua::EN::Inflect::Phrase::to_S('sources split'), 'source splits'; } { local $Lingua::EN::Inflect::Phrase::prefer_nouns = 1; is Lingua::EN::Inflect::Phrase::to_S('source splits'), 'source split'; } =head1 OPTIONAL EXPORTS L, L =cut our @EXPORT_OK = qw/to_PL to_S/; =head1 SUBROUTINES =cut our $prefer_nouns = 1; my $MAYBE_NOUN = qr{(\S+)/(?:NN[PS]?|CD|JJ)\b}; my $MAYBE_NOUN_TAG = qr{/(?:NN[PS]?|CD|JJ)\b}; my $NOUN_OR_VERB = qr{(\S+)/(?:NN[PS]?|CD|JJ|VB[A-Z]?)\b}; my $NOUN_OR_VERB_TAG = qr{/(?:NN[PS]?|CD|JJ|VB[A-Z]?)\b}; my $VERB_TAG = qr{/VB[A-z]?\b}; my $PREPOSITION_OR_CONJUNCTION_TAG = qr{/(?:CC|IN)\b}; my $tagger; sub _inflect_noun { my ($noun, $want_plural, $is_plural) = @_; my $want_singular = not $want_plural; $is_plural = Lingua::EN::Inflect::Number::number($noun) ne 's' unless defined $is_plural; # fix "people" and "heroes" and a few others if ($noun =~ /^(?:people|person)\z/i) { return $want_singular ? 'person' : 'people'; } elsif ($noun =~ /^hero(?:es)?\z/i) { return $want_singular ? 'hero' : 'heroes'; } elsif ($want_singular && lc($noun) eq 'aliases') { return 'alias'; } elsif ($want_singular && lc($noun) eq 'statuses') { return 'status'; } elsif (lc($noun) eq 'belongs') { return undef; } elsif ($want_plural && lc($noun) eq 'two') { return 'twos'; } elsif ($noun =~ /^[A-Z].+ity\z/) { return $want_plural ? ucfirst(Lingua::EN::Inflect::Number::to_PL(lc($noun))) : $noun; } elsif ($noun =~ /^[A-Z].+ities\z/) { return $want_plural ? $noun : ucfirst(Lingua::EN::Inflect::Number::to_S(lc($noun))); } if ($want_plural && (not $is_plural)) { return Lingua::EN::Inflect::Number::to_PL($noun); } elsif ($want_singular && $is_plural) { return Lingua::EN::Inflect::Number::to_S($noun); } return undef; } sub _inflect { my ($phrase, $want_plural) = @_; my $want_singular = not $want_plural; # 'a' inflects to 'some', special-case it here if ($phrase eq 'a') { return $want_singular ? $phrase : 'as'; } # Do not tag initial number, if any. # Regex is from perldoc -q 'is a number'. my ($det, $number, $pad, $rest) = $phrase =~ m{^(\s*\S+/DET)?(\s*(?:[+-]?)(?=\d|\.\d)\d*(?:\.\d*)?(?:[Ee](?:[+-]?\d+))?)(\s*)(.*)$}; $_ ||= '' for $det, $pad, $rest; my $tagged; $tagger ||= Lingua::EN::Tagger->new; # force plural unless number is '1' if ((grep { defined && length } ($number, $pad, $rest)) == 3) { my $tagged_rest = $tagger->get_readable($rest); $tagged = $det . $number . $pad . $tagged_rest; if ($number =~ /^\s*1(?:\.0*[Ee]?0*)?\z/ && $tagged_rest !~ m{^(?:\S+/CC|\d)}) { $want_plural = 0; $want_singular = 1; } else { $want_plural = 1; $want_singular = 0; } } else { $tagged = $tagger->get_readable($phrase); } # check for phrases like "one something" and force singular, # or "one and a half ..." and force plural if (my ($det, $number, $conj, $and_zero, $pad, $rest) = $tagged =~ m{ ^ (\s* \S+/DET)? (\s* (?:one|single))/(?:JJ|NN|CD)\b (\s*\S+/CC\b)? (?:(\s* (?:no|zero))/(?:DET|CD))? (\s*) (.*) }x) { $_ ||= '' for $det, $conj, $and_zero, $pad, $rest; $tagged = $det . $number . $conj . $and_zero . $pad . $rest; if (length $conj && (not $and_zero)) { $want_plural = 1; $want_singular = 0; } elsif (length $rest) { $want_plural = 0; $want_singular = 1; } } # handle other numbers as words at the start of the phrase # using Lingua::EN::FindNumber elsif ($tagged =~ m{^\s*(?:(\S+)/DET)?} && (substr $phrase, $+[1]||0) =~ /^\s*$number_re/) { $number = (sort { length $a <=> length $b } map $_||'', ($1, $2, $3, $4, $5))[-1]; if (not is_ordinal($number)) { my $tagged_number_re; foreach my $num_elem (split /\s+/, $number) { $tagged_number_re .= "\Q$num_elem\E/[A-Z]+\\s*"; } my $tagged_number; ($tagged_number, $pad, $rest) = $tagged =~ m/($tagged_number_re)(\s*)(.*)/; my @tagged_number_pos = ($-[1], $+[1]); if (length $rest) { substr($tagged, $tagged_number_pos[0], ($tagged_number_pos[1] - $tagged_number_pos[0])) = $number; $want_plural = 1; $want_singular = 0; } } } my ($noun, $tag); # last noun (or verb that could be a noun) before a preposition/conjunction # or last noun/verb if ( (($noun) = $tagged =~ m|${MAYBE_NOUN} (?! .* ${MAYBE_NOUN_TAG} .* ${PREPOSITION_OR_CONJUNCTION_TAG}) .* ${PREPOSITION_OR_CONJUNCTION_TAG}|x) or (($noun) = $tagged =~ m|${MAYBE_NOUN} (?!.*${MAYBE_NOUN_TAG})|x) or (($noun) = $tagged =~ m|${NOUN_OR_VERB} (?!.*${NOUN_OR_VERB_TAG} .* ${PREPOSITION_OR_CONJUNCTION_TAG}) .* ${PREPOSITION_OR_CONJUNCTION_TAG}|x) or (($noun) = $tagged =~ m|${NOUN_OR_VERB} (?! .* ${NOUN_OR_VERB_TAG})|x)) { my @pos = ($-[1], $+[1]); my $inflected_noun; $inflected_noun = _inflect_noun($noun, $want_plural); # check if there is a verb following the noun # the verb either needs to be pluarlized or be taken as the noun, # depending on the value of $prefer_nouns my ($verb) = substr($tagged, $pos[1]) =~ m|^/[A-Z]+\s+(\S+)${VERB_TAG}|; my @verb_pos = map $pos[1] + $_, grep defined, ($-[1], $+[1]); # the verb may be tagged as a noun unless singularized (pluralized as a noun.) if ((not $verb) && (not $prefer_nouns) && $tagger->get_readable(_inflect_noun($noun, 1, 0)) =~ $VERB_TAG) { # find the preceding noun if (my ($preceding_noun) = substr($tagged, 0, $pos[0]) =~ m|${MAYBE_NOUN}\s*\z|) { my @preceding_noun_pos = ($-[1], $+[1]); $verb = $noun; @verb_pos = @pos; $noun = $preceding_noun; @pos = @preceding_noun_pos; $inflected_noun = _inflect_noun($noun, $want_plural); } } if ($verb) { my $plural_verb = Lingua::EN::Inflect::PL_V($verb); if ($prefer_nouns) { if ($tagger->get_readable($plural_verb) =~ $MAYBE_NOUN || ( # noun singular verb plural should be handled as noun noun, unless something follows it, # and only for "VB" not "VBZ" or "VBN" $verb eq $plural_verb && $tagger->get_readable(_inflect_noun($verb, 1)) =~ $MAYBE_NOUN && substr($tagged, $verb_pos[1]) =~ m{^\s*/VB\s*$} )) { $inflected_noun = _inflect_noun($verb, $want_plural); @pos = @verb_pos; } } elsif ($inflected_noun) { if ($want_plural) { substr($tagged, $verb_pos[0], ($verb_pos[1] - $verb_pos[0])) = $plural_verb; } elsif ($want_singular) { # to singularize a verb we pluralize it as a noun my $singular_verb = _inflect_noun($verb, 1, 0); substr($tagged, $verb_pos[0], ($verb_pos[1] - $verb_pos[0])) = $singular_verb; } } } substr($tagged, $pos[0], ($pos[1] - $pos[0])) = $inflected_noun if $inflected_noun; ($phrase = $tagged) =~ s{/[A-Z]+}{}g; } # fallback else { my $number = Lingua::EN::Inflect::Number::number($phrase); if ($want_plural && $number ne 'p') { return Lingua::EN::Inflect::Number::to_PL($phrase); } elsif ($want_singular && $number ne 's') { return Lingua::EN::Inflect::Number::to_S($phrase); } } return $phrase; } =head2 to_PL Attempts to pluralizes a phrase unless already plural. =cut sub to_PL { return _inflect(shift, 1); } =head2 to_S Attempts to singularize a phrase unless already singular. =cut sub to_S { return _inflect(shift, 0); } =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 REPOSITORY git clone git://github.com/rkitover/lingua-en-inflect-phrase.git lingua-en-inflect-phrase =head1 SEE ALSO L, L, L =head1 AUTHOR rkitover: Rafael Kitover =head1 CONTRIBUTORS zakame: Zak B. Elep =head1 LICENSE AND COPYRIGHT Copyright (c) 2018 Rafael Kitover (rkitover@cpan.org). This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. =cut 1; # vim:et sts=2 sw=2 tw=0: