Author Topic: Proper Names  (Read 2078 times)

0 Members and 1 Guest are viewing this topic.

David Bethel

  • Swamp Rat
  • Posts: 656
Proper Names
« on: December 11, 2004, 07:56:05 PM »
In creating an AutoLisp string function to format proper names,  I haven't found a definitive source for the format for proper names. ( Queen's English I think )  Most spreadsheets  (etc) can only handle the first letter of each word.  I want something a bit more robust.

I think the comma should always be the indicator for a suffix.  I also think Jr.  & PhD are proper.  Are professional suffixes ( or whatever they are called ) always CAPS?

Anyone care to enlighten me? Or add to the list of special conditions?

Code: [Select]
(defun proper (s / tmp pv sx rl i cl)
  (while (= " " (substr s (strlen s)))
         (setq s (substr s 1 (1- (strlen s)))))

  (setq tmp (strcase (substr s 1 1));1st letter always CAP
         pv tmp ;previous letter
           i 2)

  (while (<= i (strlen s))
         (setq cl (substr s i 1) ;current letter

               rl (substr s i)) ;remaining letters
         (cond (sx
                 (cond ((= " JR." (strcase rl))
                        (setq tmp (strcat tmp " Jr.")))
                       ((= " PHD" (strcase rl))
                        (setq tmp (strcat tmp " PhD")))
                       (T
                        (setq tmp (strcat tmp (strcase rl)))))
                 (setq i (1+ (strlen s))))
                ((= cl " ")
                 (setq tmp (strcat tmp cl)
                       pv cl
                       i (1+ i)))
                ((and (/= cl " ")
                      (or (= pv " ")
                          (= pv ".")))
                 (setq tmp (strcat tmp (strcase cl))
                       pv cl
                       i (1+ i)))
                ((= cl ",")
                 (setq tmp (strcat tmp cl)
                       pv cl
                       sx T
                       i (1+ i)))
                ((and (/= cl " ")
                      (/= pv " "))
                 (setq tmp (strcat tmp (strcase cl t))
                       pv cl
                       i (1+ i)))
                (T
                 (setq tmp (strcat tmp (strcase cl))
                       pv cl
                       i (1+ i)))))
tmp)



The test bed:
Code: [Select]
(textpage)
(foreach n '("john doe"
             "mr.john doe"
             "mr. JOHN q. doe"
             "mr. & mrs. John Q. doe"
             "mr. & mrs. John Q. doe, esq"
             "john doe, jr."
             "dr. j.q. Doe"
             "JOHN DOE, III"
             "john doe, aia"
            )
(princ "\n")
(princ (proper n)))


I stripped all spaces off of the end of the orginal string just to make things a little easier.  -David
R12 Dos - A2K

hendie

  • Guest
Proper Names
« Reply #1 on: December 13, 2004, 03:28:58 AM »
Professional "suffixes" are not always caps ~ eg BSc for Bachelor of Science. I can't think of any definitive source ~perhaps lookup some university website and see what professional degrees are offered ?

David Bethel

  • Swamp Rat
  • Posts: 656
Proper Names
« Reply #2 on: December 13, 2004, 08:57:29 AM »
Yes, I've found very elementary rule site, but nothing real elaborate.

I've added a couple tests to the thing.

               "mr. JOHN q. MCDOE"
               "john doe, pres."


-David
R12 Dos - A2K