From 5ca1b61ad2659177690cbde2cf7675f9c0d50491 Mon Sep 17 00:00:00 2001 From: Jeff Veit Date: Tue, 20 Nov 2018 00:41:47 +0000 Subject: [PATCH] Added the Porter Stemmer module to improve searches. This doesn't deal with some Englishisms, for instance -ise, because the algorithm works best on American English, but it's still better than without it, and the Search API Synonym module helps with this. --- web/modules/contrib/porterstemmer/INSTALL.txt | 34 + web/modules/contrib/porterstemmer/LICENSE.txt | 339 + web/modules/contrib/porterstemmer/README.txt | 50 + .../porterstemmer/porterstemmer.info.yml | 13 + .../porterstemmer/porterstemmer.module | 98 + .../contrib/porterstemmer/src/Porter2.php | 623 + .../porterstemmer/src/Tests/LangCodeTest.php | 160 + .../tests/src/Unit/Porter2Pecl1.php | 47 + .../tests/src/Unit/Porter2Pecl2.php | 47 + .../tests/src/Unit/Porter2Pecl3.php | 47 + .../tests/src/Unit/Porter2Pecl4.php | 47 + .../tests/src/Unit/Porter2Pecl5.php | 47 + .../tests/src/Unit/Porter2Pecl6.php | 47 + .../tests/src/Unit/Porter2Test1.php | 43 + .../tests/src/Unit/Porter2Test2.php | 43 + .../tests/src/Unit/Porter2Test3.php | 43 + .../tests/src/Unit/Porter2Test4.php | 43 + .../tests/src/Unit/Porter2Test5.php | 43 + .../tests/src/Unit/Porter2Test6.php | 43 + .../tests/src/Unit/PorterPeclBase.php | 31 + .../tests/src/Unit/TestItemsTrait.php | 53 + .../tests/src/Unit/testwords.txt | 29410 ++++++++++++++++ 22 files changed, 31351 insertions(+) create mode 100644 web/modules/contrib/porterstemmer/INSTALL.txt create mode 100644 web/modules/contrib/porterstemmer/LICENSE.txt create mode 100644 web/modules/contrib/porterstemmer/README.txt create mode 100644 web/modules/contrib/porterstemmer/porterstemmer.info.yml create mode 100644 web/modules/contrib/porterstemmer/porterstemmer.module create mode 100644 web/modules/contrib/porterstemmer/src/Porter2.php create mode 100644 web/modules/contrib/porterstemmer/src/Tests/LangCodeTest.php create mode 100644 web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Pecl1.php create mode 100644 web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Pecl2.php create mode 100644 web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Pecl3.php create mode 100644 web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Pecl4.php create mode 100644 web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Pecl5.php create mode 100644 web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Pecl6.php create mode 100644 web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Test1.php create mode 100644 web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Test2.php create mode 100644 web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Test3.php create mode 100644 web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Test4.php create mode 100644 web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Test5.php create mode 100644 web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Test6.php create mode 100644 web/modules/contrib/porterstemmer/tests/src/Unit/PorterPeclBase.php create mode 100644 web/modules/contrib/porterstemmer/tests/src/Unit/TestItemsTrait.php create mode 100644 web/modules/contrib/porterstemmer/tests/src/Unit/testwords.txt diff --git a/web/modules/contrib/porterstemmer/INSTALL.txt b/web/modules/contrib/porterstemmer/INSTALL.txt new file mode 100644 index 000000000..984fbb67b --- /dev/null +++ b/web/modules/contrib/porterstemmer/INSTALL.txt @@ -0,0 +1,34 @@ +For general information about this module, check the README.txt file. + +Installation +------------ + +1. Unzip the files, and upload them as a subdirectory of the +modules/ directory of your Drupal installation (or the +location you normally use for contributed modules). + +2. Go to 'Manage > Extend', and enable the Porter Stemmer module. + +3. Go to 'Manage > Configuration > Search pages' +and click 'Re-index site'. You should do this step whenever you upgrade to a +new version of the Porter Stemmer module, so that the search index is +rebuilt with any changes to the stemming algorithm. + +4. Ensure that cron has run at least once, to build the search +index. On larger sites, it may take several cron runs to complete the +search index. You can check progress on the Search settings page, and +you can run cron manually by visiting 'Administer > Reports > Status report', +and clicking on 'Run cron manually'. + +5. This module will use the PECL "stem" library for PHP, if it is installed +on your server. If you have full administrative/root access to your server, and +are comfortable with Apache/PHP configuration and system administration, you +can install this library by following the instructions at: + http://us3.php.net/manual/en/install.pecl.php +Once the library is installed, you will need to add a line to your php.ini +file to enable the module: + extension=stem.so +If the PECL "stem" library is not available, the module uses a PHP +implementation of the stemming algorithm. The output is identical. +More information about the PECL "stem" library: + http://pecl.php.net/package/stem diff --git a/web/modules/contrib/porterstemmer/LICENSE.txt b/web/modules/contrib/porterstemmer/LICENSE.txt new file mode 100644 index 000000000..d159169d1 --- /dev/null +++ b/web/modules/contrib/porterstemmer/LICENSE.txt @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, 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 licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU 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. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), 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 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 show them these terms so they know 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. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + 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 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 derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 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 License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +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. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary 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 + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 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 Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing 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 for copying, distributing or modifying +the Program or works based on it. + + 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. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. 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 this 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 +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. 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 + + 11. 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. + + 12. 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 + + 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 the public, 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) + + 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 2 of the License, 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) year 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 is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/web/modules/contrib/porterstemmer/README.txt b/web/modules/contrib/porterstemmer/README.txt new file mode 100644 index 000000000..e6c018f3b --- /dev/null +++ b/web/modules/contrib/porterstemmer/README.txt @@ -0,0 +1,50 @@ + +GENERAL INFORMATION +------------------- + +This module implements the Porter-Stemmer algorithm, version 2, to improve +English-language searching with the Drupal built-in Search module. Information +about the algorithm can be found at +http://snowball.tartarus.org/algorithms/english/stemmer.html + +Stemming reduces a word to its basic root or stem (e.g. 'blogging' to 'blog') so +that variations on a word ('blogs', 'blogger', 'blogging', 'blog') are +considered equivalent when searching. This generally results in more relevant +results. + +Note that a few parts of the Porter Stemmer algorithm work better for American +English than British English, so some British spellings will not be stemmed +correctly. + +This module will use the PECL "stem" library's implementation of the Porter +Stemmer algorithm, if it is installed on your server. If the PECL "stem" library +is not available, the module uses its own PHP implementation of the +algorithm. The output is the same in either case. More information about the +PECL "stem" library: http://pecl.php.net/package/stem + + +INSTALLATION +------------ + +See the INSTALL.txt file for installation instructions. + + +TESTING +------- + +The Porter Stemmer module includes tests for the stemming algorithm and +functionality. If you would like to run the tests, enable the core Testing +module, and then run the tests following instructions on +https://www.drupal.org/docs/8/phpunit/running-phpunit-tests. Commands below: + +cd core +../vendor/bin/phpunit --group porterstemmer + + +Each test for the Porter Stemmer module includes approximately +5000 individual word stemming tests (which test the module against a standard +word list). + +Tests are provided both for the internal algorithm and the PECL library. + +There is also a functional test for integration with Drupal search. diff --git a/web/modules/contrib/porterstemmer/porterstemmer.info.yml b/web/modules/contrib/porterstemmer/porterstemmer.info.yml new file mode 100644 index 000000000..e4e336db1 --- /dev/null +++ b/web/modules/contrib/porterstemmer/porterstemmer.info.yml @@ -0,0 +1,13 @@ +name: Porter-Stemmer +type: module +description: Improves American English language searching by simplifying related words to their root (conjugations, plurals, ...). +# core: 8.x +package: Search +dependencies: + - search + +# Information added by Drupal.org packaging script on 2016-11-18 +version: '8.x-1.0' +core: '8.x' +project: 'porterstemmer' +datestamp: 1479503654 diff --git a/web/modules/contrib/porterstemmer/porterstemmer.module b/web/modules/contrib/porterstemmer/porterstemmer.module new file mode 100644 index 000000000..0a886af10 --- /dev/null +++ b/web/modules/contrib/porterstemmer/porterstemmer.module @@ -0,0 +1,98 @@ +' . t('About') . ''; + $output .= '

' . t('Improves American English language searching by simplifying related words to their root (conjugations, plurals, ...).') . '

'; + return $output; + + default: + } +} + +/** + * Implements hook_search_preprocess(). + * + * Stems the words in $text, using the Porter 2 (English) stemming algorithm. + */ +function porterstemmer_search_preprocess($text, $langcode = NULL) { + // If the language is not set, get it from the language manager. + if (!isset($langcode)) { + $langcode = \Drupal::languageManager()->getCurrentLanguage()->getId(); + } + + if ($langcode == 'en') { + // Convert text to lower case, and replace special apostrophes with regular + // apostrophes. + $text = strtolower(str_replace('’', "'", $text)); + + // Split into words. + $words = preg_split('/(' . PORTERSTEMMER_BOUNDARY . '+)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE); + + if (!count($words)) { + return $text; + } + + $has_pecl_stem = _porterstemmer_pecl_loaded(); + + // Process each word, skipping delimiters. + $isword = !preg_match('/' . PORTERSTEMMER_BOUNDARY . '/', $words[0]); + foreach ($words as $k => $word) { + if ($isword) { + if ($has_pecl_stem) { + $words[$k] = stem_english($word); + } + else { + $words[$k] = Porter2::stem($word); + } + } + $isword = !$isword; + } + + // Put it all back together (note that delimiters are in $words). + return implode('', $words); + } + + return $text; +} + +/** + * Checks to see if the PECL stem extension has been loaded. + * + * @return bool + * TRUE if the stem_english() function from the PECL stem library can be + * used, FALSE if not. + */ +function _porterstemmer_pecl_loaded() { + static $has_pecl_stem = FALSE; + static $already_checked = FALSE; + + if ($already_checked) { + return $has_pecl_stem; + } + + $has_pecl_stem = extension_loaded('stem') && function_exists('stem_english'); + $already_checked = TRUE; + return $has_pecl_stem; +} diff --git a/web/modules/contrib/porterstemmer/src/Porter2.php b/web/modules/contrib/porterstemmer/src/Porter2.php new file mode 100644 index 000000000..f26937ca7 --- /dev/null +++ b/web/modules/contrib/porterstemmer/src/Porter2.php @@ -0,0 +1,623 @@ + 'ski', + 'skies' => 'sky', + 'dying' => 'die', + 'lying' => 'lie', + 'tying' => 'tie', + 'idly' => 'idl', + 'gently' => 'gentl', + 'ugly' => 'ugli', + 'early' => 'earli', + 'only' => 'onli', + 'singly' => 'singl', + 'sky' => 'sky', + 'news' => 'news', + 'howe' => 'howe', + 'atlas' => 'atlas', + 'cosmos' => 'cosmos', + 'bias' => 'bias', + 'andes' => 'andes', + ); + + // Process exceptions. + if (isset($exceptions[$word])) { + $word = $exceptions[$word]; + } + elseif (strlen($word) > 2) { + // Only execute algorithm on words that are longer than two letters. + $word = self::prepare($word); + $word = self::step0($word); + $word = self::step1a($word); + $word = self::step1b($word); + $word = self::step1c($word); + $word = self::step2($word); + $word = self::step3($word); + $word = self::step4($word); + $word = self::step5($word); + } + return strtolower($word); + } + + /** + * Set initial y, or y after a vowel, to Y. + * + * @param string $word + * The word to stem. + * + * @return string $word + * The prepared word. + */ + protected static function prepare($word) { + $inc = 0; + if (strpos($word, "'") === 0) { + $word = substr($word, 1); + } + while ($inc <= strlen($word)) { + if (substr($word, $inc, 1) === 'y' && ($inc == 0 || self::isVowel($inc - 1, $word))) { + $word = substr_replace($word, 'Y', $inc, 1); + } + $inc++; + } + return $word; + } + + /** + * Search for the longest among the "s" suffixes and removes it. + * + * @param string $word + * The word to stem. + * + * @return string $word + * The modified word. + */ + protected static function step0($word) { + $found = FALSE; + $checks = array("'s'", "'s", "'"); + foreach ($checks as $check) { + if (!$found && self::hasEnding($word, $check)) { + $word = self::removeEnding($word, $check); + $found = TRUE; + } + } + return $word; + } + + /** + * Handles various suffixes, of which the longest is replaced. + * + * @param string $word + * The word to stem. + * + * @return string $word + * The modified word. + */ + protected static function step1a($word) { + $found = FALSE; + if (self::hasEnding($word, 'sses')) { + $word = self::removeEnding($word, 'sses') . 'ss'; + $found = TRUE; + } + $checks = array('ied', 'ies'); + foreach ($checks as $check) { + if (!$found && self::hasEnding($word, $check)) { + // @todo: check order here. + $length = strlen($word); + $word = self::removeEnding($word, $check); + if ($length > 4) { + $word .= 'i'; + } + else { + $word .= 'ie'; + } + $found = TRUE; + } + } + if (self::hasEnding($word, 'us') || self::hasEnding($word, 'ss')) { + $found = TRUE; + } + // Delete if preceding word part has a vowel not immediately before the s. + if (!$found && self::hasEnding($word, 's') && self::containsVowel(substr($word, 0, -2))) { + $word = self::removeEnding($word, 's'); + } + return $word; + } + + /** + * Handles various suffixes, of which the longest is replaced. + * + * @param string $word + * The word to stem. + * + * @return string $word + * The modified word. + */ + protected static function step1b($word) { + $exceptions = array( + 'inning', + 'outing', + 'canning', + 'herring', + 'earring', + 'proceed', + 'exceed', + 'succeed', + ); + if (in_array($word, $exceptions)) { + return $word; + } + $checks = array('eedly', 'eed'); + foreach ($checks as $check) { + if (self::hasEnding($word, $check)) { + if (self::r($word, 1) !== strlen($word)) { + $word = self::removeEnding($word, $check) . 'ee'; + } + return $word; + } + } + $checks = array('ingly', 'edly', 'ing', 'ed'); + $second_endings = array('at', 'bl', 'iz'); + foreach ($checks as $check) { + // If the ending is present and the previous part contains a vowel. + if (self::hasEnding($word, $check) && self::containsVowel(substr($word, 0, -strlen($check)))) { + $word = self::removeEnding($word, $check); + foreach ($second_endings as $ending) { + if (self::hasEnding($word, $ending)) { + return $word . 'e'; + } + } + // If the word ends with a double, remove the last letter. + $double_removed = self::removeDoubles($word); + if ($double_removed != $word) { + $word = $double_removed; + } + elseif (self::isShort($word)) { + // If the word is short, add e (so hop -> hope). + $word .= 'e'; + } + return $word; + } + } + return $word; + } + + /** + * Replaces suffix y or Y with i if after non-vowel not @ word begin. + * + * @param string $word + * The word to stem. + * + * @return string $word + * The modified word. + */ + protected static function step1c($word) { + if ((self::hasEnding($word, 'y') || self::hasEnding($word, 'Y')) && strlen($word) > 2 && !(self::isVowel(strlen($word) - 2, $word))) { + $word = self::removeEnding($word, 'y'); + $word .= 'i'; + } + return $word; + } + + /** + * Implements step 2 of the Porter2 algorithm. + * + * @param string $word + * The word to stem. + * + * @return string $word + * The modified word. + */ + protected static function step2($word) { + $checks = array( + "ization" => "ize", + "iveness" => "ive", + "fulness" => "ful", + "ational" => "ate", + "ousness" => "ous", + "biliti" => "ble", + "tional" => "tion", + "lessli" => "less", + "fulli" => "ful", + "entli" => "ent", + "ation" => "ate", + "aliti" => "al", + "iviti" => "ive", + "ousli" => "ous", + "alism" => "al", + "abli" => "able", + "anci" => "ance", + "alli" => "al", + "izer" => "ize", + "enci" => "ence", + "ator" => "ate", + "bli" => "ble", + "ogi" => "og", + ); + foreach ($checks as $find => $replace) { + if (self::hasEnding($word, $find)) { + if (self::inR1($word, $find)) { + $word = self::removeEnding($word, $find) . $replace; + } + return $word; + } + } + if (self::hasEnding($word, 'li')) { + if (strlen($word) > 4 && self::validLi(self::charAt(-3, $word))) { + $word = self::removeEnding($word, 'li'); + } + } + return $word; + } + + /** + * Implements step 3 of the Porter2 algorithm. + * + * @param string $word + * The word to stem. + * + * @return string $word + * The modified word. + */ + protected static function step3($word) { + $checks = array( + 'ational' => 'ate', + 'tional' => 'tion', + 'alize' => 'al', + 'icate' => 'ic', + 'iciti' => 'ic', + 'ical' => 'ic', + 'ness' => '', + 'ful' => '', + ); + foreach ($checks as $find => $replace) { + if (self::hasEnding($word, $find)) { + if (self::inR1($word, $find)) { + $word = self::removeEnding($word, $find) . $replace; + } + return $word; + } + } + if (self::hasEnding($word, 'ative')) { + if (self::inR2($word, 'ative')) { + $word = self::removeEnding($word, 'ative'); + } + } + return $word; + } + + /** + * Implements step 4 of the Porter2 algorithm. + * + * @param string $word + * The word to stem. + * + * @return string $word + * The modified word. + */ + protected static function step4($word) { + $checks = array( + 'ement', + 'ment', + 'ance', + 'ence', + 'able', + 'ible', + 'ant', + 'ent', + 'ion', + 'ism', + 'ate', + 'iti', + 'ous', + 'ive', + 'ize', + 'al', + 'er', + 'ic', + ); + foreach ($checks as $check) { + // Among the suffixes, if found and in R2, delete. + if (self::hasEnding($word, $check)) { + if (self::inR2($word, $check)) { + if ($check !== 'ion' || in_array(self::charAt(-4, $word), array('s', 't'))) { + $word = self::removeEnding($word, $check); + } + } + return $word; + } + } + return $word; + } + + /** + * Implements step 5 of the Porter2 algorithm. + * + * @param string $word + * The word to stem. + * + * @return string $word + * The modified word. + */ + protected static function step5($word) { + if (self::hasEnding($word, 'e')) { + // Delete if in R2, or in R1 and not preceded by a short syllable. + if (self::inR2($word, 'e') || (self::inR1($word, 'e') && !self::isShortSyllable($word, strlen($word) - 3))) { + $word = self::removeEnding($word, 'e'); + } + return $word; + } + if (self::hasEnding($word, 'l')) { + // Delete if in R2 and preceded by l. + if (self::inR2($word, 'l') && self::charAt(-2, $word) == 'l') { + $word = self::removeEnding($word, 'l'); + } + } + return $word; + } + + /** + * Removes certain double consonants from the word's end. + * + * @param string $word + * The word to stem. + * + * @return string $word + * The modified word. + */ + protected static function removeDoubles($word) { + $doubles = array('bb', 'dd', 'ff', 'gg', 'mm', 'nn', 'pp', 'rr', 'tt'); + foreach ($doubles as $double) { + if (substr($word, -2) == $double) { + $word = substr($word, 0, -1); + break; + } + } + return $word; + } + + /** + * Checks whether a character is a vowel. + * + * @param int $position + * The character's position. + * @param string $word + * The word in which to check. + * @param string[] $additional + * (optional) Additional characters that should count as vowels. + * + * @return bool + * TRUE if the character is a vowel, FALSE otherwise. + */ + protected static function isVowel($position, $word, $additional = array()) { + $vowels = array_merge(array('a', 'e', 'i', 'o', 'u', 'y'), $additional); + return in_array(self::charAt($position, $word), $vowels); + } + + /** + * Retrieves the character at the given position. + * + * @param int $position + * The 0-based index of the character. If a negative number is given, the + * position is counted from the end of the string. + * @param string $word + * The word from which to retrieve the character. + * + * @return string + * The character at the given position, or an empty string if the given + * position was illegal. + */ + protected static function charAt($position, $word) { + $length = strlen($word); + if (abs($position) >= $length) { + return ''; + } + if ($position < 0) { + $position += $length; + } + return $word[$position]; + } + + /** + * Determines whether the word ends in a "vowel-consonant" suffix. + * + * Unless the word is only two characters long, it also checks that the + * third-last character is neither "w", "x" nor "Y". + * + * @param int|null $position + * (optional) If given, do not check the end of the word, but the character + * at the given position, and the next one. + * + * @return bool + * TRUE if the word has the described suffix, FALSE otherwise. + */ + protected static function isShortSyllable($word, $position = NULL) { + if ($position === NULL) { + $position = strlen($word) - 2; + } + // A vowel at the beginning of the word followed by a non-vowel. + if ($position === 0) { + return self::isVowel(0, $word) && !self::isVowel(1, $word); + } + // Vowel followed by non-vowel other than w, x, Y and preceded by + // non-vowel. + $additional = array('w', 'x', 'Y'); + return !self::isVowel($position - 1, $word) && self::isVowel($position, $word) && !self::isVowel($position + 1, $word, $additional); + } + + /** + * Determines whether the word is short. + * + * A word is called short if it ends in a short syllable and if R1 is null. + * + * @return bool + * TRUE if the word is short, FALSE otherwise. + */ + protected static function isShort($word) { + return self::isShortSyllable($word) && self::r($word, 1) == strlen($word); + } + + /** + * Determines the start of a certain "R" region. + * + * R is a region after the first non-vowel following a vowel, or end of word. + * + * @param int $type + * (optional) 1 or 2. If 2, then calculate the R after the R1. + * + * @return int + * The R position. + */ + protected static function r($word, $type = 1) { + $inc = 1; + if ($type === 2) { + $inc = self::r($word, 1); + } + elseif (strlen($word) > 5) { + $prefix_5 = substr($word, 0, 5); + if ($prefix_5 === 'gener' || $prefix_5 === 'arsen') { + return 5; + } + if (strlen($word) > 5 && substr($word, 0, 6) === 'commun') { + return 6; + } + } + + while ($inc <= strlen($word)) { + if (!self::isVowel($inc, $word) && self::isVowel($inc - 1, $word)) { + $position = $inc; + break; + } + $inc++; + } + if (!isset($position)) { + $position = strlen($word); + } + else { + // We add one, as this is the position AFTER the first non-vowel. + $position++; + } + return $position; + } + + /** + * Checks whether the given string is contained in R1. + * + * @param string $string + * The string. + * + * @return bool + * TRUE if the string is in R1, FALSE otherwise. + */ + protected static function inR1($word, $string) { + $r1 = substr($word, self::r($word, 1)); + return strpos($r1, $string) !== FALSE; + } + + /** + * Checks whether the given string is contained in R2. + * + * @param string $string + * The string. + * + * @return bool + * TRUE if the string is in R2, FALSE otherwise. + */ + protected static function inR2($word, $string) { + $r2 = substr($word, self::r($word, 2)); + return strpos($r2, $string) !== FALSE; + } + + /** + * Checks whether the word ends with the given string. + * + * @param string $string + * The string. + * + * @return bool + * TRUE if the word ends with the given string, FALSE otherwise. + */ + protected static function hasEnding($word, $string) { + $length = strlen($string); + if ($length > strlen($word)) { + return FALSE; + } + return (substr_compare($word, $string, -1 * $length, $length) === 0); + } + + /** + * Removes a given string from the end of the current word. + * + * Does not check whether the ending is actually there. + * + * @param string $string + * The ending to remove. + */ + protected static function removeEnding($word, $string) { + return substr($word, 0, -strlen($string)); + } + + /** + * Checks whether the given string contains a vowel. + * + * @param string $string + * The string to check. + * + * @return bool + * TRUE if the string contains a vowel, FALSE otherwise. + */ + protected static function containsVowel($string) { + $inc = 0; + $return = FALSE; + while ($inc < strlen($string)) { + if (self::isVowel($inc, $string)) { + $return = TRUE; + break; + } + $inc++; + } + return $return; + } + + /** + * Checks whether the given string is a valid -li prefix. + * + * @param string $string + * The string to check. + * + * @return bool + * TRUE if the given string is a valid -li prefix, FALSE otherwise. + */ + protected static function validLi($string) { + return in_array($string, array( + 'c', + 'd', + 'e', + 'g', + 'h', + 'k', + 'm', + 'n', + 'r', + 't', + )); + } + +} diff --git a/web/modules/contrib/porterstemmer/src/Tests/LangCodeTest.php b/web/modules/contrib/porterstemmer/src/Tests/LangCodeTest.php new file mode 100644 index 000000000..9926d59f6 --- /dev/null +++ b/web/modules/contrib/porterstemmer/src/Tests/LangCodeTest.php @@ -0,0 +1,160 @@ + 'I walk through the streets, looking around for trouble.', + 'Second Page' => 'I walked home from work today.', + 'Third Page' => 'I am always walking everywhere.', + ); + + /** + * An array of search terms. + * + * @var string[] + */ + protected $searches = array( + 'walk', + 'walked', + 'walking', + ); + + /** + * An array of nodes created for testing purposes. + * + * @var \Drupal\node\NodeInterface[] + */ + protected $nodes; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + + $this->testUser = $this->drupalCreateUser(array( + 'search content', + 'access content', + 'administer nodes', + 'access site reports', + 'use advanced search', + 'administer languages', + 'access administration pages', + 'administer site configuration', + )); + $this->drupalLogin($this->testUser); + + // Add a new language. + ConfigurableLanguage::createFromLangcode('fr')->save(); + + // Make the body field translatable. The title is already translatable by + // definition. + $field_storage = FieldStorageConfig::loadByName('node', 'body'); + $field_storage->setTranslatable(TRUE); + $field_storage->save(); + + // Create EN language nodes. + foreach ($this->test_data as $title => $body) { + $info = array( + 'title' => $title . ' (EN)', + 'body' => array(array('value' => $body)), + 'type' => 'page', + 'langcode' => 'en', + ); + $this->nodes[$title] = $this->drupalCreateNode($info); + } + + // Create non-EN nodes. + foreach ($this->test_data as $title => $body) { + $info = array( + 'title' => $title . ' (FR)', + 'body' => array(array('value' => $body)), + 'type' => 'page', + 'langcode' => 'fr', + ); + $this->nodes[$title] = $this->drupalCreateNode($info); + } + + // Create language-unspecified nodes. + foreach ($this->test_data as $title => $body) { + $info = array( + 'title' => $title . ' (UND)', + 'body' => array(array('value' => $body)), + 'type' => 'page', + 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, + ); + $this->nodes[$title] = $this->drupalCreateNode($info); + } + + // Run cron to ensure the content is indexed. + $this->cronRun(); + $this->drupalGet('admin/reports/dblog'); + $this->assertText(t('Cron run completed'), 'Log shows cron run completed'); + } + + /** + * Test that search variations return English language results. + */ + protected function testStemSearching() { + + foreach ($this->searches as $search) { + $this->drupalPostForm('search/node', array('keys' => $search), t('Search')); + + // Verify that all English-language test node variants show up in results. + foreach ($this->test_data as $title => $body) { + $this->assertText($title . ' (EN)', format_string('Search for %search returns English-language node with body %body', array('%search' => $search, '%body' => $body))); + } + + // Check for results by language. + switch ($search) { + case 'walk': + $this->assertNoText('Second Page (FR)', format_string('Search for %search does not show stemmed non-English results.', array('%search' => $search))); + $this->assertNoText('Second Page (UND)', format_string('Search for %search does show stemmed language-unspecified results.', array('%search' => $search))); + break; + + case 'walked': + $this->assertNoText('Second Page (FR)', format_string('Search for %search does not show stemmed non-English results.', array('%search' => $search))); + $this->assertNoText('Second Page (UND)', format_string('Search for %search does not show stemmed language-unspecified results.', array('%search' => $search))); + break; + + case 'walking': + $this->assertText('First Page (FR)', format_string('Search for %search does show matching non-English results.', array('%search' => $search))); + $this->assertText('First Page (UND)', format_string('Search for %search does show matching language-unspecified results.', array('%search' => $search))); + break; + + } + } + } + +} diff --git a/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Pecl1.php b/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Pecl1.php new file mode 100644 index 000000000..719c47538 --- /dev/null +++ b/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Pecl1.php @@ -0,0 +1,47 @@ +has_pecl_stem) { + $this->assertEquals($stem, stem_english($word)); + } + else { + $this->assertTrue(TRUE, 'No PECL stem library found, Aborting test.'); + } + } + + /** + * Data provider for testStem(). + * + * @return array + * Nested arrays of values to check: + * - $word + * - $stem + */ + public function stemDataProvider() { + if ($this->has_pecl_stem) { + return $this->retrieveStemWords(0); + } + else { + return array(array('', '')); + } + } + +} diff --git a/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Pecl2.php b/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Pecl2.php new file mode 100644 index 000000000..b732593bf --- /dev/null +++ b/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Pecl2.php @@ -0,0 +1,47 @@ +has_pecl_stem) { + $this->assertEquals($stem, stem_english($word)); + } + else { + $this->assertTrue(TRUE, 'No PECL stem library found, Aborting test.'); + } + } + + /** + * Data provider for testStem(). + * + * @return array + * Nested arrays of values to check: + * - $word + * - $stem + */ + public function stemDataProvider() { + if ($this->has_pecl_stem) { + return $this->retrieveStemWords(5000); + } + else { + return array(array('', '')); + } + } + +} diff --git a/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Pecl3.php b/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Pecl3.php new file mode 100644 index 000000000..1a5412727 --- /dev/null +++ b/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Pecl3.php @@ -0,0 +1,47 @@ +has_pecl_stem) { + $this->assertEquals($stem, stem_english($word)); + } + else { + $this->assertTrue(TRUE, 'No PECL stem library found, Aborting test.'); + } + } + + /** + * Data provider for testStem(). + * + * @return array + * Nested arrays of values to check: + * - $word + * - $stem + */ + public function stemDataProvider() { + if ($this->has_pecl_stem) { + return $this->retrieveStemWords(10000); + } + else { + return array(array('', '')); + } + } + +} diff --git a/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Pecl4.php b/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Pecl4.php new file mode 100644 index 000000000..3299e6772 --- /dev/null +++ b/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Pecl4.php @@ -0,0 +1,47 @@ +has_pecl_stem) { + $this->assertEquals($stem, stem_english($word)); + } + else { + $this->assertTrue(TRUE, 'No PECL stem library found, Aborting test.'); + } + } + + /** + * Data provider for testStem(). + * + * @return array + * Nested arrays of values to check: + * - $word + * - $stem + */ + public function stemDataProvider() { + if ($this->has_pecl_stem) { + return $this->retrieveStemWords(15000); + } + else { + return array(array('', '')); + } + } + +} diff --git a/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Pecl5.php b/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Pecl5.php new file mode 100644 index 000000000..85c22c703 --- /dev/null +++ b/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Pecl5.php @@ -0,0 +1,47 @@ +has_pecl_stem) { + $this->assertEquals($stem, stem_english($word)); + } + else { + $this->assertTrue(TRUE, 'No PECL stem library found, Aborting test.'); + } + } + + /** + * Data provider for testStem(). + * + * @return array + * Nested arrays of values to check: + * - $word + * - $stem + */ + public function stemDataProvider() { + if ($this->has_pecl_stem) { + return $this->retrieveStemWords(20000); + } + else { + return array(array('', '')); + } + } + +} diff --git a/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Pecl6.php b/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Pecl6.php new file mode 100644 index 000000000..eb2421dc0 --- /dev/null +++ b/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Pecl6.php @@ -0,0 +1,47 @@ +has_pecl_stem) { + $this->assertEquals($stem, stem_english($word)); + } + else { + $this->assertTrue(TRUE, 'No PECL stem library found, Aborting test.'); + } + } + + /** + * Data provider for testStem(). + * + * @return array + * Nested arrays of values to check: + * - $word + * - $stem + */ + public function stemDataProvider() { + if ($this->has_pecl_stem) { + return $this->retrieveStemWords(25000); + } + else { + return array(array('', '')); + } + } + +} diff --git a/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Test1.php b/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Test1.php new file mode 100644 index 000000000..a48dbca8c --- /dev/null +++ b/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Test1.php @@ -0,0 +1,43 @@ +assertEquals($stem, Porter2::stem($word)); + } + + /** + * Data provider for testStem(). + * + * @return array + * Nested arrays of values to check: + * - $word + * - $stem + */ + public function stemDataProvider() { + return $this->retrieveStemWords(0, 5000); + } + +} diff --git a/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Test2.php b/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Test2.php new file mode 100644 index 000000000..6849446af --- /dev/null +++ b/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Test2.php @@ -0,0 +1,43 @@ +assertEquals($stem, Porter2::stem($word)); + } + + /** + * Data provider for testStem(). + * + * @return array + * Nested arrays of values to check: + * - $word + * - $stem + */ + public function stemDataProvider() { + return $this->retrieveStemWords(5000, 5000); + } + +} diff --git a/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Test3.php b/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Test3.php new file mode 100644 index 000000000..2cfcd29b3 --- /dev/null +++ b/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Test3.php @@ -0,0 +1,43 @@ +assertEquals($stem, Porter2::stem($word)); + } + + /** + * Data provider for testStem(). + * + * @return array + * Nested arrays of values to check: + * - $word + * - $stem + */ + public function stemDataProvider() { + return $this->retrieveStemWords(10000, 5000); + } + +} diff --git a/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Test4.php b/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Test4.php new file mode 100644 index 000000000..998aa3470 --- /dev/null +++ b/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Test4.php @@ -0,0 +1,43 @@ +assertEquals($stem, Porter2::stem($word)); + } + + /** + * Data provider for testStem(). + * + * @return array + * Nested arrays of values to check: + * - $word + * - $stem + */ + public function stemDataProvider() { + return $this->retrieveStemWords(15000, 5000); + } + +} diff --git a/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Test5.php b/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Test5.php new file mode 100644 index 000000000..99eb3ac86 --- /dev/null +++ b/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Test5.php @@ -0,0 +1,43 @@ +assertEquals($stem, Porter2::stem($word)); + } + + /** + * Data provider for testStem(). + * + * @return array + * Nested arrays of values to check: + * - $word + * - $stem + */ + public function stemDataProvider() { + return $this->retrieveStemWords(20000, 5000); + } + +} diff --git a/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Test6.php b/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Test6.php new file mode 100644 index 000000000..4e5dff1eb --- /dev/null +++ b/web/modules/contrib/porterstemmer/tests/src/Unit/Porter2Test6.php @@ -0,0 +1,43 @@ +assertEquals($stem, Porter2::stem($word)); + } + + /** + * Data provider for testStem(). + * + * @return array + * Nested arrays of values to check: + * - $word + * - $stem + */ + public function stemDataProvider() { + return $this->retrieveStemWords(25000, 5000); + } + +} diff --git a/web/modules/contrib/porterstemmer/tests/src/Unit/PorterPeclBase.php b/web/modules/contrib/porterstemmer/tests/src/Unit/PorterPeclBase.php new file mode 100644 index 000000000..3e8fb051a --- /dev/null +++ b/web/modules/contrib/porterstemmer/tests/src/Unit/PorterPeclBase.php @@ -0,0 +1,31 @@ +has_pecl_stem = extension_loaded('stem') && function_exists('stem_english'); + } + +} diff --git a/web/modules/contrib/porterstemmer/tests/src/Unit/TestItemsTrait.php b/web/modules/contrib/porterstemmer/tests/src/Unit/TestItemsTrait.php new file mode 100644 index 000000000..92a453faf --- /dev/null +++ b/web/modules/contrib/porterstemmer/tests/src/Unit/TestItemsTrait.php @@ -0,0 +1,53 @@ +