Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
C++CodeDelphi

Easily Manipulate Text With The FlashText Python Library In A Delphi Windows App

We know how to search or replace text in our Delphi/C++ Builder using Regular Expressions. Similarly, Python’s standard library and some other low-level modules help to search or replace text using Regular Expressions. However, to perform the search or replace keywords in documents at scale from within Python, the performance of python standard library regular expressions is not fast enough. To solve this, a high-performance Python Library FlashText is available. In this post will get to understand how to use FlashText using Python4Delphi in the Delphi/C++ application for Python GUI apps.

Delphi itself offers fast processing of text via the TRegEx object. If you have an existing Python application and you need faster text processing you could use FlashText or you could bring the text over to Delphi via Python4Delphi and process the text from inside Delphi itself. You can use Python4Delphi a number of different ways such as:

  • Create a Windows GUI around you existing Python app.
  • Add Python scripting to your Delphi Windows apps.
  • Add parallel processing to your Python apps through Delphi threads.
  • Enhance your speed sensitive Python apps with functions from Delphi for more speed.

Prerequisites.

  • If not python and Python4Delphi is not installed on your machine, Check this, how to run a simple python script in Delphi application using Python4Delphi sample app
  • Open windows open command prompt, and type pip install -U flashtext to install FlashText. For more info for Installing Python Modules check here
  • First, run the Demo1 project for executing Python script in Python for Delphi. Then load the script in the Memo1 field and press the Execute Script button to see the result. Go to GitHub to download the Demo1 source.

FlashText Python Library sample script details: The sample script demonstrates,

  • How the Extract or replace keywords in the documentation.
  • Extract case sensitive, a span of keywords, get extra information for the keyword extracted.
  • Add Multiple keywords simultaneously, remove keywords.
  • To check the Number of terms in KeywordProcessor and if the term is present in KeywordProcessor. Get all keywords in the dictionary.
flashtextdemo 8207167
<strong>FlashText Python Library Demo<strong>

Note: Samples used for demonstration were picked from here with only the difference of printing the outputs. You can check the APIs and some more samples from the same place.

You have read the quick overview of flashtext library, download this library from here and perform a high-performance search or replace keywords in your applications. Check out Python4Delphi and easily build Python GUIs for Windows using Delphi.

See What's New in 12.2 Athens See What's New in 12.2 Athens Dev Days of Summer 2-24

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES