Skip to main content

Hello everyone,

I am using the StringPairReplacer to find and replace short codes with their corresponding fulltext from a string that may contain multiple codes. It looks something like this

A1, A2(A3), A4 → Fulltext1, Fulltext2(Fulltext3), Fulltext4

with the Replacement Pairs: A1 Fulltext1 A2 Fulltext2 A3 Fulltext4 A4 Fulltext4 

This works fine, however the lookup table containing codes-fulltext translations may change in the future and I would like to implement a dynamic solution which doesnt rely on changing the workspace everytime something changes in the translation. 

I managed to create the correct text for the replacement pairs field using the SQL Creator from my translation database but am having trouble inserting this string into the appropriate field as it only accepts text and user parameter input. 

I am not too familiar with user parameters and cant seem to work out a solution to insert the dynamically created string into the StringPairReplacer.

Does anyone have an idea how to do this?     

I should be able to provide an example later on, if nobody else obliges in the meantime.


Deleted


I’ve taken the request to mean multiple string replacements within a single attribute. @pkno can you clarify?

The process I’ve previously used involves the TCL caller which isn’t available in 2024.1 onwards

 


Does the pattern come from the feature itself or does it come from a global user input?

Could you make a small example with your current situation, and may be something you allready tried? I have a hard time to see what the problem is.


Thank you all for responding. Here is some more info to clarify my request.

@ebygomm

Yes, exactly. The strings I am trying to replace (remap to fulltext equivalents) are stored in a single attribute. Based on the feature, the attribut can require one or multiple replacements.

 

@jkr_wrk

The pattern (e.g. A1, A2(A3), A4) comes from the feature itself. A quick example could look something like this

id string
1 A1, A2(A3), A4
2 A6, A1(A4(A12)), A2-A5

 

with the desired transformation to

id string
1 Fulltext1, Fulltext2(Fulltext3), Fulltext4
2 Fulltext6, Fulltext1(Fulltext4(Fulltext12)), Fulltext2-Fulltext5 

 

these are obviously fillers, but the idea should be clear. What succesfully works is the StringPairReplacer transformer with the caveat that all lookup values are stored in the transformer itself. What I want is to get those values dynamically from a database. The following query in SQLCreator outputs a string which should work as  a valid input for the replacement field input of the transformer and also takes into account possible spaces in the fulltext values:
 

select string_agg(stringpairs,' ') 
from(
    select string_agg(concat(short, ' ',replace(fulltext,' ','_')),' ') as stringpairs
    from table
    group by short, fulltext
    order by length(table.short) desc
    )

What I wasnt able to do is to use that as input for the StringPairReplace transformer. 

Thank you all.


You can read the replacement pairs from the database in one workspace, and pass them on to a User Parameter of a second workspace that contains the StringPairReplacer. You start the second workspace from the first workspace using WorkspaceRunner in FME Form or FMEFlowJobSubmitter in FME Flow.

 


Note: the order of the replacement pairs is important!

In your example you have an abbriviation A12. Make sure that replacement happens before the replacement of A1, as the replacement of A1 will process A12 as well.

A10 Fulltext10
A11 Fulltext11
A12 Fulltext12
A1 Fulltext1
A2 Fulltext2
... ...

 


Thank you @geomancer 

Based on your idea, I believe I found a solution that works within a single workspace. The one concession I had to make is, that I need to write a temporary text file which contains the replacement pairs. 

Essentially I create this file using the SQLCreator and a writer transformer.

I use this writer as initiator for my database reader to ensure the file is written before the replacement takes place. The file is transformed via a user parameter/scripted parameter value into a string that I can use as input for the StringPairReplacer.   


Reply