C.2.2.1 Pseudo code

The following is the pseudo code for the second step.

if sub-list 4 is not empty:
    if givenname is usually first, store its elements as alternative surname.
    if surname is usually first, store its elements as alternative givenname.
if sub-list 3 is not empty:
    if givenname is usually first, append its elements as alternative surname.
    if surname is usually first, append its elements as alternative givenname.
if sub-list 2 is not empty:
    if givenname is usually first, store surname element as surname, and
       append alternative surname element to alternative surname.
    if surname is usually first, store givenname element as givenname, and
       append alternative givenname element to alternative givenname.
if sub-list 1 is not empty:
    if the first name component (e.g. givenname) doesn't have an alternative
       name, but the second name component (e.g. surname) does, then store the
       elements alternative surname.
    if the first name component has an alternative name, then sub-list 2
       was not empty, then store the elements as either alternative surname (if surname
       is usually first) or alternative givenname (if given name is usually first).
sub-list 0 should be non-empty all the time:
    if both sub-list 1 and 2 are not empty, then the elements in this list is
       either surname & altnative surname (if surname is usually first) , or
       givenname & alternative givenname (if given name is usually first).
    if sub-list 2 is empty, then for both cases sub-list 1 empty or not
       this sub-list 0 contains surname and givenname.

The following pseudo code shows the rules if only sub-list 0 is non-empty (i.e. no other sub-list contains any words, the case with all simple names).

if sub-list 1 and 2 is empty, this is the most often case:
   for each element in sub-list 0:
       if the element is saint:
         if it is a word only:
              if givenname is usually first, store the element as givenname.
              if surname is usually first, store the element as surname.
         else:
              if givenname is usually first, store the element as givenname,
                 and store the element after hypen as alternative givenname.
              if surname is usually first, store the element as surname, and
                 store the element after hypen as alternative surname.
       if the element is rubbish:
         pass over it.
       if the element is baby-of:
         if givenname is usually first, store the element as givenname.
         if surname is usually first, store the element as surname.
       if the element is prefix:
         if givenname is usually first, store the element as givenname.
         if surname is usually first, store the element as surname.
       if the element is a number or alphanumeric:
         if givenname is usually first, store the element as givenname.
         if surname is usually first, store the element as surname.
       if the element is hyphen:
         if givenname is usually first, store the element as givenname.
         if surname is usually first, store the element as surname.
       if the element is a single character:
         it is alternative given name, convert the name usually appear into
         surname (assuming surname follows after an initial).
       if the element is something else:
         all name after hyphen is assigned to the same component.
         if the current word (or hyphened words) is the last and no
              givenname has been assigned yet, then assign it to givenname.
         if the current word (or hyphened words) is the last and no surname
              has been assigned yet, then assign it to surname.
         if the current name component is givenname and no givenname has
              been assigned yet, then assign it to givenname.
         if the current name component is surname and no surname has
              been assigned yet, then assign it to surname.
         if it no hyphened name and the tag of the current word is
              givenname (only) then assign to givenname.
         if it no hyphened name and the tag of the current word is
              surname (only) then assign to surname.
         if the current name component is givenname and the current word is
              (not only) a surname, then assign current name to givenname.
         if the current name component is surname and the current word is
              (not only) a givenname, then assign current name to surname.
         else:
              if givenname is usually first, store the element as givenname.
              if surname is usually first, store the element as surname.