Git Product home page Git Product logo

pluralize's Introduction

Project Status: Active – The project has reached a stable, usable state and is being actively developed. Signed by Signed commit % Linux build Status Coverage Status Minimal R Version License

pluralize

Pluralize and ‘Singularize’ Any (English) Word

Description

Tools are provided to create plural, singular and regular forms of English words along with tools to augment the built-in rules to fit specializied needs. Core functionality is based on a JavaScript library, https://github.com/blakeembrey/pluralize.

What’s Inside The Tin

The following functions are implemented:

  • add_irregular_rule: Add a custom rule for making “deregularizing” a word
  • add_plural_rule: Add a custom rule for making a word plural
  • add_singular_rule: Add a custom rule for making a word singular
  • add_uncountable_rule: Make a word “uncountable”
  • is_plural: Test plural state of a word
  • pluralize: Pluralize a word
  • singularize: Singularize a word

Installation

remotes::install_gitlab("hrbrmstr/pluralize")
# or
remotes::install_github("hrbrmstr/pluralize")

NOTE: To use the ‘remotes’ install options you will need to have the {remotes} package installed.

Usage

library(pluralize)

# current version
packageVersion("pluralize")
## [1] '0.2.0'
pluralize('test')
## [1] "tests"

singularize('test')
## [1] "test"

singularize(c("boats", "houses", "cats", "rivers"))
## [1] "boat"  "house" "cat"   "river"

pluralize(singularize(c("boats", "houses", "cats", "rivers")))
## [1] "boats"  "houses" "cats"   "rivers"

singularize(c("buses", "wishes", "pitches", "boxexs"))
## [1] "bus"   "wish"  "pitch" "boxex"

pluralize(singularize(c("buses", "wishes", "pitches", "boxexs")))
## [1] "buses"   "wishes"  "pitches" "boxexes"

singularize(c("pennies", "spies", "babies", "cities", "daisies"))
## [1] "penny"  "spy"    "baby"   "city"   "daisie"

pluralize(singularize(c("pennies", "spies", "babies", "cities", "daisies")))
## [1] "pennies" "spies"   "babies"  "cities"  "daisies"

singularize(c("sheep", "fish", "deer", "species", "aircraft"))
## [1] "sheep"    "fish"     "deer"     "specie"   "aircraft"

pluralize(singularize(c("sheep", "fish", "deer", "species", "aircraft")))
## [1] "sheep"    "fish"     "deer"     "species"  "aircraft"

pluralize('test', 5)
## [1] "tests"

pluralize('test', 5, TRUE)
## [1] "5 tests"

pluralize('regex')
## [1] "regexes"

add_plural_rule("gex", "gexii")

pluralize('regex')
## [1] "regexii"

singularize('singles')
## [1] "single"

add_singular_rule("singles", "singular")

singularize('singles')
## [1] "singular"

pluralize("irregular")
## [1] "irregulars"

pluralize(c("woman", "man", "child", "tooth", "foot", "person", "leaf"))
## [1] "women"    "men"      "children" "teeth"    "feet"     "people"   "leaves"

singularize(c("woman", "man", "child", "tooth", "foot", "person", "leaf"))
## [1] "woman"  "man"    "child"  "tooth"  "foot"   "person" "leaf"

add_irregular_rule("irregular", "regular")

pluralize("irregular")
## [1] "regular"

pluralize("paper")
## [1] "papers"

add_uncountable_rule("paper")

pluralize("paper")
## [1] "paper"

pluralize Metrics

Lang # Files (%) LoC (%) Blank lines (%) # Lines (%)
HTML 1 0.1 367 0.79 33 0.28 2 0.01
Rmd 2 0.2 58 0.12 72 0.61 71 0.39
R 7 0.7 40 0.09 13 0.11 108 0.60

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

pluralize's People

Contributors

gtm19 avatar hrbrmstr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jimsforks gtm19

pluralize's Issues

CRAN release?

Great package. Any plans to release that on CRAN?

Singularizes tennis to tenni

Installed off github:
devtools::install_github("hrbrmstr/pluralize")
library(pluralize)
singularize(c('tennis'))
[1] "tenni"

.onAttach prevents use of pluralize in packages

Small issue I had when trying to import pluralize for use in a package. When adding pluralize::pluralize to a function in my package (whether or not @importing pluralize), I would get the following error:

> pl("tree")

Error in .pkgenv$ct$call("pluralize", y, n, prepend) : 
 attempt to apply non-function 

This is because the ct object in .pkenv is only created when pluralize is loaded using library().

I believe I have fixed this using .onLoad() and will open a PR shortly.

It converse "has" to "ha", "was" to "wa".

It's a good pkg to change between plurals and singular, but I found it will converse "has" to "ha" and "was" to "wa" when I use the sigularize() function. These are not the results I want. Can you fix this? Thanks for the fantastic job.

Does not work with dataframes/vectors?

This works:

data <- c("tests", "nations")
singularize(data)

However, this does not:

data <- data.frame(c("tests", "nations"))
singularize(data)

Error:

Error in context_eval(join(src), private$context) :
TypeError: word.toLowerCase is not a function

I was trying to apply this to a large dataframe after using TidyText's unnest_tokens

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.