Openrefine: Enhancement : a contains() that support regex

Created on 26 Mar 2018  路  5Comments  路  Source: OpenRefine/OpenRefine

Issue #1550 shows that a contains() function that accepts Regex might be useful. Now that @jackyq2015 has coded the find() function, looks like even a complete beginner would be able to draw on his code to enrich contains(). Could it make a "good first issue" ?

enhancement good first issue

Most helpful comment

Hi ,
As my first issue, I'd like to take this one.
I already tried to implement it, this looks like this :
image

Before rushing into (my also first) PR I'll check the whole process before doing so (test code, documentation? )
And is it what you requested ?
It will work like the partition method second argument, meaning that contains(string s, string sub) will become contains(string s, string or regex sub)

Thank!
Maxime

All 5 comments

Hi ,
As my first issue, I'd like to take this one.
I already tried to implement it, this looks like this :
image

Before rushing into (my also first) PR I'll check the whole process before doing so (test code, documentation? )
And is it what you requested ?
It will work like the partition method second argument, meaning that contains(string s, string sub) will become contains(string s, string or regex sub)

Thank!
Maxime

Hi Maxime @gobertm - sounds great!

What I find useful when looking at adding functionality like this is to have a list of test cases and what the expected outcome would be. This is useful in terms of communicating how the function will work, and also gives you a set of test statements you can include in your unit tests for the functionality.

In this particular case where you are changing an existing function please make sure (and add test cases if they don't already exist) that the function continues to work as expected when used as currently intended.

Hi,

(had a few days off).
I created PR #1558 .

I can not find any particular test on this function.
I tried creating mine, with simple line such as :
Assert.assertEquals(invoke("contains", "it contains", "con"),true);
Assert.assertEquals(invoke("contains", "123contains", "\\d{3}"),true);

but it seems I have to include a special evaluation function (something with Evaluable object) in order to interpret the regular expression. I do not fully get this mechanism yet. So I created the PR as is. And look forward your input.

Regards,
Maxime

Hi @gobertm , here is the complete Jacky's PR for the find function, this can perhaps be used as a model.

@ettorerizza thanks! This is better. I rushed with the partition function implementation..
Test case works now.

Was this page helpful?
0 / 5 - 0 ratings