Re: Is there any library for converting common English words to its equivalent numeric value in digits?



"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.)
.



Relevant Pages

  • Re: Max forms
    ... I was thinking about a utility, that would convert dfm into that kind ... If you do it this way you have to decode the string to a sequence of bytes ... of storage actually needed since it encodes each byte as two hex characters. ... You then create a TstringStream from this constant and load the icon from it. ...
    (borland.public.delphi.language.objectpascal)
  • Re: VBA macro stops executing on Word 2003 but works on Word XP
    ... The macro executes perfectly. ... Dim PatFullName() As String ... ' Load Provider Name into ProvPath var ...
    (microsoft.public.word.vba.general)
  • Re: VBA macro stops executing on Word 2003 but works on Word XP
    ... The macro executes perfectly. ... Dim PatFullName() As String ... ' Load Provider Name into ProvPath var ...
    (microsoft.public.word.vba.general)
  • Re: Problem when I boot...
    ... You have an invalid or remnant entry in a place used to load programs on ... What's likely is that a program neglected to enclose its load string ... enclose the string identifying the program within double quotes if it ... the spaces embedded in the paths to their executables. ...
    (microsoft.public.windowsxp.hardware)
  • Re: VBA macro stops executing on Word 2003 but works on Word XP
    ... Dim PatFullName() As String ... Dim ProgNotePathAndFileName As String ... ' Load Provider Name into ProvPath var ...
    (microsoft.public.word.vba.general)