URL manipulation

Hi there,

i need help to create a workflow to read or get some restful resources
i have many URL as String the different between them is only in one term
like

www.host.domain/xxx where xxx is placeholder
www.host.domain/yyy where yyy is placeholder
www.host.domain/zzz where zzz is placeholder

the question ist how can i replace the last part of each URL
with the suitable value

xxx = first_value
yyy = second_value
zzz = third_value

where first_value != second_value != third_value

replace the placeholder with the suitable String ?

i look for some Nodes to solve this problem but all of them work with
only one placeholder for all rows in one columen but not multiple

thanks for helping me

Raed

Hi,
not sure if i fully understood your intended outcomes, however the string manipulation node allows you to concatenate column values, , so itā€™s a matter of preparing a table with a domain column and whatever values you have.

If you have an example of the source data and the intended outcome we could help further.

Gavin

Hi Gavin_Attard

thanks alot for your answer
i mean i have many (N) URL the difference is only in one mini String
is there any (one) Node to fill with www.host.domain/* the next Node
shall replace the * sign with the suitable String ?

Node 1 has one row --> www.host.domain/*
Node 2 has 3 rows

xxx
yyy
zzz

through the iteration in the second Node will build the whole URL ?
then with Get Request Node read each URL resource.

Get_Restful_Resource

the problem all Nodes for manipulting a String could replace one and only one sign (*) in many rows
what if i have many different signs need to replace them with different String?

Java Snippet has the following code:

String url = $column0$;
if (url.contains(ā€œaspā€)){
return url.replace(ā€œaspā€, ā€œaspirinā€);
}else if (url.contains(ā€œgluā€)){
return url.replace(ā€œgluā€, ā€œglucoseā€);
}else{
return url;
}

Ok, i think i get you, you want a kind of ā€˜Find and Replaceā€™ node, that can iterate through all possible values in the string and replace accordingly.

You can use a series of String Replacer nodes. Itā€™s easier to manage than a java snippet.

You can also try looping around this to iterate around a number of find replace terms.

Hi Gavin_Attard

thanks alot as i know each Replacer Node can replace only one sign thats mean for each
String i need one Replacer Node ? (String Replacer Dictionary may be is the solution)
i muƟt have a better look at how to iterate through Strings with Knime Node ?

if you have any Workflow it will be nice in any case thank you so much.

Raed

Yes i was thinking one node per string to replace.

The string replace dictionary could also work, Iā€™ve not used it before so not certain on the outcome.

A task like this almost needs a hybrid as you may want to build the ā€˜dictionaryā€™ in flow rather than write to a fileā€¦ the read againā€¦

Iā€™d give it a go see what happens.

Hello Gavin_Attrad

thanks alot again i will try some Nodes may be get a solution thank you so much for
your helpful discussion.

Raed

Hello @Raed,

welcome to KNIME Community!

Can this be a job for Rule Engine node and LIKE operator?

URL_column LIKE ā€œ*aspā€ => ā€œaspirinā€
URL_column LIKE ā€œ*gluā€ => ā€œglucoseā€
ā€¦
TRUE => URL_column

Then use String Manipulation node and join() function to have URL you want.

Br,
Ivan

1 Like

Hi Raed

I think this should do what you are after.
find-replace.knwf (37.0 KB)

Similar to your idea of using the java snippet, in this case, i used a lookup table. The values are ā€˜groupedā€™ into a list,then appended to each row.

The java snippet then loops through each list value replacing as necessary.
It is quite crude, but should do the job

1 Like

Hello Gavin_Attard

very nice i tried with String Replacer(Dictionary) but it does not work canā€™t replace part of URL
it replaces the whole URL but not a sign like * or ?

i will download your workflow and test it thanks alot.

Hello @ipazin,

i need to create 3 Nodes the suggestion with Rule Engin was OK it filters the String but i am not sure if the String Manipulation Node would be work with more than one expression because i got canā€™t complie Error ?

you need a semicolon after each line

Hi Gavin_Attard

of course i do that after each line but i get an Error ?

have you tried the workflow i sent you yet?

Hi Gavin_Attard

i get an Error i think because i am using Knime 4.1 may be your workflow for 4.2 ?

Yes correct i am on 4.2

Hi @Raed,

This is what I had in mind:
2020_07_21_String_Repalcement.knwf (12.9 KB)

Though still not sure what your input data structure is together with desired outputā€¦

In String Manipulation node you can not have multiple expressions.

Br,
Ivan

Hello @ipazin

if i have the follwing URL

https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/name/**asp**/cids/TXT
https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/name/**glu**/cids/TXT

i need to change (Replace)

asp => aspirin
glu => glucose

i think your workflow works only if you want to replace the END of any URL but not the middle of it ?

best regards

Hi @Raed,

then you need to modify it a bit :wink:
2020_07_21_String_Repalcement.knwf (12.8 KB)

This would be a use case for Cell Replacer with some wildcard/regex support.

Br,
Ivan

Hello @ipazin

really i am new user of Knime but i need some help to cope with it or learn about the nodes and what each one does