Python - Text Munging





Munging in general means cleaning up anything messy by transforming them. In our case we will see how we can transform text to get some result which gives us some desirable changes to data. At a simple level it is only about transforming the text we are dealing with.

Example

In the below example we plan to shuffle and then rearrange all the letters of a sentence except the first and the last one to get the possible alternate words which may get generated as a mis-spelled word during writing by a human. This rearrangement helps us in

import random

import re

def replace(t):
    inner_word = list(t.group(2))
    random.shuffle(inner_word)
    return t.group(1) + "".join(inner_word) + t.group(3)
text = "Hello, You should reach the finish line."
print re.sub(r"(\w)(\w+)(\w)", replace, text)

print re.sub(r"(\w)(\w+)(\w)", replace, text)

When we run the above program we get the following output −

Hlleo, You slouhd raech the fsiinh lnie.
Hlleo, You suolhd raceh the fniish line.

Here you can see how the words are jumbled except for the first and the last letters. By taking a statistical approach to wrong spelling we can decided what are the commonly mis0spelled words and supply the correct spelling for them.



Frequently Asked Questions

+
Ans: Python Text Processing Tutorial for Beginners - Learn Python Text Processing in simple and easy steps starting from basic to advanced concepts with examples including Text Processing,Text Processing Environment,String Immutability,Sorting Lines,Reformatting Paragraphs,Counting Token in Paragraphs ,Convert Binary to ASCII,Convert ASCII to Binary,Strings as Files,Backward File Reading,Filter Duplicate Words,Extract Emails from Text,Extract URL from Text,Pretty Print Numbers,Text Processing State Machine,Capitalize and Translate,Tokenization,Remove Stopwords,Synonyms and Antonyms,Text Translation,Word Replacement,Spelling Check,WordNet Interface,Corpora Access,Tagging Words,Chunks and Chinks,Chunk Classification,Text Classification,Bigrams,Process PDF,Process Word Document,Reading RSS feed,Sentiment Analysis,Search and Match,Text Munging,Text wrapping,Frequency Distribution,Text Summarization,Stemming Algorithms,Constrained Search. view more..
+
Ans: Python Text Processing Tutorial for Beginners - Learn Python Text Processing in simple and easy steps starting from basic to advanced concepts with examples including Text Processing,Text Processing Environment,String Immutability,Sorting Lines,Reformatting Paragraphs,Counting Token in Paragraphs ,Convert Binary to ASCII,Convert ASCII to Binary,Strings as Files,Backward File Reading,Filter Duplicate Words,Extract Emails from Text,Extract URL from Text,Pretty Print Numbers,Text Processing State Machine,Capitalize and Translate,Tokenization,Remove Stopwords,Synonyms and Antonyms,Text Translation,Word Replacement,Spelling Check,WordNet Interface,Corpora Access,Tagging Words,Chunks and Chinks,Chunk Classification,Text Classification,Bigrams,Process PDF,Process Word Document,Reading RSS feed,Sentiment Analysis,Search and Match,Text Munging,Text wrapping,Frequency Distribution,Text Summarization,Stemming Algorithms,Constrained Search. view more..
+
Ans: Python Text Processing Tutorial for Beginners - Learn Python Text Processing in simple and easy steps starting from basic to advanced concepts with examples including Text Processing,Text Processing Environment,String Immutability,Sorting Lines,Reformatting Paragraphs,Counting Token in Paragraphs ,Convert Binary to ASCII,Convert ASCII to Binary,Strings as Files,Backward File Reading,Filter Duplicate Words,Extract Emails from Text,Extract URL from Text,Pretty Print Numbers,Text Processing State Machine,Capitalize and Translate,Tokenization,Remove Stopwords,Synonyms and Antonyms,Text Translation,Word Replacement,Spelling Check,WordNet Interface,Corpora Access,Tagging Words,Chunks and Chinks,Chunk Classification,Text Classification,Bigrams,Process PDF,Process Word Document,Reading RSS feed,Sentiment Analysis,Search and Match,Text Munging,Text wrapping,Frequency Distribution,Text Summarization,Stemming Algorithms,Constrained Search. view more..
+
Ans: Python Text Processing Tutorial for Beginners - Learn Python Text Processing in simple and easy steps starting from basic to advanced concepts with examples including Text Processing,Text Processing Environment,String Immutability,Sorting Lines,Reformatting Paragraphs,Counting Token in Paragraphs ,Convert Binary to ASCII,Convert ASCII to Binary,Strings as Files,Backward File Reading,Filter Duplicate Words,Extract Emails from Text,Extract URL from Text,Pretty Print Numbers,Text Processing State Machine,Capitalize and Translate,Tokenization,Remove Stopwords,Synonyms and Antonyms,Text Translation,Word Replacement,Spelling Check,WordNet Interface,Corpora Access,Tagging Words,Chunks and Chinks,Chunk Classification,Text Classification,Bigrams,Process PDF,Process Word Document,Reading RSS feed,Sentiment Analysis,Search and Match,Text Munging,Text wrapping,Frequency Distribution,Text Summarization,Stemming Algorithms,Constrained Search. view more..
+
Ans: Python Text Processing Tutorial for Beginners - Learn Python Text Processing in simple and easy steps starting from basic to advanced concepts with examples including Text Processing,Text Processing Environment,String Immutability,Sorting Lines,Reformatting Paragraphs,Counting Token in Paragraphs ,Convert Binary to ASCII,Convert ASCII to Binary,Strings as Files,Backward File Reading,Filter Duplicate Words,Extract Emails from Text,Extract URL from Text,Pretty Print Numbers,Text Processing State Machine,Capitalize and Translate,Tokenization,Remove Stopwords,Synonyms and Antonyms,Text Translation,Word Replacement,Spelling Check,WordNet Interface,Corpora Access,Tagging Words,Chunks and Chinks,Chunk Classification,Text Classification,Bigrams,Process PDF,Process Word Document,Reading RSS feed,Sentiment Analysis,Search and Match,Text Munging,Text wrapping,Frequency Distribution,Text Summarization,Stemming Algorithms,Constrained Search. view more..
+
Ans: Python Text Processing Tutorial for Beginners - Learn Python Text Processing in simple and easy steps starting from basic to advanced concepts with examples including Text Processing,Text Processing Environment,String Immutability,Sorting Lines,Reformatting Paragraphs,Counting Token in Paragraphs ,Convert Binary to ASCII,Convert ASCII to Binary,Strings as Files,Backward File Reading,Filter Duplicate Words,Extract Emails from Text,Extract URL from Text,Pretty Print Numbers,Text Processing State Machine,Capitalize and Translate,Tokenization,Remove Stopwords,Synonyms and Antonyms,Text Translation,Word Replacement,Spelling Check,WordNet Interface,Corpora Access,Tagging Words,Chunks and Chinks,Chunk Classification,Text Classification,Bigrams,Process PDF,Process Word Document,Reading RSS feed,Sentiment Analysis,Search and Match,Text Munging,Text wrapping,Frequency Distribution,Text Summarization,Stemming Algorithms,Constrained Search. view more..
+
Ans: Python Text Processing Tutorial for Beginners - Learn Python Text Processing in simple and easy steps starting from basic to advanced concepts with examples including Text Processing,Text Processing Environment,String Immutability,Sorting Lines,Reformatting Paragraphs,Counting Token in Paragraphs ,Convert Binary to ASCII,Convert ASCII to Binary,Strings as Files,Backward File Reading,Filter Duplicate Words,Extract Emails from Text,Extract URL from Text,Pretty Print Numbers,Text Processing State Machine,Capitalize and Translate,Tokenization,Remove Stopwords,Synonyms and Antonyms,Text Translation,Word Replacement,Spelling Check,WordNet Interface,Corpora Access,Tagging Words,Chunks and Chinks,Chunk Classification,Text Classification,Bigrams,Process PDF,Process Word Document,Reading RSS feed,Sentiment Analysis,Search and Match,Text Munging,Text wrapping,Frequency Distribution,Text Summarization,Stemming Algorithms,Constrained Search. view more..
+
Ans: Python Text Processing Tutorial for Beginners - Learn Python Text Processing in simple and easy steps starting from basic to advanced concepts with examples including Text Processing,Text Processing Environment,String Immutability,Sorting Lines,Reformatting Paragraphs,Counting Token in Paragraphs ,Convert Binary to ASCII,Convert ASCII to Binary,Strings as Files,Backward File Reading,Filter Duplicate Words,Extract Emails from Text,Extract URL from Text,Pretty Print Numbers,Text Processing State Machine,Capitalize and Translate,Tokenization,Remove Stopwords,Synonyms and Antonyms,Text Translation,Word Replacement,Spelling Check,WordNet Interface,Corpora Access,Tagging Words,Chunks and Chinks,Chunk Classification,Text Classification,Bigrams,Process PDF,Process Word Document,Reading RSS feed,Sentiment Analysis,Search and Match,Text Munging,Text wrapping,Frequency Distribution,Text Summarization,Stemming Algorithms,Constrained Search. view more..
+
Ans: Python Text Processing Tutorial for Beginners - Learn Python Text Processing in simple and easy steps starting from basic to advanced concepts with examples including Text Processing,Text Processing Environment,String Immutability,Sorting Lines,Reformatting Paragraphs,Counting Token in Paragraphs ,Convert Binary to ASCII,Convert ASCII to Binary,Strings as Files,Backward File Reading,Filter Duplicate Words,Extract Emails from Text,Extract URL from Text,Pretty Print Numbers,Text Processing State Machine,Capitalize and Translate,Tokenization,Remove Stopwords,Synonyms and Antonyms,Text Translation,Word Replacement,Spelling Check,WordNet Interface,Corpora Access,Tagging Words,Chunks and Chinks,Chunk Classification,Text Classification,Bigrams,Process PDF,Process Word Document,Reading RSS feed,Sentiment Analysis,Search and Match,Text Munging,Text wrapping,Frequency Distribution,Text Summarization,Stemming Algorithms,Constrained Search. view more..
+
Ans: Python Tutorial for Beginners - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python Overview - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python Environment Setup - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python 3 Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python Basic Syntax - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python Variable Types - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python Basic Operators - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python Decision Making - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python Loops - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..
+
Ans: Python Numbers - Learn Python in simple and easy steps starting from basic to advanced concepts with examples including Python Syntax Object Oriented Language, Methods, Tuples, Tools/Utilities, Exceptions Handling, Sockets, GUI, Extentions, XML Programming. view more..




Rating - NAN/5
546 views

Advertisements