Skip to main content
Solved

Query if list of terms are present in a text attribute of a CSV file; if present add a value to a new field


Hello, I'm new to FME and want to work out which transformers can be used for this task. I need to query a text field held in a CSV file against a list of values (text) stored in a separate CSV. If these values are present I would like to add a value of '1' to a new field in the CSV.

I'm sure this is very basic but would be grateful for any assistance!

Chris

Best answer by nielsgerrits

I think I understand you want to know if a string contains one or more words from a list?

You can do this with a StringSearcher and a regex like suggested here.

Depending how dynamic this needs to be, I would:

  • Read the list of words in a seperate stream, merge those words to one feature using a Aggregator, Attributes to Concatenate: "words", Seperator Character: "|".
  • Create Regex with an AttributeCreator and concatenated words. (?:^|(?<= ))(@Value(Words))(?:(?= )|$)
  • Merge regex to all string features using a FeatureMerger, requester and supplier = 1 to match all suppliers to all requestors. Regex being the supplier stream.
  • Check for matches using the StringSearcher.
View original
Did this help you find an answer to your question?

2 replies

nielsgerrits
VIP
  • Best Answer
  • August 13, 2021

I think I understand you want to know if a string contains one or more words from a list?

You can do this with a StringSearcher and a regex like suggested here.

Depending how dynamic this needs to be, I would:

  • Read the list of words in a seperate stream, merge those words to one feature using a Aggregator, Attributes to Concatenate: "words", Seperator Character: "|".
  • Create Regex with an AttributeCreator and concatenated words. (?:^|(?<= ))(@Value(Words))(?:(?= )|$)
  • Merge regex to all string features using a FeatureMerger, requester and supplier = 1 to match all suppliers to all requestors. Regex being the supplier stream.
  • Check for matches using the StringSearcher.

Thank you, Niels - that has done exactly what I needed to do! Much appreciated. Chris


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings