Any Way to Use Regular Expressions to Change Case of Specific Words
I've got a requirement to change the appearance of articles and prepositions in words in a column to be displayed as lowercase after running a Title Case on the rest of the phrase. Right now, I have an extensive list of text replacements in Magic ETL to do this, but I was wondering if there might be a way to do this with a regular expression that just lists the words I'm looking for and only converts those to lowercase. Here's a screenshot of the mess I currently deal with:
You can do this in a MagicETL. The best way I've found to do this is using the Python Scripting Block. In the example I put together for you, I wanted to make it simple to configure which words end up capitalized without having to reconfigure my ETL every time I want to add a new preposition. In the design pattern below, I just used a Domo Webform to store a list of my words so all you need to do is pop new values into it.
1) There are 2 data sources in this ETL. The first is a table containing rows of articles text. The second is my dataset of prepositions.
2) Connect both sources to a Python Scripting block and add the python code shown in the screenshot at the bottom of this post.
3) Make sure you change any references of 'Articles' or 'Prepositions' to match your dataset names. Then, change 'ArticleText' in the code to whatever the column name is in your articles dataset.
4) Once you make sure all dataset name and column name references match your existing datasets, run a preview and check the 'SCHEMA' tab on the Python Script block to ensure it's properly picking up the output schema.
You'll notice a simple capitalise() function. All it does is take your prepositions dataset and convert it into a list. Then it takes your article dataset and converts the article text itself into a list. It then goes through your article text and checks to see each word is in your prepositions list. If it is, it capitalises it with the title() function. If not, it leaves that word unmodified.
What you are left with is an output dataset where the article text has your prepositions capitalized because we've run a pandas apply() function to your article data and telling it to execute the capitalise() function on your data.
Edit: I just realized you wanted to opposite of capitalizing, and instead lowercasing your prepositions. Thats easy enough to do by changing the "v.title() if v in list..." to "v.lower() if v in list..."
Apologies for the mix up! This should still get you 99% of the way there. I hope this helps! :)
Final ETL Output
Notice all instances of and, to, from, the, with are now all capitalized1
Thanks so much for the comprehensive suggestion @bobbyragsdale - I'll give this a try in our environment!0
@pstrauss You're very welcome! If you try it out and get stuck or need any guidance please feel free to message me directly and I'll help where I can. If you implement it successfully, a quick follow-up here would be greatly appreciated as well. I'm just trying to be mindful of others who might find this technique useful and wonder if the solutions proposed are worth their time.0
- 7.6K All Categories
- 914 Connectors
- 241 Workbench
- 470 Transform
- 1.8K Magic ETL
- 60 SQL DataFlows
- 445 Datasets
- 24 Visualize
- 194 Beast Mode
- 2K Charting
- 6 Variables
- 14 Cards, Dashboards, Stories
- 1 Automate
- 348 APIs & Domo Developer
- 82 Apps
- 14 Predict
- 3 Jupyter Workspaces
- 11 R & Python Tiles
- 241 Distribute
- 59 Domo Everywhere
- 241 Scheduled Reports
- 14 Manage
- 35 Governance & Security
- 18 Product Ideas
- 1.1K Ideas Exchange
- Community Forums
- 15 Getting Started
- 1 Community Member Introductions
- 49 Community News
- 18 Event Recordings
- 579 日本支部