Re: Is there any library for converting common English words to its equivalent numeric value in digits?
- From: Kent M Pitman <pitman@xxxxxxxxxxx>
- Date: 23 Mar 2008 16:35:59 -0400
"Steven M. Haflich" <smh@xxxxxxxxxxxx> writes:
Here is an implementation of the reverse, written long ago.
This isn't very fault tolerant, takes kind of a long time to load,
takes more storage than you'd like, and doesn't work over the full
range of numbers, but has a bit of elegance in its simplicity...
(defun parse-english-number (string)
(or (gethash string
;; Might take a while (and a bit of space) to load.
;; Oh, and I recommend you do this compiled, not interpreted.
(load-time-value
(let ((table (make-hash-table :test #'equalp)))
;; Doesn't work for really huge numbers
(dotimes (i 1000000)
(setf (gethash (format nil "~R" i) table) i)) table)
nil))
(error "Can't parse English number: ~A" string)))
This one is even shorter, uses less space, works over a more general
range, but runs a bit slower in the worst case (not too bad in the
best case, though):
(defun parse-english-number (string)
(loop for i from 0 do
(when (equal string (format nil "~R" i))
(return i))))
[There's a trivial variant of this that would find negatives, too.]
(No, these are not serious suggestions.)
.
- Follow-Ups:
- References:
- Is there any library for converting common English words to its equivalent numeric value in digits?
- From: normanj
- Re: Is there any library for converting common English words to its equivalent numeric value in digits?
- From: John Thingstad
- Re: Is there any library for converting common English words to its equivalent numeric value in digits?
- From: Brian
- Re: Is there any library for converting common English words to its equivalent numeric value in digits?
- From: Steven M. Haflich
- Is there any library for converting common English words to its equivalent numeric value in digits?
- Prev by Date: Re: Managing many small libraries
- Next by Date: Re: C++ program as a Lisp expression
- Previous by thread: Re: Is there any library for converting common English words to its equivalent numeric value in digits?
- Next by thread: Re: Is there any library for converting common English words to its equivalent numeric value in digits?
- Index(es):
Relevant Pages
|