Exercise 3.2 Locating Transformers
Data 3-1-1 case location details (XLS hosted on the web)
Overall Goal Find a transformer to fix inconsistent data
Demonstrates Using Transformer Gallery and Quick Add
Start Workspace C:\FMEData2019\Workspaces\IntroToDesktop\Ex3.2-Begin.fmw
End Workspace C:\FMEData2019\Workspaces\IntroToDesktop\Ex3.2-Complete.fmw

In Exercise 2.2, we found that some of our values for the Local Area attribute were inconsistent. In this exercise, we will find an appropriate transformer to address this problem. As we just covered, there are many options for searching for transformers. In this case, we need a transformer that can find specific text strings in an attribute and replace them with another value. Specifically, we want to find values of Local Area and replace them as such:

Find Replace
Dunbar Southlands Dunbar-Southlands
Arbutus Ridge Arbutus-Ridge

We could use any of the resources available (Transformer Gallery in Workbench, Transformer Gallery online, the FME Transformer Reference Guide, and Quick Add search) to find such a transformer.

1) Examine Transformer Gallery Categories

Go to the FME Transformer Gallery and click the category drop-down menu:

Which category do you think we might need to look in? We are trying to modify the values of an attribute, so it makes sense to start our search in the Attributes category. Select Attribute from the drop-down to filter by these transformers.

Well, that's a good start, but there are still 30 transformers in this category. We could go through one-by-one and read each description until we find the right one, but that would take too long. Instead, we should search for some keywords that describe what we want to do.

Try searching for these terms:

  • Find
  • Replace

These terms don't yield any transformers in this category. Maybe we should try a different approach.

2) Try a Different Category

Is it possible that our transformer might be in a different category? Return to the drop-down and take a look. There is a Strings category! That could work, since we are trying to modify a text (i.e., string) value. Select the Strings category.

This category has even more transformers in it: 43! But let's try searching transformers in this category with our keywords again:

  • Find
  • Replace

"Find" results in the ListSearcher, which searches lists (a special kind of attribute value), not attributes, so that won't work.

"Replace" results in three transformers:

  • StringReplacer - Replaces substrings matching a string or regular expression in the string contained in the source attribute.
  • StringPairReplacer - Replaces characters in the value contained in the source attribute based on replacement key-value pairs.
  • CharacterCodeReplacer- Sets the result attribute to the character whose numeric code was contained in the source code attribute (or the entered integer).

It sounds like either of the first two will work! As an experienced FME user, I know that either will work, but the StringReplacer will be a bit more straightforward, so let's use that transformer.

FME Lizard says...

There are often multiple solutions to a given problem in FME. We could accomplish the same result by using:

Did you find another way? Congratulations! Please let us know at train@safe.com.

3) Start FME Workbench

Now, let's add the StringReplacer transformer to our workspace.

Start FME Workbench (if necessary) and open the workspace from Exercise 3.1. Alternatively you can open C:\FMEData2019\Workspaces\IntroToDesktop\Ex3.2-Begin.fmw.

4) Add a StringReplacer

Add a StringReplacer to the canvas between the AttributeManager and the writer feature type by clicking the feature connection line and typing in StringReplacer to view it in Quick Add, then hitting enter:

Once it is added, double-click it to open its parameters. This transformer requires you to choose an attribute to modify, and then supply a string for Text to Replace (i.e., find) and Replacement Text (i.e., replace). You can also specify what happens to values that don't have a match, which defaults to <No Action>. The source values in the incoming data are replaced by any matching output values, or otherwise receive a default value.

As you can see, because we can only enter a single find and a single replace value, we will have to use two StringReplacers, one for each data problem.

Fill in the parameters like this:

Parameter Value
Attributes Local Area
Text To Replace Arbutus Ridge
Replacement Text Arbutus-Ridge

We will replace any values with a space to those with a dash - this fits the City of Vancouver specification.

Your dialog should look like this:

Click OK.

5) Add Second StringReplacer

We can add another StringReplacer by right-clicking our first and clicking Duplicate or using the shortcut Ctrl + D:

Now we need to connect it to the data flow. Click and drag your second StringReplacer; you will notice a small green arrow in the top left corner. Move this arrow over the feature connection line between the first StringReplacer and the writer feature type. You will see the feature connection line is highlighted. Release your click to attach the transformer at that point:

Double-click the second transformer to open its parameters. We can leave some of the parameters from our first transformer, but make sure you change the following:

Parameter Value
Text To Replace Dunbar Southlands
Replacement Text Dunbar-Southlands

Once you have filled those in, click OK.

6) Save Workspace

Save your workspace regularly.

7) Inspect Result

Now let's inspect our data to confirm we've fixed the problem. Click the second StringReplacer to select it, and then click Run To This:

Once the cache is loaded, click the second StringReplacer to open it in Visual Preview. We can use the same procedure from Exercise 2.3 of searching our Table View to confirm our data has changed. Type our original values ("Arbutus Ridge" and "Dunbar Southlands") into the search bar in the bottom left of the Table View to search for them. They should both yield zero results, whereas if you search for the version with the dash, you should get 2,236 and 4,062 results, respectively:

By completing this exercise, you have learned how to:
  • Search for a transformer using the online Transformer Gallery
  • Use a StringReplacer to fix inconsistent data values

results matching ""

    No results matching ""