Permalink
Browse files

Use earmuffs for special variables

  • Loading branch information...
1 parent 0ce208c commit 2c6a42b8d6216185fe12e11812a51423b9a54c29 Sean Grove committed Nov 14, 2010
Showing with 45 additions and 45 deletions.
  1. +18 −18 inflector.lisp
  2. +27 −27 tests/inflector.lisp
View
@@ -3,9 +3,9 @@
:cl-ppcre
:vana-utils)
(:export :pluralize
- :plural
+ :plural-of
:singularize
- :singular
+ :singular-of
:irregular?
:irregular
:uncountable?
@@ -15,7 +15,7 @@
;; Adapted *cough*ripped*cough* from rails inflector.rb
;;; singular->plurals regular expressions
-(defvar plurals
+(defvar **plurals**
(reverse (list (list "$" "s")
(list "s$" "s")
(list "(ax|test)is$" "\\1es")
@@ -35,7 +35,7 @@
(list "(quiz)$" "\\1zes"))))
;;; plurals->singular regular expressions
-(defvar singulars
+(defvar **singulars**
(reverse (list
(list "s$" "")
(list "(n)ews$" "\\1ews")
@@ -63,10 +63,10 @@
(list "(quiz)zes$" "\\1")
(list "(database)s$" "\\1"))))
-(defvar uncountables
+(defvar **uncountables**
(list "equipment" "information" "rice" "money" "species" "series" "fish" "sheep" "jeans"))
-(defvar irregulars
+(defvar **irregulars**
(args->alist
"person" "people"
"man" "men"
@@ -75,51 +75,51 @@
"move" "moves"
"cow" "kine"))
-;; Interface for adding new uncountables, querying, etc.
+;; Interface for adding new **uncountables**, querying, etc.
(defun uncountable (word)
"Notifies the inflector that a word is uncountable"
- (setf uncountables (cons word uncountables)))
+ (setf **uncountables** (cons word **uncountables**)))
(defun uncountable? (word)
- (member word uncountables :test #'string-equal))
+ (member word **uncountables** :test #'string-equal))
(defun irregular (singular plural)
"Adds a irregular single-plural set to the irregular list"
- (setf irregulars (acons singular plural irregulars)))
+ (setf **irregulars** (acons singular plural **irregulars**)))
(defun irregular? (word)
- (or (-> word irregulars)
- (rassoc word irregulars :test #'string-equal)))
+ (or (-> word **irregulars**)
+ (rassoc word **irregulars** :test #'string-equal)))
;; For a touch of added robustness
(defun irregular-plural? (word)
- (rassoc word irregulars :test #'string-equal))
+ (rassoc word **irregulars** :test #'string-equal))
(defun irregular-singular? (word)
- (-> word irregulars))
+ (-> word **irregulars**))
;; These two could be combined nicely, I'm sure
(defun get-irregular-singular (plural)
(if (irregular-singular? plural)
plural
- (car (rassoc plural irregulars :test #'string-equal))))
+ (car (rassoc plural **irregulars** :test #'string-equal))))
(defun get-irregular-plural (singular)
(if (irregular-plural? singular)
singular
- (-> singular irregulars)))
+ (-> singular **irregulars**)))
(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))))
+ (t (inflector-helper word **plurals**))))
(defun singular-of (word)
"Returns the singular of a word if it's singular, or itself if already singular"
(cond ((uncountable? word) word)
((irregular? word) (get-irregular-singular word))
- (t (inflector-helper word singulars))))
+ (t (inflector-helper word **singulars**))))
(defun pluralize (count word)
(if (not (= count 1))
View
@@ -5,41 +5,41 @@
(in-package :vana-inflector-test)
-(define-test test-pluralize-regular
- (assert-equal "quizzes" (pluralize "quiz"))
- (assert-equal "oxen" (pluralize "ox"))
- (assert-equal "matrices" (pluralize "matrix"))
- (assert-equal "vertices" (pluralize "vertex"))
- (assert-equal "indices" (pluralize "index"))
- (assert-equal "hives" (pluralize "hive"))
- (assert-equal "tomatoes" (pluralize "tomato"))
- (assert-equal "crises" (pluralize "crisis")))
-
-(define-test test-pluralize-irregular
- (assert-equal "people" (pluralize "person"))
- (assert-equal "men" (pluralize "man"))
- (assert-equal "sexes" (pluralize "sex"))
- (assert-equal "kine" (pluralize "cow")))
+(define-test test-plural-of-regular
+ (assert-equal "quizzes" (plural-of "quiz"))
+ (assert-equal "oxen" (plural-of "ox"))
+ (assert-equal "matrices" (plural-of "matrix"))
+ (assert-equal "vertices" (plural-of "vertex"))
+ (assert-equal "indices" (plural-of "index"))
+ (assert-equal "hives" (plural-of "hive"))
+ (assert-equal "tomatoes" (plural-of "tomato"))
+ (assert-equal "crises" (plural-of "crisis")))
+
+(define-test test-plural-of-irregular
+ (assert-equal "people" (plural-of "person"))
+ (assert-equal "men" (plural-of "man"))
+ (assert-equal "sexes" (plural-of "sex"))
+ (assert-equal "kine" (plural-of "cow")))
(define-test test-add-irregular
- (assert-equal "womans" (pluralize "woman"))
+ (assert-equal "womans" (plural-of "woman"))
(irregular "woman" "women")
- (assert-equal "women" (pluralize "woman")))
+ (assert-equal "women" (plural-of "woman")))
(define-test test-uncountable
- (assert-equal "fish" (pluralize "fish"))
- (assert-equal "fish" (singularize "fish"))
- (assert-equal "sheep" (pluralize "sheep"))
- (assert-equal "sheep" (singularize "sheep")))
+ (assert-equal "fish" (plural-of "fish"))
+ (assert-equal "fish" (singular-of "fish"))
+ (assert-equal "sheep" (plural-of "sheep"))
+ (assert-equal "sheep" (singular-of "sheep")))
(define-test test-add-uncountable
- (assert-equal "cackles" (pluralize "cackle"))
+ (assert-equal "cackles" (plural-of "cackle"))
(uncountable "cackle")
- (assert-equal "cackle" (pluralize "cackle")))
+ (assert-equal "cackle" (plural-of "cackle")))
-(define-test test-singularize
- (assert-equal "cup" (singularize "cups"))
- (assert-equal "ox" (singularize "oxen"))
- (assert-equal "life" (singularize "lives")))
+(define-test test-singular-of
+ (assert-equal "cup" (singular-of "cups"))
+ (assert-equal "ox" (singular-of "oxen"))
+ (assert-equal "life" (singular-of "lives")))
;;(run-tests)

0 comments on commit 2c6a42b

Please sign in to comment.