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

  • August 12, 2021
  • 2 replies
  • 93 views

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.
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

nielsgerrits
VIP
Forum|alt.badge.img+60
  • 2938 replies
  • 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.

  • Author
  • 1 reply
  • August 20, 2021

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