Skip to content Skip to sidebar Skip to footer

Finding A Similar Text Present In String In Python

I have a txt file containing text Table of Contents Preface 1 Chapter 1: Tokenizing Text and WordNet Basics 7 Tokenizing text into sentences 8 Tokenizing sentences into wor

Solution 1:

If you are prepared to preprocess your chapter headings, eliminating page numbers and stuff, this:

import difflib
contents = ["Tokenizing Text and WordNet Basics",
            "Tokenizing text into sentences",
            "Tokenizing sentences into words",
            "Tokenizing sentences using regular expressions"]
input = "Tokenzing sentence using expressions"print (difflib.get_close_matches(input, contents, n=1))

will give you this output:

['Tokenizing sentences using regular expressions']

Post a Comment for "Finding A Similar Text Present In String In Python"