Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Minor data changes

  • Loading branch information...
commit 29d9299f28141a2da217cc91a56d6ac111aff1bb 1 parent 11f7a9f
Sean Grove authored
Showing with 53 additions and 44 deletions.
  1. +53 −44 inflector.lisp
View
97 inflector.lisp
@@ -15,53 +15,52 @@
;; Adapted *cough*ripped*cough* from rails inflector.rb
;;; singular->plurals regular expressions
-(setf **plurals**
- (reverse (list (list "$" "s")
- (list "s$" "s")
- (list "(ax|test)is$" "\\1es")
- (list "(octop|vir)us$" "\\1i")
- (list "(alias|status)$" "\\1es")
- (list "(bu)s$" "\\1ses")
- (list "(buffal|tomat)o$" "\\1oes")
- (list "([ti])um$" "\\1a")
- (list "sis$" "ses")
- (list "(?:([^f])fe|([lr])f)$" "\\1\\2ves")
- (list "(hive)$" "\\1s")
- (list "([^aeiouy]|qu)y$" "\\1ies")
- (list "(x|ch|ss|sh)$" "\\1es")
- (list "(matr|vert|ind)(?:ix|ex)$" "\\1ices")
- (list "([m|l])ouse$" "\\1ice")
- (list "^(ox)$" "\\1en")
- (list "(quiz)$" "\\1zes"))))
+(defvar **plurals**
+ '(("(quiz)$" "\\1zes")
+ ("^(ox)$" "\\1en")
+ ("([m|l])ouse$" "\\1ice")
+ ("(matr|vert|ind)(?:ix|ex)$" "\\1ices")
+ ("(x|ch|ss|sh)$" "\\1es")
+ ("([^aeiouy]|qu)y$" "\\1ies")
+ ("(hive)$" "\\1s")
+ ("(?:([^f])fe|([lr])f)$" "\\1\\2ves")
+ ("sis$" "ses")
+ ("([ti])um$" "\\1a")
+ ("(buffal|tomat)o$" "\\1oes")
+ ("(bu)s$" "\\1ses")
+ ("(alias|status)$" "\\1es")
+ ("(octop|vir)us$" "\\1i")
+ ("(ax|test)is$" "\\1es")
+ ("s$" "s")
+ ("$" "s")))
;;; plurals->singular regular expressions
(defvar **singulars**
- (reverse (list
- (list "s$" "")
- (list "(n)ews$" "\\1ews")
- (list "([ti])a$" "\\1um")
- (list "((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$" "\\1\\2sis")
- (list "(^analy)ses$" "\\1sis")
- (list "([^f])ves$" "\\1fe")
- (list "(hive)s$" "\\1")
- (list "(tive)s$" "\\1")
- (list "([lr])ves$" "\\1f")
- (list "([^aeiouy]|qu)ies$" "\\1y")
- (list "(s)eries$" "\\1eries")
- (list "(m)ovies$" "\\1ovie")
- (list "(x|ch|ss|sh)es$" "\\1")
- (list "([m|l])ice$" "\\1ouse")
- (list "(bus)es$" "\\1")
- (list "(o)es$" "\\1")
- (list "(shoe)s$" "\\1")
- (list "(cris|ax|test)es$" "\\1is")
- (list "(octop|vir)i$" "\\1us")
- (list "(alias|status)es$" "\\1")
- (list "^(ox)en" "\\1")
- (list "(vert|ind)ices$" "\\1ex")
- (list "(matr)ices$" "\\1ix")
- (list "(quiz)zes$" "\\1")
- (list "(database)s$" "\\1"))))
+ '(("(database)s$" "\\1")
+ ("(quiz)zes$" "\\1")
+ ("(matr)ices$" "\\1ix")
+ ("(vert|ind)ices$" "\\1ex")
+ ("^(ox)en" "\\1")
+ ("(alias|status)es$" "\\1")
+ ("(octop|vir)i$" "\\1us")
+ ("(cris|ax|test)es$" "\\1is")
+ ("(shoe)s$" "\\1")
+ ("(o)es$" "\\1")
+ ("(bus)es$" "\\1")
+ ("([m|l])ice$" "\\1ouse")
+ ("(x|ch|ss|sh)es$" "\\1")
+ ("(m)ovies$" "\\1ovie")
+ ("(s)eries$" "\\1eries")
+ ("([^aeiouy]|qu)ies$" "\\1y")
+ ("([lr])ves$" "\\1f")
+ ("(tive)s$" "\\1")
+ ("(hive)s$" "\\1")
+ ("([^f])ves$" "\\1fe")
+ ("(^analy)ses$" "\\1sis")
+ ("((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$" "\\1\\2sis")
+ ("([ti])a$" "\\1um")
+ ("(n)ews$" "\\1ews")
+ ("s$" ""))
(defvar **uncountables**
(list "equipment" "information" "rice" "money" "species" "series" "fish" "sheep" "jeans"))
@@ -109,12 +108,22 @@
singular
(-> singular **irregulars**)))
+(defun 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"
+ (setf **plurals** (cons (list rule replacement)
+ **plurals**)))
+
(defun plural-of (word)
"Returns the plural of a word if it's singular, or itself if already plural"
(cond ((uncountable? word) word)
((irregular? word) (get-irregular-plural word))
(t (inflector-helper word **plurals**))))
+(defun 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"
+ (setf **singulars** (cons (list rule replacement)
+ **singulars**)))
+
(defun singular-of (word)
"Returns the singular of a word if it's singular, or itself if already singular"
(cond ((uncountable? word) word)
Please sign in to comment.
Something went wrong with that request. Please try again.