The cl-inflector Reference Manual

Table of Contents

Next: , Previous: , Up: (dir)   [Contents][Index]

The cl-inflector Reference Manual

This is the cl-inflector Reference Manual, version 0.2, generated automatically by Declt version 2.3 "Robert April" on Wed Mar 14 03:21:58 2018 GMT+0.


Next: , Previous: , Up: Top   [Contents][Index]

1 Introduction

CL-Inflector

A common lisp library to easily pluralize and singularize English and Portuguese words.

This is a port of the ruby ActiveSupport Inflector module.

Installation

Just use Quicklisp:

> (ql:quickload 'cl-inflector)

Usage

Example Usage:

> (use-package :cl-inflector)
> (let ((dollars 1.7)
        (users 34)
        (purchases 1))
       (format nil "The site has ~D ~A, with a total of ~D ~A and $~D ~A"  
               users (pluralize users "user") 
               purchases (pluralize purchases "purchase") 
               dollars (pluralize dollars "dollar")))
"The site has 34 users, with a total of 1 purchase and $1.7 dollars"

Basic Usage, plural-of and singular-of:

> (plural-of "octopus") 
"octopi"
> (plural-of "datum")
"data"
> (singular-of "children")
"child"
> (singular-of "cats")
"cat"
> (singular-of "data")
"datum"

Basic Usage, pluralize:

> (pluralize 2 "octopus")
"octopi"
> (pluralize 1 "octopus")
"octopus"

You can pass in the default plural to be used. If not, the inflector is used to determine the plural.

> (pluralize 2 "tooth" "teeth")
"teeth"
> (pluralize 2 "tooth")
"tooths"

Use irregular to add an irregular:

> (singular-of "feet")
"feet"
> (irregular "foot" "feet")
> (singular-of "feet")
"foot"
> (plural-of "foot")
"feet"

Use uncountable to add an uncountable:

> (plural-of "advice")
"advices"
> (singular-of "advice")
"advice"
> (singular-of "advices")
"advice"
> (uncountable "advice")
> (plural-of "advice")
"advice"

You can also pluralize/singularize symbols (very useful for writing macros):

> (symbol-plural-of 'book)
BOOKS
> (symbol-singular-of 'pages)
PAGE

Internationalization support

Currently, cl-inflector has built-in support for english(en_US) and brazilian portuguese(pt_BR), and it also offers a simple API to change between languages:

> (available-languages)
(:EN_US :PT_BR)
> (current-language-name)
:EN_US

For changing between languages, use set-language!:

> (plural-of "país")
"país"
> (set-language! :pt_BR)
:PT_BR
> (plural-of "país")
"países"

You can add irregular words and uncountable in the same way as presented above, but you still does not support adding a whole new language.

For more examples, check the tests source. License

Released under the MIT license, please see LICENSE for more details

Thanks

Authors


Next: , Previous: , Up: Top   [Contents][Index]

2 Systems

The main system appears first, followed by any subsystem dependency.


Previous: , Up: Systems   [Contents][Index]

2.1 cl-inflector

License

MIT

Description

Functions to pluralize and singularize english and portuguese languages words

Version

0.2

Dependencies
Source

cl-inflector.asd (file)

Components

Next: , Previous: , Up: Top   [Contents][Index]

3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


Previous: , Up: Files   [Contents][Index]

3.1 Lisp


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.1 cl-inflector.asd

Location

cl-inflector.asd

Systems

cl-inflector (system)

Packages

cl-inflector.system


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.2 cl-inflector/langs.lisp

Parent

cl-inflector (system)

Location

langs.lisp

Packages

cl-inflector.langs

Exported Definitions
Internal Definitions

Previous: , Up: Lisp files   [Contents][Index]

3.1.3 cl-inflector/inflector.lisp

Parent

cl-inflector (system)

Location

inflector.lisp

Packages

cl-inflector

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

4 Packages

Packages are listed by definition order.


Next: , Previous: , Up: Packages   [Contents][Index]

4.1 cl-inflector.system

Source

cl-inflector.asd

Use List

Next: , Previous: , Up: Packages   [Contents][Index]

4.2 cl-inflector.langs

Package with the language class and its methods and a few functions to handle the language class.

Source

langs.lisp (file)

Use List

common-lisp

Exported Definitions
Internal Definitions

Previous: , Up: Packages   [Contents][Index]

4.3 cl-inflector

Package with function to pluralize/singularize words.

Source

inflector.lisp (file)

Nickname

inflector

Use List
Exported Definitions
Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


Next: , Previous: , Up: Definitions   [Contents][Index]

5.1 Exported definitions


Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.1 Special variables

Special Variable: *current-language*

Current language used. Defaults to en_US.

Package

cl-inflector.langs

Source

langs.lisp (file)


Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.2 Functions

Function: available-languages ()

Returns the name of all available languages.

Package

cl-inflector.langs

Source

langs.lisp (file)

Function: current-language ()

Returns the current language object.

Package

cl-inflector.langs

Source

langs.lisp (file)

Function: current-language-name ()

Returns the name of the current language.

Package

cl-inflector.langs

Source

langs.lisp (file)

Function: irregular SINGULAR PLURAL

Adds a irregular single-plural set to the irregular list

Package

cl-inflector

Source

inflector.lisp (file)

Function: irregular? WORD

Tests if a given ‘word’ is irregular, plural or singular.

Package

cl-inflector

Source

inflector.lisp (file)

Function: plural-of WORD

Returns the plural of a word if it’s singular, or itself if already plural

Package

cl-inflector

Source

inflector.lisp (file)

Function: pluralize COUNT WORD &optional PLURAL

If ‘count’ is greater than 1, returns the ‘plural’ arg if provided, otherwise pluralizes the given ‘word’.

Package

cl-inflector

Source

inflector.lisp (file)

Function: set-language! LANG &optional CLONE?

Sets the current language, if clone? then set to a copy of the current language this is useful - eg in testing or creating custom dictionaries.

Package

cl-inflector.langs

Source

langs.lisp (file)

Function: singular-of WORD

Returns the singular of a word if it’s singular, or itself if already singular

Package

cl-inflector

Source

inflector.lisp (file)

Function: symbol-plural-of WORD &key PACKAGE

Creates a symbol with the plural version of the given ‘word’.

Package

cl-inflector

Source

inflector.lisp (file)

Function: symbol-singular-of WORD &key PACKAGE

Creates a symbol with the singular version of the given ‘word’.

Package

cl-inflector

Source

inflector.lisp (file)

Function: uncountable WORD

Notifies the inflector that a word is uncountable.

Package

cl-inflector

Source

inflector.lisp (file)

Function: uncountable? WORD

Checks whether a given ‘word’ is uncountable.

Package

cl-inflector

Source

inflector.lisp (file)


Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.3 Generic functions

Generic Function: irregulars OBJECT
Generic Function: (setf irregulars) NEW-VALUE OBJECT
Package

cl-inflector.langs

Methods
Method: irregulars (LANGUAGE language)
Method: (setf irregulars) NEW-VALUE (LANGUAGE language)

Alist with irregular words pairs.

Source

langs.lisp (file)

Generic Function: plurals OBJECT
Generic Function: (setf plurals) NEW-VALUE OBJECT
Package

cl-inflector.langs

Methods
Method: plurals (LANGUAGE language)
Method: (setf plurals) NEW-VALUE (LANGUAGE language)

Alist with (singular-matching-regex plural-equiv).

Source

langs.lisp (file)

Generic Function: singulars OBJECT
Generic Function: (setf singulars) NEW-VALUE OBJECT
Package

cl-inflector.langs

Methods
Method: singulars (LANGUAGE language)
Method: (setf singulars) NEW-VALUE (LANGUAGE language)

Alist with (plural-matching-regex singular-equiv).

Source

langs.lisp (file)

Generic Function: uncountables OBJECT
Generic Function: (setf uncountables) NEW-VALUE OBJECT
Package

cl-inflector.langs

Methods
Method: uncountables (LANGUAGE language)
Method: (setf uncountables) NEW-VALUE (LANGUAGE language)

List with uncountable words.

Source

langs.lisp (file)


Previous: , Up: Exported definitions   [Contents][Index]

5.1.4 Classes

Class: language ()

Language object to hold all lists with regexps, irregulars and uncountable words.

Package

cl-inflector.langs

Source

langs.lisp (file)

Direct superclasses

standard-object (class)

Direct methods
Direct slots
Slot: name

Name of the language as a keyword.

Initargs

:name

Readers

name (generic function)

Writers

(setf name) (generic function)

Slot: plurals

Alist with (singular-matching-regex plural-equiv).

Initargs

:plurals

Readers

plurals (generic function)

Writers

(setf plurals) (generic function)

Slot: singulars

Alist with (plural-matching-regex singular-equiv).

Initargs

:singulars

Readers

singulars (generic function)

Writers

(setf singulars) (generic function)

Slot: uncountables

List with uncountable words.

Initargs

:uncountables

Readers

uncountables (generic function)

Writers

(setf uncountables) (generic function)

Slot: irregulars

Alist with irregular words pairs.

Initargs

:irregulars

Readers

irregulars (generic function)

Writers

(setf irregulars) (generic function)


Previous: , Up: Definitions   [Contents][Index]

5.2 Internal definitions


Next: , Previous: , Up: Internal definitions   [Contents][Index]

5.2.1 Special variables

Special Variable: +en_us+

Adapted *cough*ripped*cough* from rails inflector.rb singular->plurals regular expressions

Package

cl-inflector.langs

Source

langs.lisp (file)

Special Variable: +languages+

List of all available languages objects.

Package

cl-inflector.langs

Source

langs.lisp (file)

Special Variable: +pt_br+
Package

cl-inflector.langs

Source

langs.lisp (file)


Next: , Previous: , Up: Internal definitions   [Contents][Index]

5.2.2 Functions

Function: get-irregular-plural SINGULAR

Makes sure that a ‘singular’ word is on its plural form. If it is already plural, returns it. If it is not irregular, returns nil.

Package

cl-inflector

Source

inflector.lisp (file)

Function: get-irregular-singular PLURAL

Makes sure that a ‘plural’ word is on its singular form. If it is already singular, returns it. If it is not irregular, returns nil.

Package

cl-inflector

Source

inflector.lisp (file)

Function: inflector-helper WORD REGEXES
Package

cl-inflector

Source

inflector.lisp (file)

Function: irregular-plural? WORD

Tests if a given ‘word’ is an irregular word in its plural form.

Package

cl-inflector

Source

inflector.lisp (file)

Function: irregular-singular? WORD

Tests if a given ‘word’ is an irregular word in its singular form.

Package

cl-inflector

Source

inflector.lisp (file)

Function: plural RULE REPLACEMENT

Adds a plural rule, where RULE can be either a string or a regex, and REPLACEMENT can contain capture references defined in RULE

Package

cl-inflector

Source

inflector.lisp (file)

Function: singular RULE REPLACEMENT

Adds a singular rule, where RULE can be either a string or a regex, and REPLACEMENT can contain capture references defined in RULE

Package

cl-inflector

Source

inflector.lisp (file)


Previous: , Up: Internal definitions   [Contents][Index]

5.2.3 Generic functions

Generic Function: name OBJECT
Generic Function: (setf name) NEW-VALUE OBJECT
Package

cl-inflector.langs

Methods
Method: name (LANGUAGE language)
Method: (setf name) NEW-VALUE (LANGUAGE language)

Name of the language as a keyword.

Source

langs.lisp (file)


Previous: , Up: Top   [Contents][Index]

Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts

Jump to:   C   F   L  
Index Entry  Section

C
cl-inflector.asd: The cl-inflector<dot>asd file
cl-inflector/inflector.lisp: The cl-inflector/inflector<dot>lisp file
cl-inflector/langs.lisp: The cl-inflector/langs<dot>lisp file

F
File, Lisp, cl-inflector.asd: The cl-inflector<dot>asd file
File, Lisp, cl-inflector/inflector.lisp: The cl-inflector/inflector<dot>lisp file
File, Lisp, cl-inflector/langs.lisp: The cl-inflector/langs<dot>lisp file

L
Lisp File, cl-inflector.asd: The cl-inflector<dot>asd file
Lisp File, cl-inflector/inflector.lisp: The cl-inflector/inflector<dot>lisp file
Lisp File, cl-inflector/langs.lisp: The cl-inflector/langs<dot>lisp file

Jump to:   C   F   L  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   (  
A   C   F   G   I   M   N   P   S   U  
Index Entry  Section

(
(setf irregulars): Exported generic functions
(setf irregulars): Exported generic functions
(setf name): Internal generic functions
(setf name): Internal generic functions
(setf plurals): Exported generic functions
(setf plurals): Exported generic functions
(setf singulars): Exported generic functions
(setf singulars): Exported generic functions
(setf uncountables): Exported generic functions
(setf uncountables): Exported generic functions

A
available-languages: Exported functions

C
current-language: Exported functions
current-language-name: Exported functions

F
Function, available-languages: Exported functions
Function, current-language: Exported functions
Function, current-language-name: Exported functions
Function, get-irregular-plural: Internal functions
Function, get-irregular-singular: Internal functions
Function, inflector-helper: Internal functions
Function, irregular: Exported functions
Function, irregular-plural?: Internal functions
Function, irregular-singular?: Internal functions
Function, irregular?: Exported functions
Function, plural: Internal functions
Function, plural-of: Exported functions
Function, pluralize: Exported functions
Function, set-language!: Exported functions
Function, singular: Internal functions
Function, singular-of: Exported functions
Function, symbol-plural-of: Exported functions
Function, symbol-singular-of: Exported functions
Function, uncountable: Exported functions
Function, uncountable?: Exported functions

G
Generic Function, (setf irregulars): Exported generic functions
Generic Function, (setf name): Internal generic functions
Generic Function, (setf plurals): Exported generic functions
Generic Function, (setf singulars): Exported generic functions
Generic Function, (setf uncountables): Exported generic functions
Generic Function, irregulars: Exported generic functions
Generic Function, name: Internal generic functions
Generic Function, plurals: Exported generic functions
Generic Function, singulars: Exported generic functions
Generic Function, uncountables: Exported generic functions
get-irregular-plural: Internal functions
get-irregular-singular: Internal functions

I
inflector-helper: Internal functions
irregular: Exported functions
irregular-plural?: Internal functions
irregular-singular?: Internal functions
irregular?: Exported functions
irregulars: Exported generic functions
irregulars: Exported generic functions

M
Method, (setf irregulars): Exported generic functions
Method, (setf name): Internal generic functions
Method, (setf plurals): Exported generic functions
Method, (setf singulars): Exported generic functions
Method, (setf uncountables): Exported generic functions
Method, irregulars: Exported generic functions
Method, name: Internal generic functions
Method, plurals: Exported generic functions
Method, singulars: Exported generic functions
Method, uncountables: Exported generic functions

N
name: Internal generic functions
name: Internal generic functions

P
plural: Internal functions
plural-of: Exported functions
pluralize: Exported functions
plurals: Exported generic functions
plurals: Exported generic functions

S
set-language!: Exported functions
singular: Internal functions
singular-of: Exported functions
singulars: Exported generic functions
singulars: Exported generic functions
symbol-plural-of: Exported functions
symbol-singular-of: Exported functions

U
uncountable: Exported functions
uncountable?: Exported functions
uncountables: Exported generic functions
uncountables: Exported generic functions

Jump to:   (  
A   C   F   G   I   M   N   P   S   U  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.3 Variables

Jump to:   *   +  
I   N   P   S   U  
Index Entry  Section

*
*current-language*: Exported special variables

+
+en_us+: Internal special variables
+languages+: Internal special variables
+pt_br+: Internal special variables

I
irregulars: Exported classes

N
name: Exported classes

P
plurals: Exported classes

S
singulars: Exported classes
Slot, irregulars: Exported classes
Slot, name: Exported classes
Slot, plurals: Exported classes
Slot, singulars: Exported classes
Slot, uncountables: Exported classes
Special Variable, *current-language*: Exported special variables
Special Variable, +en_us+: Internal special variables
Special Variable, +languages+: Internal special variables
Special Variable, +pt_br+: Internal special variables

U
uncountables: Exported classes

Jump to:   *   +  
I   N   P   S   U  

Previous: , Up: Indexes   [Contents][Index]

A.4 Data types

Jump to:   C   L   P   S  
Index Entry  Section

C
cl-inflector: The cl-inflector system
cl-inflector: The cl-inflector package
cl-inflector.langs: The cl-inflector<dot>langs package
cl-inflector.system: The cl-inflector<dot>system package
Class, language: Exported classes

L
language: Exported classes

P
Package, cl-inflector: The cl-inflector package
Package, cl-inflector.langs: The cl-inflector<dot>langs package
Package, cl-inflector.system: The cl-inflector<dot>system package

S
System, cl-inflector: The cl-inflector system

Jump to:   C   L   P   S