Solved

How to convert integer list to text values?

  • 5 April 2022
  • 9 replies
  • 65 views

Badge +7

I have an attribute that contains a string with 1 or more comma separated integers. The range of integers is 1 to 13. Here are some example values:

  • 10
  • 2,3,5
  • 7,8,9,10
  • 3,2
  • 5,6

I need to replace each integer with a text value that I've looked up from a table such as an Excel file. I know how to use the DatabaseJoiner to look up values, but I'm not sure how to process a list of lookup values. Ideally, I'd like to sort the integers before looking up the text values. For example, "3,2" would be "2,3" before the lookup. I'd also like the option of separating the text values with a new line character instead of comma.

 

Is what I'm trying to do possible with FME Desktop?

icon

Best answer by geomancer 7 April 2022, 12:06

View original

9 replies

Badge +2

@datablue​ You should be able to use the ListBasedFeatureMerger. Combined with the AttributeSplitter to create an FME list{} attribute from your list of values.

Example workspace attached (FME 2021.2)

Badge +7

@datablue​ You should be able to use the ListBasedFeatureMerger. Combined with the AttributeSplitter to create an FME list{} attribute from your list of values.

Example workspace attached (FME 2021.2)

Thanks for your response and example workspace. If the value of the intlist attribute is "2,3,4" then the new attribute (same record) that I'm looking for is "b,c,d" (from your example values). I think that I didn't explain this very well in my original question.

 

I will try to put together a sample project for this. Thanks.

Badge +7

Thanks for your response and example workspace. If the value of the intlist attribute is "2,3,4" then the new attribute (same record) that I'm looking for is "b,c,d" (from your example values). I think that I didn't explain this very well in my original question.

 

I will try to put together a sample project for this. Thanks.

Here is a sample data file.

Badge +7

Thanks for your response and example workspace. If the value of the intlist attribute is "2,3,4" then the new attribute (same record) that I'm looking for is "b,c,d" (from your example values). I think that I didn't explain this very well in my original question.

 

I will try to put together a sample project for this. Thanks.

And here's a look up table. Ideally, this can be in an Excel file or a single transformer. I may need to lookup 24 values.

 

I'm trying to create a workspace that uses the sample data to create a second attribute as follows. If sample data is "1,2,3" then new attribute is "one,two,three" with more examples below:

1 -> one

2,3 -> two,three

7,8,9 -> seven,eight,nine

3,2 -> two,three

 

If possible, it would be great to sort the integers before adding the text values as shown in the last line. I'd also like the option of separating the text values with a new line character instead of a comma.

 

One solution may be to duplicate the Integer_List attribute then search and replace, "1" with "one", "2" with "two" and so on. Hopefully, there's something a little more elegant.

Userlevel 4
Badge +36

Surely this can be done with FME Desktop.

One possible way, including sorting and new line characters, is shown below.

Numbers_to_Text_Sorted

Userlevel 4
Badge +36

Or, with the replacement of integers by text strings hardcoded in the StringPairReplacer:

Numbers_to_Text_Hardcoded

Badge +7

Or, with the replacement of integers by text strings hardcoded in the StringPairReplacer:

Numbers_to_Text_Hardcoded

Thank you! I have verified that both of these work. I still need to integrate everything into my main workspace. I'll do that next week.

Badge +7

Thank you! I have verified that both of these work. I still need to integrate everything into my main workspace. I'll do that next week.

I integrated two conversions (string of comma separated list of integers into string of comma separated text value) into my main workspace. My "customer" wanted comma separated instead of new line separated.

 

I made some changes to the StringPairReplacer. I had to get the strings to be replaced to include spaces. For example, instead of "six" I needed something like "my six." Adding quotes shown below worked fine. To make the replacement pairs more readable, I put one pair per line. I didn't realize that was possible. It's much more readable especially with longer strings.

 

Also, I noticed that you ordered the string pairs starting with 13 down to 1. I didn't know that was important. When I reordered my values like the following, I had an error.

  • 1 one
  • 2 two
  • 3 three
  • 4 four
  • 5 five
  • 6 "my six"
  • 7 seven
  • 8 eight
  • 9 nine
  • 10 ten
  • 11 eleven
  • 12 twelve
  • 13 thirteen

The error was that "10" needed to be converted to "ten" the result was "one0." I think that it found the "1" in "10" and replaced it with "one" resulting in "one0." I corrected the error by reordering the list starting with the highest value first.

 

Thank you for your solution.

Userlevel 4
Badge +36

Thank you! I have verified that both of these work. I still need to integrate everything into my main workspace. I'll do that next week.

I'm glad to see my solution worked for you.

Thank you for your detailed description. You taught me something new today: I didn't know about the quotes (like "my six"), or the possibility to spread the replacement pairs over several lines. These possibilities are not currently mentioned in the documentation.

Reply