The HotDocs Computation Archive
Get Extra Help

0089 - "a" or "an"

Description:

Automatically chooses "a" or "an" to place before a text variable, as appropriate.


• Code •

""
// Numbers
IF "0123456789" CONTAINS FIRST( TextVar, 1 )
   IF FIRST( TextVar, 1 ) = "8"
   OR INTEGER( TextVar ) = 11
   OR (INTEGER( TextVar ) >= 11000
       AND INTEGER( TextVar ) <= 11999)
   OR (INTEGER( TextVar ) >= 11000000
       AND INTEGER( TextVar ) <= 11999999)
   OR INTEGER( TextVar ) = 18
   OR (INTEGER( TextVar ) >= 18000
       AND INTEGER( TextVar ) <= 18999)
   OR (INTEGER( TextVar ) >= 18000000
       AND INTEGER( TextVar ) <= 18999999)
      "an «TextVar»"
   ELSE
      "a «TextVar»"
   END IF

// Distinct letters: Test is if 2nd char is not a letter
// Acronyms: Must be separated by periods, as in "F.B.I."
ELSE IF MID( TextVar, 2, 1 ) < "a"
OR MID( TextVar, 2, 1 ) > "z"
   IF "aefhilmnorsx" CONTAINS FIRST( TextVar, 1 )
      "an «TextVar»"
   ELSE
      "a «TextVar»"
   END IF

// "H" Oddities: Test is the first four letters
ELSE IF "heir~herb~hono~hour" CONTAINS FIRST( TextVar, 4 )
   "an «TextVar»"

// "U" Oddities: Test is the first four letters
ELSE IF
"ubi ~ubic~ubiq~uint~ukul~unan~unic~unid~unif~unig~" +
"unil~unio~uniq~unit~univ~unum~uran~uret~urin~usab~" +
"usag~usan~use ~used~usee~usef~user~usin~usua~usuc~" +
"usuf~usur~usus~utah~ute ~uten~uti ~uter~util~utop~utru"
CONTAINS FIRST( TextVar, 4 )
AND FIRST( aAn-t, 6 ) != "uniden"   // unidentified
	"a «aAn-t»"

// "O" Oddities: Test is the first four letters
ELSE IF "one ~one-~once~ones~onet" CONTAINS FIRST( TextVar, 4 )
   "a «TextVar»"

// Typical words
ELSE IF "aeiou" CONTAINS FIRST( TextVar, 1 )
   "an «TextVar»"
ELSE
   "a «TextVar»"
END IF

• Explanation •

This computation looks at a text variable and determines whether it needs to be preceeded with "a" or "an." Note that the computation will also work with a multiple choice variable or with another computation variable that produces a text result. Our example requires only one variable, TextVar.

The computation takes into account "odd" pairings. It accurately produced each of the following: an 18-wheeler, an F.B.I. agent, a Utahn, an heiress, an 11th hour appeal, a user, an 18 year-old, a unit.

While the computation looks daunting, it will work without any modifications. Just cut and paste it, and change TextVar to the name of your variable. Then place the computation variable where you want the full expression "a/an bla bla bla" to appear, and you're done. If you want the full explanation, read on.

The difficulty with selecting the appropriate indefinite article (a/an) is that it is the initial sound of the word that determines which to use rather than the initial letter. Words that begin with a vowel sound take "an," and words that begin with a consonant or a "y" sound begin with "a." For example: an apple, a bagel, a car, a dog, an elephant, etc. BUT, a Utahn (yutahn), a unit (yunit), a user (yuser), an 18 year-old (eighteen...), an heiress (airess), an hour (our), an FBI agent (eff bee eye), etc.

Fortunately, the seeming "exceptions" fall into nice categories and can be tested for. The computation above tests for these categories one at a time. Each is described next.

Numbers. Three numbers require "an": 8, 11, 18 and numbers that begin with them (e.g. 11,000). We can accurately extract the entire number from the start of TextVar using HotDocs 5.1's INTEGER( ) model. This takes every number up to the first non-number and converts it to an integer value. We then test this integer. Any number that begins with 8 will take "an." Any number that begins with 11, up to 11,999,999 will likewise take "an" (you can add more levels if necessary). And 18 is analyzed just like 11.

Distinct Letters & Acronyms: At times letters are used alone, as in a-bomb, c-section, F-16, and part numbers such as A4936. Acronyms are also composed of distinct letters: IQ, CIA, USA, etc. Unfortunately, our ability to test for this category is limited. The most reasonable test, and the one employed in the computation, is whether the second character is a non-letter. The limitation of this test is that it requires acronyms to be separated with periods (F.B.I.) and it will not catch words that begin with two or three distinct letters (DC-10, AK-47). But it's the best we can do without a lot of extra code. If you use acronyms that are pronounced as words (e.g. NAFTA), enter the word without separating periods. If your situation calls for words that this test will not catch, you can test for them specifically. By the way, there are 12 letters that require "an": AEFHILMNORSX. The rest take "a."

For the brave of heart: You can use Computation #0090: Determine Lettercase to check the lettercase of the second letter in TextVar. If it is uppercase, you likely have an acronym. This is a better method than requiring your users to use periods in their acronyms. But the procedure is a little bit involved.

"H" Words: English has a handful of words beginning in "h" where the "h" is silent. These are heir, herb, honor, hour, and their children (heiress, honorary, hourly, etc.). We can detect all of them by testing just the first four letters of TextVar. Using the CONTAINS( ) model, we construct a string of these "h" exceptions, then test whether this string CONTAINS the first four letters extracted from TextVar. If so, we use "an."

A Note on CONTAINS: In constructing the CONTAINS string, we have separated each of the words with a tilde "~" in order to clearly separate them. CONTAINS will return true if a string is contained anywhere in the CONTAINS string. For example, if our CONTAINS string is "hono hour" and TextVar is "no house," the first four letters of TextVar are "no h" and are indeed found in the CONTAINS string. Because tildes are rare in English, they work well to separate words in the CONTAINS string to prevent these cross-word matches.

"U" Words: There are quite a few words in English with a long "u" sound, which is the equivalent of them beginning with "y." Each of these takes "a" rather than "an." For example, a union, a unique man, a usual hour, etc. Again, by testing the first four letters of TextVar we can locate all of them. The only potential snag is "UNISon" conflicting with "UNISsued," but we ignore it here because "a unison" is odd and unlikely.

"O" Words: There are a very few words in English with a consonantal "o" sound, which is the equivalent of them beginning with "w." Each of these takes "a" rather than "an." For example, a one-time friend, a once-worn suit, a onesided argument, etc. Again, by testing the first four letters of TextVar we can locate all of them.

Mainstream Words: If the computation fails to find any of the special situations above, it resorts to a simple check of the first letter of TextVar. If that letter is a vowel, "an" is used.

 

• Model Template •

This template has everything you need set up and configured for you. It will work as-is, or can be adapted to your variable and dialog names. It contains: 1) sample Word and WordPerfect templates (or an Automator form) to demonstrate an implementation of the computation, 2) a component file containing the computation and all supporting dialogs and variables, and 3) instructions for adapting the computation for your use.

(Go to the download page)

 
 

• Contributors •

LegalCS