-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 2 new GREL functions for replacing strings matching a search list #2606
Comments
I also noticed that Apache StringUtils.replaceEach() does expect the lengths of the arrays to be the same size, otherwise it throws IllegalArgumentException. Its
For our own GREL function of its implied "index mapping" shown:
but our proposed GREL
Something to discuss, for sure. |
Let me check this out |
Is your feature request related to a problem or area of OpenRefine? Please describe.
Currently we do not have a nice single replace() function that takes a List of Strings as an argument to search for in a String and replace any found match with a replacement character.
We have to resort to use of cross() or forEach() with inArray() to perform the lookup/inspection of a List or Array and then perform our String replacement.
Mailing list thread comment:
https://groups.google.com/d/msg/openrefine/XIfKTL6sv0w/BjUedqn0AgAJ
GIVEN: 2 columns where column A has the string we want to replace when a list of substrings are found.
AND: column B has a list (or can be split into an Array) of those substrings to search for
AND: and when matching,
THEN: replace ANY matching substring in our column A with a single replacement value like "" empty string or whatever the user desires.
The following GREL performs this:
however, it is very verbose.
Describe the solution you'd like
Instead we can probably simplify this large expression to something like this that takes as an argument (a list of strings to search for) and those that match get replaced with a replacement char.
Describe alternatives you've considered
headaches and more coffee and continue with GREL snakes.
Additional context
Apache StringUtils seems to have already 2 nice functions to help
replaceEach()
andreplaceEachRepeatedly()
:http://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html#replaceEach-java.lang.String-java.lang.String:A-java.lang.String:A-
... as well as many "index" methods.
Example Problem OpenRefine Project with provided "GREL snake" current solution:
vidal_santos.openrefine.tar.gz
The text was updated successfully, but these errors were encountered: