String replace (Dictionary) problem

Hi,

I am wondering why String replace (Dictionary) is not working with attached example!

The example text is following:
D:\Download\Test\BAADER BANK reported that XYZ - (Abcc) - 2020-06-04 1958.eml

and I would like to have only
Column1 Column2 Date
BAADER BANK XYZ 2020-06-04 1958

I also tried with encoding the slashes (e.g: D%3A%5CDownload%5CTest)

Test.knwf (10.0 KB)
Dictionary_StringRemoval.txt (42 Bytes)

Best,
Mateen

Hi Mateen,

The cell is compared against the keys in the dictionary file and - given that a matching key is found - the cell content is then replaced by the value of the respective dictionary entry.

AFAIK, the String Replace (Dictionary) compares the complete cell content and replaces it. It does not look out for partial matches. That said, it behaves different to its potential counterpart String Replacer that allows to define wildcard patterns and regular expressions.

I am not aware of a node that directly reads from a dictionary file and replaces partial matches in a cell.

I see a couple of potential workarounds:

  1. Manually create a regular expression based on your replacement rules (provided as file) and use it once in the String Replacer.

  2. Use a combination of String Replacer in combination with looping nodes (to apply each rule individually) – you probably need Table Row To Variable Loop Start/Loop End for applying multiple patterns in a loop and Recursive Loop Start/Recursive Loop End for passing the same string over and over again.

Maybe one of our more knowledgable forum users has an already working solution available or a way to solve this with even less nodes.

Best regards,
Daniel

2 Likes

Hello there!

isn’t this a job for Regex Split node?

Br,
Ivan

1 Like

Yeah. That took me also by surprise :slightly_smiling_face:

1 Like

Hi @mateenraj,

not sure I follow. Check node description and examples in it to see how Regex Split works.

Br,
Ivan

I hope Knime Devs up their game with the string nodes. A proper string replacer dictionary node is needed. I deal with a lot of scraping data and Knime was a godsend but I honestly struggle with string manipulation when I need to do some bulk operations.

Many times I end up using SQL which was one of the things that I was trying to avoid.

1 Like

Can you give examples?

I’m probably going to do this through SQL: Replace ~8000 terms in forum DB extraction (NickName Anonimization)

UPDATE table SET Body = REPLACE(Body,'old_nickname','new_nickname') WHERE Body LIKE '%old_nickname wrote:%';

Even with my poor SQL Skills I can run this piece of SQL code 8k times with SQLite or DuckDB, but would be a PITA to do in Knime because the dictionary replace is too limit, or I just have to use some Wizardry with Loops and so on.

I mean, Knime Desktop is free, I’m very grateful for it, but I really really carve for proper text manipulation, it feels clunky currently. My needs are not that common anyway.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.