Start a new topic

Dictionary: if non of the above, then exception

Hi all,

Probably this is a stupid question, but I can't find the answer.
I want to match certain values to a new value via a dictionary, but if I have a value that is not defined in my dictionary, the record should go to exceptions. Could someone please explain how to do this?

For example:
Replacement value 1 = "Accordeon", values to match on "a"
Replacement value 2 = "Ball", values to match on "b"
Replacement value 3 = "Cricket", values to match on "c"
When I have value "d" (or anything else) in my file (value to match on), the record should go to exceptions. I would like to have a solution where you don't say "not a, b or c" because the actual list is too long and contains too much regular expressions.

Could someone please help me with this?
Thank you in advance,
Ann

This is quite tricky but you can use the "cascading" effect of dictionaries to accomplish this.

The cascade effect simply means that each expression is tried in order using the output of the previous row.

Example Dictionary

image

Logic

The logic is that first, it will replace the match with the intended value pre-pended with : to mark it as having been replaced.

Then, second to last, it will take anything that does NOT start with : and make it an error. 

Finally, it removes the : to make the correct intended value.

NOTE: ORDER IS VERY IMPORTANT HERE.  THE LAST TWO LINES MUST STAY AS THE LAST TWO LINES NO MATTER HOW MANY COME BEFORE!

Examples

Input: a

1) a -> :Thing1

2) (no match)

3) (no match)

4) (no match)

5) :Thing1 -> Thing1

 

Input: d

1) (no match)

2) (no match)

3) (no match)

4) d -> ERROR

5) (not reached)


Thank you, this works!


Is there a way to move values up or down in the replacement values list so I can make sure the last 2 stay the last ones?
You should use the "paste from excel spreadsheet" function.  That way you can lay it out however you want and add rows as needed.

 

Login or Signup to post a comment