1593829496
Text****data is the most common format of the data out there. An abundance of articles, tweets, documents, books and else, fly around us every day. The amount of insights you can extract is immense and the tools to help on extracting them are improving continuously.
In Python, you can use external libraries to process text data. One issue with these libraries is that they are not lightweight and they do have a steep learning curve for starters. In many cases, functions written in pure Python can do great if your sole intention is to explore and get to know with the data.
Below I’ve provided a list of 10 such functions that I use mostly. These functions are mainly **heuristic functions **that work properly under assumptions made. These assumptions are stated at the points below at functions where they are considered.
Assumption: Everything that ends with a dot, question mark or exclamation mark, is taken as a sentence.
def get_sentences(text):
import re
pattern = r'([A-Z][^\.!?]*[\.!?])'
pattern_compiled = re.compile(pattern, re.M)
list_of_sentences = re.findall(pattern, text)
return list_of_sentences
# Test
text = """This is the most frequent question we're asked by prospective students. And our response? Absolutely! We've trained people from all walks of life."""
get_sentences(text)
# [
# "This is the most frequent questions we're asked by prospective students.",
# 'And our response?',
# 'Absolutely!',
# "We've trained people from all walks of life."
# ]
Assumption: A colon followed by a list of items separated with comma is taken.
def get_listed_items_with_colon(text):
import re
list_of_items = []
list_of_sentences = re.split('\.|\?|\!', text)
for sentence in list_of_sentences:
if ':' in sentence:
start_index = sentence.find(':')
sub_sentence = sentence[start_index+1:]
list_of_items.append([word.strip() for word in sub_sentence.split(',')])
return list_of_items
# Test
text = """The house has everything I need: two bedrooms, a backyard, and a garage. I have several favorite genres of movies: drama, science fiction, and mystery."""
get_listed_items_with_colon(text)
# [ ['two bedrooms', 'a backyard', 'and a garage'], ['drama', 'science fiction', 'and mystery'] ]
#data-science #nlp #programming #text-mining #python
1619510796
Welcome to my Blog, In this article, we will learn python lambda function, Map function, and filter function.
Lambda function in python: Lambda is a one line anonymous function and lambda takes any number of arguments but can only have one expression and python lambda syntax is
Syntax: x = lambda arguments : expression
Now i will show you some python lambda function examples:
#python #anonymous function python #filter function in python #lambda #lambda python 3 #map python #python filter #python filter lambda #python lambda #python lambda examples #python map
1619518440
Welcome to my Blog , In this article, you are going to learn the top 10 python tips and tricks.
…
#python #python hacks tricks #python learning tips #python programming tricks #python tips #python tips and tricks #python tips and tricks advanced #python tips and tricks for beginners #python tips tricks and techniques #python tutorial #tips and tricks in python #tips to learn python #top 30 python tips and tricks for beginners
1599758100
Learn how to convert your Text into Voice with Python and Google APIs
Text to speech is a process to convert any text into voice. Text to speech project takes words on digital devices and convert them into audio with a button click or finger touch. Text to speech python project is very helpful for people who are struggling with reading.
To implement this project, we will use the basic concepts of Python, Tkinter, gTTS, and playsound libraries.
To install the required libraries, you can use pip install command:
pip install tkinter
pip install gTTS
pip install playsound
Please download the source code of Text to Speech Project: Python Text to Speech
The objective of this project is to convert the text into voice with the click of a button. This project will be developed using Tkinter, gTTs, and playsound library.
In this project, we add a message which we want to convert into voice and click on play button to play the voice of that text message.
So these are the basic steps that we will do in this Python project. Let’s start.
#python tutorials #python project #python project for beginners #python text to speech #text to speech convertor #python
1593829496
Text****data is the most common format of the data out there. An abundance of articles, tweets, documents, books and else, fly around us every day. The amount of insights you can extract is immense and the tools to help on extracting them are improving continuously.
In Python, you can use external libraries to process text data. One issue with these libraries is that they are not lightweight and they do have a steep learning curve for starters. In many cases, functions written in pure Python can do great if your sole intention is to explore and get to know with the data.
Below I’ve provided a list of 10 such functions that I use mostly. These functions are mainly **heuristic functions **that work properly under assumptions made. These assumptions are stated at the points below at functions where they are considered.
Assumption: Everything that ends with a dot, question mark or exclamation mark, is taken as a sentence.
def get_sentences(text):
import re
pattern = r'([A-Z][^\.!?]*[\.!?])'
pattern_compiled = re.compile(pattern, re.M)
list_of_sentences = re.findall(pattern, text)
return list_of_sentences
# Test
text = """This is the most frequent question we're asked by prospective students. And our response? Absolutely! We've trained people from all walks of life."""
get_sentences(text)
# [
# "This is the most frequent questions we're asked by prospective students.",
# 'And our response?',
# 'Absolutely!',
# "We've trained people from all walks of life."
# ]
Assumption: A colon followed by a list of items separated with comma is taken.
def get_listed_items_with_colon(text):
import re
list_of_items = []
list_of_sentences = re.split('\.|\?|\!', text)
for sentence in list_of_sentences:
if ':' in sentence:
start_index = sentence.find(':')
sub_sentence = sentence[start_index+1:]
list_of_items.append([word.strip() for word in sub_sentence.split(',')])
return list_of_items
# Test
text = """The house has everything I need: two bedrooms, a backyard, and a garage. I have several favorite genres of movies: drama, science fiction, and mystery."""
get_listed_items_with_colon(text)
# [ ['two bedrooms', 'a backyard', 'and a garage'], ['drama', 'science fiction', 'and mystery'] ]
#data-science #nlp #programming #text-mining #python
1602968400
Python is awesome, it’s one of the easiest languages with simple and intuitive syntax but wait, have you ever thought that there might ways to write your python code simpler?
In this tutorial, you’re going to learn a variety of Python tricks that you can use to write your Python code in a more readable and efficient way like a pro.
Swapping value in Python
Instead of creating a temporary variable to hold the value of the one while swapping, you can do this instead
>>> FirstName = "kalebu"
>>> LastName = "Jordan"
>>> FirstName, LastName = LastName, FirstName
>>> print(FirstName, LastName)
('Jordan', 'kalebu')
#python #python-programming #python3 #python-tutorials #learn-python #python-tips #python-skills #python-development