0

I tried fixing contractions in a large number of text files using contractions package. It works good for most of cases, but fails in handling contraction like 's. Here is an example:

text = "I'll give two examples. Lets have the first example: let's say someone's name. Second example: My name's Sam"

import contractions
contractions.fix(text)

Output:

"I will give two examples. Let Us have the first example: let us say someone is name. Second example: My name's Sam"

The first 's is fixed but it is failed in properly fixing the second and the third ones. Any workable solutions (or packages) to fix this problem?

An ideal output would be the below (or at least closer to the main string):

"I will give two examples. Let us have the first example: let us say someone's name. Second example: My name is Sam"
Sam S.
  • 627
  • 1
  • 7
  • 23
  • 1
    Sounds more like a bug report than a question. – Klaus D. Aug 08 '22 at 05:35
  • 1
    Apparently `contractions` allows this, but in your `text`, "Lets" is a misspelled version of "Let's". If you need that flexibility to be a requirement, you'll run into some problems where those are ambiguous. – Grismar Aug 08 '22 at 05:36
  • Thanks for your comments. I am looking for any alternative package or solution. One idea will be using re.sub and replacing all possible contractions, but it again fails for 's. – Sam S. Aug 08 '22 at 06:16
  • Regarding Lets: if you use lowercase, it returns lowercase us. For example "lets" will be replaced with "let us". – Sam S. Aug 08 '22 at 06:18

0 Answers0