Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing whether a word is plural or not #28

Closed
pdscopes opened this issue May 11, 2018 · 2 comments
Closed

Testing whether a word is plural or not #28

pdscopes opened this issue May 11, 2018 · 2 comments

Comments

@pdscopes
Copy link
Contributor

Since you can convert a word from its singular form to plural form and visa versa, is there a way to test if a word is plural or singular?

If not could I submit a pull request to do this? I would guess there could be issues with ambiguous words, e.g. sheep.

    /**
     * Returns true if the word is plural, false otherwise.
     * Ambiguous words return true.
     *
     * <pre>
     * $this->isPlural('post');       // false
     * $this->isPlural('children');   // true
     * $this->isPlural('sheep');      // true
     * $this->isPlural('words');      // true
     * $this->isPlural('CamelChild'); // false
     * </pre>
     *
     * @param string $word
     *
     * @return string
     */
    public function isPlural($word)
    {
        return $word == $this->apply_inflections($word, $this->inflections->plurals);
    }

    /**
     * Returns true if the word is plural, false otherwise.
     * Ambiguous words return true.
     *
     * <pre>
     * $this->isSingular('post');       // true
     * $this->isSingular('children');   // false
     * $this->isSingular('sheep');      // true
     * $this->isSingular('words');      // false
     * $this->isSingular('CamelChild'); // true
     * </pre>
     *
     * @param string $word
     *
     * @return string
     */
    public function isSingular($word)
    {
        return $word == $this->apply_inflections($word, $this->inflections->singulars);
    }
@olvlvl
Copy link
Member

olvlvl commented May 28, 2018

Thanks for your suggestion, that could be useful. Instead of applying inflections and checking if the word changes, what do you think about using the plural and singular regexp available in the Inflections instance?

@pdscopes
Copy link
Contributor Author

I think that would be a nicer way of doing it actually. I'll give it go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants