DelphiPythonPython GUIWindows

Quickly Build A Python GUI Apps For Replacing And Extracting Keywords In Sentences Using FlashText Library In A Delphi Windows App

pexels tima miroshnichenko 5380590

Do you want to perform Natural Language Processing tasks like replacing or extracting words in a text, in your GUI app? This post will get you to understand how to use FlashText Python Library using Python4Delphi (P4D) in the Delphi/C++ Builder application and perform some interesting NLP or Regular Expressions-like tasks. 

FlashText is a module that can be used to replace keywords in sentences or extract keywords from sentences. It is based on the FlashText algorithm.

FlashText algorithm is an algorithm for replacing keywords or finding keywords in a given text. FlashText can search or replace keywords in one pass over a document. 

 

1. FlashText vs other Algorithms

The time complexity of this algorithm is not dependent on the number of terms being searched or replaced. For a document of size N (characters) and a dictionary of M keywords, the time complexity will be O(N). This algorithm is much faster than Regex, because regex time complexity is O(MxN). 

FlashText is also different from Aho Corasick Algorithm, as it doesn’t match substrings. FlashText is designed to only match complete words (words with boundary characters on both sides). For an input dictionary of {Apple}, this algorithm won’t match it to ‘I like Pineapple’. This algorithm is also designed to go for the longest match first. For an input dictionary {Machine, Learning, Machine learning} on a string ‘I like Machine learning’, it will only consider the longest match, which is Machine Learning. 

The Python implementation of this algorithm was created by Vikash Singh and available as open-source on GitHub, released under the permissive MIT License.

 

2. Run FlashText with Python4Delphi

This post will guide you on how to replace and extract keywords in sentences using Python’s FlashText and then display them in the Delphi Windows GUI app.

First, open and run our Python GUI using project Demo1 from Python4Delphi with RAD Studio. Then insert the script into the lower Memo, click the Execute button, and get the result in the upper Memo. You can find the Demo1 source on GitHub. The behind the scene details of how Delphi manages to run your Python code in this amazing Python GUI can be found at this link.

0 rundemo1 6813476

Let’s perform some introductory examples of FlashText library, like keyword extraction, replacing keywords, and case sensitive example:

The result in Python GUI:

1 2691391

 

Congratulations, now you have learned how to replace and extract keywords in sentences using Python’s FlashText and then display them in the Delphi Windows GUI app.

Check out the FlashText library for Python and use it in your projects: https://pypi.org/project/flashtext/ and

Check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi: https://github.com/pyscripter/python4delphi

Related posts
CodeIDELearn PythonPythonPython GUITkinter

How To Make More Than 20 ChatGPT Prompts Work With Python GUI Builders And NumPy Library?

CodeIDEProjectsPythonWindows

Unlock the Power of Python for Deep Learning with Generative Adversarial Networks (GANs) - The Engine behind DALL-E

CodeIDELearn PythonPythonPython GUITkinter

How To Make More Than 20 ChatGPT Prompts Work With Python GUI Builders And Matplotlib Library?

CodeIDELearn PythonPythonPython GUITkinter

How To Make More Than 20 ChatGPT Prompts Work With Python GUI Builders And Pillow Library?

Leave a Reply

Your email address will not be published. Required fields are marked *