Terry's ORA Tips

Template Examples – Library Templates

This page updated 5 Sep 2022

 

This article describes several of my example Templates for Online Repository Assistant (ORA). The other example Templates can be found in the index of Example Templates. Other articles in my ORA Section cover various topics about using the software. The "How it Works" sections below include links to articles describing the ORA features used in these Templates.

The Templates described here are Library Templates. Library Templates are intended as a way to record a segment of Template code that one will use repeatedly. Instead of having to recreate the code for particular function for each new Template, we can record it once as a Library Template and then simply call it as needed in individual Text or Auto Type Templates. Creating Library Templates is described in the Template Library section of my article on Advanced Template Methods.

This article describes some Library Templates that I have found useful:

Each Template example includes a comment line or lines describing what it does, another describing how to "call" the Library Template in a Text or Auto Type Template, then the actual Template code. That is followed by a detailed description of how it works.

Some of these examples include use of Transforms using Regular Expressions, which may seem complex to some readers. They are here precisely because they use Regular Expressions, as I find those cases to be prime candidates for Library Templates; once I work out a Regular Expression for a given task I make it a Library Template to save having to work it out again for another Collection. In the explanations below I try to explain how the Regular Expressions work.

Placing the code in these examples in a Library Template rather than directly in individual Templates not only avoids having to re-construct somewhat complex code, it also allows any additional terms or edits to the code that are found useful as additional records are encountered to be automatically applied in all Templates calling the Library Template involved.

As described in the article mentioned above, Library Templates may include one or more fields by specifying them in "call" statement in the Text or Auto Type Template. That field is represented in the Library Template by a number in braces: "{1}, {2}, {3}, etc.

Descriptions of these Templates are below:

stripUSA:

Description:

Some Repositories are inconsistent, even in the same collection, in whether they include the country in a place name or not, and if so whether it is spelled out or various abbreviations are used. This inconsistency make writing Templates involving place names more difficult. This Library Template examines a place name and if the country name or an abbreviation for it are included removes it. The remaining part of the Text or Auto Type Template can then operate on the place name without having to account for a possible country element.

Type:

Library, intended for use with in a Text or Auto Type Template.

Use:

In a Text or Auto Type Template, call the Library Template using the "call" described in the second Comment Line, substituting the actual name of the field containing the place value for "place_fieldname." Place the call statement in the place in the Template where output of the place name without the possible country element is desired.

Template:

 

# Removes USA and variants from place fields

# Call as: [lib.stripUSA:place_fieldname]

[{1}:replace:[, ]+USA\b::i:replace:[, ]+United States.*::i]

 

How it Works:

The Template consists of a single Variable with :replace Transforms chained to find either the abbreviation "USA" or the name "United States." First, the Template replaces the "{1}" term with the value from the place Variable:

[{1}:replace:[, ]+USA\b::i:replace:[, ]+United States.*::i]

Next, it applies the :replace Transform to search for "USA", with a leading comma and/or space, and if found, replacing that string with nothing:

[{1}:replace:[, ]+USA\b::i:replace:[, ]+United States.*::i]

The :replace Transform, in green above, takes three parameters. The first, in yellow above, is the string that is being searched for. In this case it is ", USA". The " [, ] " term tells the Transform to search for a comma or a space, and the " + " following it says it must find at least one of them but there may be more. That is, either or both must precede the "USA" text. The " \b " term tells the Transform that the "USA" text must be at the end of a "word", that is not embedded in a longer word. This combination insures that "USA" will not be found if it occurs within a longer name, and causes a comma and/or space before "USA" will be included in the replace operation.

The second parameter, in pink above, tells the Transform what to replace the string found by the first parameter with. In this case it is empty. The string, if found, will be replaced with nothing. In other words, the text will simply be removed.

The third parameter is normally optional, but must be included here because another Transform is "chained" after the first. It is for flags that control some operations of the Regular Expression. In this case the "i" flag is used, to indicate that the expression should be insensitive to case; that the text may be either upper or lower case letters.

Then a second :replace Transform is used, to test for the string ", United States." It works the same as the first except for the string that is being searched for, and the instead of insuring that the test string is at the end as was the case in the first part, it includes any text after that string:

[{1}:replace:[, ]+USA\b::i:replace:[, ]+United States.*::i]

The term in blue above – " .* " – tells the Transform to search for any characters, zero or more times, and if found include them with the found string. This means in addition to ", United States" the replace function will find ", United States of America" and other variations starting with "United States". While some other countries sometimes include "United States" in their name, that is not a concern since I only use this Template for records from my home country.

If other forms of the country name or abbreviation are found in some records, additional instances of the :replace Transform can be added to remove them as well.

 

red text:

Description:

This Template is used to cause the text created by a Text Template to appear in red in the Control Panel. I use it for various notices or warnings created with Text Templates, in order to make them more noticeable.

Example Output:

Type:

Library, intended for use with in a Text Template.

Use:

In a Text Template, call the Library Template using the "call" described in the second Comment Line, substituting the actual name of a field containing the desired text, or the actual text to be used, for "text_or_variable." Place the call statement in the place in the Template where the desired output text is generated.

Template:

 

# Colors text produced by a Text Template red

# Call as: [lib.red text:text_or_variable]

\<span style="color:Red"\>{1}\</span\>

 

How it Works:

The Template creates an HTML <span> tag, then a CSS style to color the output text of the Text Template that calls the Library Template.

The Template first creates the opening and closing elements of a <span> tag using the appropriate HTML codes:

[\<span style="color:Red"\>{1}\</span\>

Because the opening and closing angle brackets that are part of the HTML code are also special characters to ORA, the must be preceded by the "escape" character - " \ ".

Next it applies the CSS codes to style the contents of the <span> tag as red text:

[\<span style="color:Red"\>{1}\</span\>

Finally, the Template replaces the "{1}" term with the text supplied by the "call" statement in the Text Template:

[\<span style="color:Red"\>{1}\</span\>

The Control Panel is displayed in a web browser, which interprets these codes to display the text in red.

 

notTwp:

Description:

In some states in the United States there are governmental structures within counties called townships. It is not uncommon for there to be cities or towns with the same name as a township in the same state, often in a different location. So it is important to identify whether the place is a township or a town or city of the same name. Images of original records generally show when a place is in a township, but some Repositories fail to include that information in the indexed place name, especially for census records.

I include a prompt in my census Templates to ask whether a place is a township, but that prompt can be annoying when the place is obviously not a township. This Template identifies locations that are obviously not townships based on key terms in the place name, or because the place is in a state where townships were not used.

Type:

Library, intended for use with in an Auto Type Template.

Use:

In an Auto Type Template, call the Library Template using the "call" described in the second Comment Line, substituting the actual name of a field containing place name for "place_fieldname." Place the call statement in a conditional statement so that if the Library Template returns "true" no prompt for township is created, but if it does not the prompt is issued.

For example if the name of the field contains the place is "Residence," a statement like this will ask the user to respond "Y" or "N" to the whether the place is a township if the Library Template was unable to make that determination:

<[lib.notTwp:Residence]|[==:Township Y or N]>

Then, at the point in the Template where the name of the locality in output, the following statement will add "Twp." if the place was a township:

<[?:Township Y or N=y] Twp.>

For an example of the use of this Template, see my article on an Example Census Source Template.

Template:

 

# Identifies a place as not a township by the presence of terms or states
inconsistent with townships

#Call as: [lib.notTwp:place_fieldname]

#searches for "ward" "district" "precinct" or "city" and if that fails then for a state known to not have townships in the place value; if either is found produces true

<[?:{1}:extract:(ward)|(district)|(precinct)|(city)]|[?:{1}:split:,:-1:extract:(Alaska)|(Arizona)|(Colorado)|(Delaware)|(Florida)|(Georgia)|(Hawaii)|(Idaho)| (Kentucky)|(Louisiana)|(Maine)|(Maryland)|(Massachusetts)|(Mississippi)|(Nevada)|(New Hampshire)|(New Mexico)|(Oregon)|(Rhode Island)|(Tennessee)|(Texas)|(Utah)|(Washington)|(Wyoming)]>

 

How it Works:

The Template searches for terms in the place name that indicate that the place was not a township. I have found that if the indexed name of a place includes the words "ward" "district" "precinct" or "city" it is not a township. If these key words are not found, it then examines the state to see whether the place is in a state that never used townships as governmental units. The searches are done with :extract Transforms applied to Value Test Variables using the value supplied by the calling Template

The entire template is part of an Alternatives Conditional structure so that if any of the terms are found the Template returns "true."

The Template makes two separate tests. The first, shown in green below, tests for the presence of the key words "ward" "district" "precinct" or "city":

<[?:{1}:extract:(ward)|(district)|(precinct)|(city)]|[?:{1}:split:,:-1:extract:(Alaska)|(Arizona)|(Colorado)|(Delaware)|(Florida)|(Georgia)|(Hawaii)|(Idaho)| (Kentucky)|(Louisiana)|(Maine)|(Maryland)|(Massachusetts)|(Mississippi)|(Nevada)|(New Hampshire)|(New Mexico)|(Oregon)|(Rhode Island)|(Tennessee)|(Texas)|(Utah)|(Washington)|(Wyoming)]>

First, the Template replaces the "{1}" term with the value from the place Variable:

[?:{1}:extract:(ward)|(district)|(precinct)|(city)]

Next, it applies the :extract Transform to that value, trying to extract any of the key words "ward" "district" "precinct" or "city":

[?:{1}:extract:(ward)|(district)|(precinct)|(city)]

The :extract Transform, in green above, has one required parameter, a Regular Expression specifying the string being searched for. In this case the expression for the string to be found are the text "ward" "district" "precinct" and "city". They are separated by the vertical bar to indicate that any one of them can be the search target. They are enclosed by parenthesis to tell the :extract Transform that each of them is a "capturing group" to be extracted if found.

In this case we do not actually want to capture the target text, but rather to test whether or not it was found. That is done with the Value Test Variable, as shown in pink below:

[?:{1}:extract:(ward)|(district)|(precinct)|(city)]

If any of the four key words are found, the Value Test Variable returns a value of "true" the Alternatives Conditional, show in blue below, will also return "true" and the Library Template returns "true" to the calling Template.

<[?:{1}:extract:(ward)|(district)|(precinct)|(city)]|[?:{1}:split:,:-1:extract:(Alaska)|(Arizona)|(Colorado)|(Delaware)|(Florida)|(Georgia)|(Hawaii)|(Idaho)| (Kentucky)|(Louisiana)|(Maine)|(Maryland)|(Massachusetts)|(Mississippi)|(Nevada)|(New Hampshire)|(New Mexico)|(Oregon)|(Rhode Island)|(Tennessee)|(Texas)|(Utah)|(Washington)|(Wyoming)]>

If the test for key words does not return "true" then the Alternatives Conditional moves on to evaluate the second segment of that Conditional, the test for state.

The second segment uses a :split Transform to find the name of the state within the place name:

[?:{1}:split:,:-1:extract:(Alaska)|(Arizona)|(Colorado)|(Delaware)|(Florida)|(Georgia)|(Hawaii)|(Idaho)| (Kentucky)|(Louisiana)|(Maine)|(Maryland)|(Massachusetts)|(Mississippi)|(Nevada)|(New Hampshire)|(New Mexico)|(Oregon)|(Rhode Island)|(Tennessee)|(Texas)|(Utah)|(Washington)|(Wyoming)]

The :split Transform requires two parameters. The first specifies the separator character between elements, in this case a comma, as shown in yellow above. The second tells which segment to capture. In this case it is set to "-1" indicating that the first segment, counting from the end, is to be captured, because the state will be the last element in the place name (the country already having been removed in the calling Template by use of the stripUSA Library Template).

Next the Template chains the :extract Transform, applying it to the result of the :split Transform, that is the name of the state:

[?:{1}:split:,:-1:extract:(Alaska)|(Arizona)|(Colorado)|(Delaware)|(Florida)|(Georgia)|(Hawaii)|(Idaho)| (Kentucky)|(Louisiana)|(Maine)|(Maryland)|(Massachusetts)|(Mississippi)|(Nevada)|(New Hampshire)|(New Mexico)|(Oregon)|(Rhode Island)|(Tennessee)|(Texas)|(Utah)|(Washington)|(Wyoming)]

The :extract Transform tests for any of the list of states that I have found do not use townships as place names. It works exactly like the :extract Transform used to test for key words as described above. If any of those listed are found the Value Test Variable, shown below in pink, returns "true":

[?::split:,:-1:extract:(Alaska)|(Arizona)|(Colorado)|(Delaware)|(Florida)|(Georgia)|(Hawaii)|(Idaho)| (Kentucky)|(Louisiana)|(Maine)|(Maryland)|(Massachusetts)|(Mississippi)|(Nevada)|(New Hampshire)|(New Mexico)|(Oregon)|(Rhode Island)|(Tennessee)|(Texas)|(Utah)|(Washington)|(Wyoming)]

If this segment of the Alternatives Conditional returns "true" the entire Conditional, and thus the entire Template, returns "true." If it does not, the Conditional, and the Template, returns "false" to the calling Template. The calling Template can then use this value to determine whether or not to prompt the user asking whether the place is a township.

 

cleanCity:

Description:

Place names, particularly census records, often include terms that are not towns or cities, or include terms that describe parts of cities, like wards. Such names properly describe the place for record purposes, and may be included in citations, but may not be helpful in narratives that are describing were people were located. This Library Template is intended to strip such place names to terms that describe places in terms understandable today, or example in census event records.

Type:

Library, intended for use with in a Text or Auto Type Template.

Use:

In a Text or Auto Type Template, call the Library Template using the "call" described in the last Comment Line, substituting the actual name of the field containing the place value for "place_fieldname." Place the call statement in the place in the Template where output of the modified place name is desired.

For an example of the use of this Template, see my article on an Example Census Event Template.

Template:

 

# Leaves City empty if only two parts to place field
# Leaves City empty if city contains "precinct"
# Extracts City & removes Ward & District details info

# Expects City to be in first split, comma delimited

#Call as: [lib.cleanCity:place_fieldname]

<[?:{1}:splitCount:,=2]|[{1}:split:,:1:replace: ward.*::i:replace: ?district.*::i:replace:.*precinct.*:]>

 

How it Works:

The Template is enclosed in a two-part Alternatives Conditional. The first part of the Conditional uses a Value Test Variable and :splitCount Transform to determine whether the place name consists of only two parts (assumed to be county and state).

First, the Template replaces the first " {1} " term with the value from the place Variable:

<[?:{1}:splitCount:,=2]|[{1}:split:,:1:replace: ward.*::i:replace: ?district.*::i:replace:.*precinct.*:]>

Next, it applies the :splitCount Transform to test whether the place name, when split into parts, has two parts:

{1}:splitCount:,

The :splitCount Transform, in green above, takes one parameter, the character that separates the parts, shown in yellow above. in this case the separator is a comma. The Transform returns the number of parts found. Then the Value Test Variable determines whether that count was two:

[?:{1}:splitCount:,=2]

This Value Test Variable consists of the question mark and colon, shown in green above, an expression that creates the value to be tested, in this case the field and :splitCount Transform, and the test to be made, in this case " =2 " as shown in yellow. If the place does have two parts the Value Test returns "true" and the Conditional is satisfied. The rest of the Conditional is ignored, and no output is produced. the "city" is left empty.

If there are more than two parts, the rest of the Conditional comes into play. It then replaces the second " {1} " term with the value from the place Variable, and a series of Transforms, chained together, are applied. The first is a :split Transform, to extract the "city" part of the place name:

[{1}:spit:,:1:i:replace ward.*::i:replace: ?district.*::i:replace:.*precinct.*:]

The :split Transform has three parameters here. The first, in yellow above, is a comma indicating that the separator of the parts is a comma. The second, in pink, is a one, indicating that the first part, the city name, is to be used. The third parameter is normally optional, but must be included here because another Transform is "chained" after the first. It is for flags that control some operations of the Regular Expression. In this case the "i" flag is used, to indicate that the expression should be insensitive to case; that the text may be either upper or lower case letters.

Next a :replace Transform is used, to remove the string "ward" together with any associated text:

[{1}:split:,:1:replace: ward.*::i:replace: ?district.*::i:replace:.*precinct.*:]

The next :replace Transform, in green above, uses a Regular Expression, in yellow, to define the string that is to be replaced. The expression starts with a space and the text "ward" indicating that the string must include that text with a leading space. Next is a period and an asterisk. The period term represents any character, and the asterisk means there may be zero or more of them. The term ward in a place name generally includes a number or some other label. This term is intended to include those characters in the searched for string.

The second parameter, in pink is empty, telling the Transform to replace the found string with nothing. Thus the "ward" and its leading space and any following text, are removed from the "city" name.

Next a second :replace Transform is used, to remove the string "district" together with any associated text:

[{1}:split:,:1:replace: ward.*::i:replace: ?district.*::i:replace:.*precinct.*:]

It works the same as the :replace Transform for "ward" except for the question mark after the leading space. This means the string searched for may include a space, but the question mark indicates that if there is no space before the next text that can be ignored. This string too, if found, is replaced with nothing by the empty second parameter in pink. Thus the "district" and its associated leading space, if any, and any following text, are removed from the "city" name. If there is nothing preceding the term "district" in the "city" name it will now be empty.

Finally a third :replace Transform is used, to remove the string "precinct" together with any associated text:

[{1}:split:,:1:replace: ward.*::i:replace: ?district.*::i:replace:.*precinct.*:]

It works the same as the :replace Transform for "district" except that it begins with a period and asterisk. This means that any number of characters before the text "precinct" will be included in the string being searched for. This string too, if found, is replaced with nothing by the empty second parameter in pink. Thus if the text "precinct" is found, the "city" name it will now be empty. Since this is the last Transform in the chain, the optional third parameter is not required.

 

cleanStreet:

Description:

I prefer to have the suffix of road or street names – "Street" or "Avenue" for example – entered in my database in a consistent style. My preferred style is to use my standard abbreviations for the more common suffixes. For example, I use "St." and "Ave." instead of spelling out those terms. This Template examines the street name as found in the record index and if they appear different than my preferred style, changes them to the way I like them.

Type:

Library, intended for use with in a Text or Auto Type Template.

Use:

In a Text or Auto Type Template, call the Library Template using the "call" described in the second Comment Line, substituting the actual name of the field containing the place value for "place_fieldname." Place the call statement in the place in the Template where output of the place name without the possible country element is desired.

For an example of the use of this Template, see my article on an Example Census Event Template.

Template:

 

# Replaces Street, Avenue or Road with abbreviation; adds period if missing

#Call as: [lib.cleanStreet:street_fieldname]

[{1}:replace:\bstreet:St.:i:replace:\bst$:St.:i:replace:avenue:Ave.:i
:replace:\bave$:Ave.:i:replace:road:Rd.:i:replace:\brd$:Rd.:i]

 

How it Works:

The Template consists of a single Variable with a series of :replace Transforms chained to find either the terms "Street", "Avenue" or "Road", or their shortened forms without trailing periods, and replace them with my standard abbreviations for those terms.

First, the Template replaces the "{1}" term with the value from the place Variable:

[{1}:replace:\bstreet:St.:i:replace:\bst$:St.:i:replace:avenue:Ave.:i
:replace:\bave$:Ave.:i:replace:road:Rd:i:replace:\brd$:Rd.:i]

Next, it applies the first :replace Transform to search for "street" at the beginning of a "word" and replace it with "St.":

:replace:\bStreet:St.:i

The :replace Transform, in green above, takes three parameters. The first, in yellow above, is the string that is being searched for. In this case it is "street". The " \b " term in front tells the Regular Expression that the text "street" must be at the beginning of a "word" and not embedded as part of a longer word.

The second parameter, in pink above, tells the Transform what to replace the string found by the first parameter with. In this case it is the text "St."

The third parameter is normally optional, but must be included here because another Transform is "chained" after the first. It is for flags that control some operations of the Regular Expression. In this case the "i" flag is used, to indicate that the expression should be insensitive to case; that the text searched for may be either upper or lower case letters.

Then a second :replace Transform is used to find the string "st" if it exists and replace it with "St." with a period.

:replace:\bstreet:St.:i:replace:\bst$:St.:i]

It works the same as the first :replace Transform except that the search term includes the " $ " at the end, meaning that the text "st" must be at the end of the string. Thus the text "St." with a period would not be replaced.

The remaining terms of the Template are pairs of :replace Transforms that work in the same way searching for and replacing the suffixes "Avenue" and "Road" and their period-free abbreviations.

CensusHe-She:

Description:

Creates Variables for subject and possessive pronouns and populates them with male, female, or plural pronouns based on fields in an Ancestry census record. The Variables are intended for use in a Template that produces narrative text for the the Memo of a Tag recording information from the census record.

Type:

Library, intended for use with in a Text or Auto Type Template.

Use:

In a Text or Auto Type Template, call the Library Template using the "call" described in the last Comment Line. No reference to field values is needed, as the Template uses the field names used in applicable census collections.

The Template creates the Variable [He-She] and populates it with "they" for married subjects, and "he" or "she" for unmarried subjects depending on the value in gender field. It also creates the Variable [His-Her] and similarly populates it with "their", "his" or "her".

The Variables created may then be used in the calling Template to create the desired output text. The call statement for the Library Template must be placed earlier in the calling Template than the point where the Variables are used.

For an example of the use of this Template, see my article on an Example Census Event Template.

Template:

 

# Creates the variables [He-She] and [His-Her] and populates them with
# "they" "he" or "she" and "their" "his" or "her" respectively.
# Those variables can then be used in the Templates.
# Designed for Ancestry US Census records for 1900 through 1950.
# Depends on the fields [Marital Status] and [Gender] being correctly indexed.

# call as: [lib.CensusHe-She]

<[?:Marital Status=Married][=:He-She:they]|[?:Gender=Female][=:He-She:she]|[=:He-She:he]>

<[?:Marital Status=Married][=:His-Her:their]|[?:Gender=Female][=:His-Her:her]|[=:His-Her:his]>

 

How it Works:

The Template consists of two separate three-part Alternative Conditionals, each generating one of the two Variables. The first Conditional creates the Variable [He-She] with a series of pairs of Value Test Variables and Assignment Variables. The first part tests whether the subject person is shown as married, and if so assigns the value "they" to the Variable:

[?:Marital Status=Married][=:He-She:they]

The Value Test Variable in green above tests whether the value in Marital Status field is equal to "Married". If it is, that Variable returns "true" and the Assignment Variable in yellow assigns the value "they" to the Variable [He-She]. If the Value Test Variable returns "true" the Conditional is satisfied, there rest of it is ignored, and the Template moves on to the second three-part Conditional.

If the first Value Test Variable does not return "true" the second part of the Conditional comes into play. It tests whether the subject person is shown as female::

[?:Gender=Female][=:He-She:she]

As with the first part, if the Value Test Variable returns "true" the Assignment Variable assigns the text "she" to the Variable [He-She], and the Conditional is satisfied. If it does not, the third part of the Conditional uses an Assignment Variable to assign the text "he" to the Variable [He-She], and the Template moves to the second Conditional. It works the same as the first except the values of "their" "her" and "his" are assigned to the Variable [His-Her].

 

ReigelRidge Home Terry's Tips Home Contact Terry

 

 

Copyright 2000- by Terry Reigel