Split text/string into its lines and filter on those to return subset or values
Created: 2009-08-19 17:23:13
When retrieving a URL or soemthing alike, one can often identify the region of interest as a single line. Besides the expected output, also some interim values, like the lines split are forwarded, to allow some straight-forward cascading of filters with reduced redundancy.
Preview
Run
Run this Workflow in the Taverna Workbench...
Workflow Components
Authors (1)
Steffen Möller <moeller@debian.org> |
Titles (2)
Splitting string to lines and filtering those |
Splitting string to pieces and their selection |
Descriptions (2)
This workflow represents the common pattern to splitting a string into fragments and to subsequently performs a selection of those strings. Here, the filtering is performed by lines, custom selections are not supported.
The lines into which the string was split are passed as output "lines". The lines matching the regular expression are presented as "filtered lines". If the regular expression also featured a group, i.e. ()s, then the values in the first of such group are returned as "filtered values". |
This workflow introduces to the splitting of a string into fragments and performs a subsequent selection of those strings.
The string constants are named almost like their contents, which should render it all more accessible to understand than the typical Dilbert-kind of example ... which basically does the same thing. |
Dependencies (0)
Inputs (2)
Name |
Description |
string_with_lines_to_be_filtered |
Some free text that is expected (but not required) to have multiple lines.
|
regex_to_filter_lines_for |
The regular expression that lines need to match in order to appear in the output list.
The regular expression that lines need to match in order to appear in the output list. Please ensure that your RegEx matches the whole string, not only a word or another substring of it.
|
Processors (5)
Name |
Type |
Description |
Filter_List_of_Strings_by_regex |
localworker |
Scriptfilteredlist = new ArrayList();
for (Iterator i = stringlist.iterator(); i.hasNext();) {
String item = (String) i.next();
if (item.matches(regex)) {
filteredlist.add(item);
}
}
|
line_separator |
stringconstant |
Value[\r\n]+ |
Split_string_into_string_list_by_regular_expression |
localworker |
ScriptList split = new ArrayList();
if (!string.equals("")) {
String regexString = ",";
if (regex != void) {
regexString = regex;
}
String[] result = string.split(regexString);
for (int i = 0; i < result.length; i++) {
split.add(result[i]);
}
}
|
Filter_list_of_strings_extracting_match_to_a_regex |
localworker |
Scriptimport java.util.regex.*;
filteredlist = new ArrayList();
Pattern thePat = Pattern.compile(regex);
int theGroup = Integer.parseInt(group);
for (Iterator i = stringlist.iterator(); i.hasNext();) {
String item = (String) i.next();
Matcher matcher = thePat.matcher(item);
if (matcher.find()) {
filteredlist.add(matcher.group(theGroup));
}
}
|
groupNo |
stringconstant |
Value1 |
Outputs (3)
Name |
Description |
lines |
|
filtered_lines |
|
filtered_values |
|
Datalinks (10)
Source |
Sink |
Split_string_into_string_list_by_regular_expression:split |
Filter_List_of_Strings_by_regex:stringlist |
regex_to_filter_lines_for |
Filter_List_of_Strings_by_regex:regex |
line_separator:value |
Split_string_into_string_list_by_regular_expression:regex |
string_with_lines_to_be_filtered |
Split_string_into_string_list_by_regular_expression:string |
Split_string_into_string_list_by_regular_expression:split |
Filter_list_of_strings_extracting_match_to_a_regex:stringlist |
regex_to_filter_lines_for |
Filter_list_of_strings_extracting_match_to_a_regex:regex |
groupNo:value |
Filter_list_of_strings_extracting_match_to_a_regex:group |
Split_string_into_string_list_by_regular_expression:split |
lines |
Filter_List_of_Strings_by_regex:filteredlist |
filtered_lines |
Filter_list_of_strings_extracting_match_to_a_regex:filteredlist |
filtered_values |
Uploader
License
All versions of this Workflow are
licensed under:
Version 2 (latest)
(of 2)
Credits (1)
(People/Groups)
Attributions (0)
(Workflows/Files)
None
Shared with Groups (0)
None
Featured In Packs (0)
None
Log in to add to one of your Packs
Attributed By (0)
(Workflows/Files)
None
Favourited By (0)
No one
Statistics
Other workflows that use similar services
(0)
There are no workflows in myExperiment that use similar services to this Workflow.
Comments (0)
No comments yet
Log in to make a comment