Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZeroDivisionError #6

Open
Rao2321 opened this issue May 21, 2019 · 2 comments
Open

ZeroDivisionError #6

Rao2321 opened this issue May 21, 2019 · 2 comments

Comments

@Rao2321
Copy link

Rao2321 commented May 21, 2019


ZeroDivisionError Traceback (most recent call last)
in
1 file = r"C:\Users\Sashankh\axaxaxax.txt"
----> 2 convert(file)

in convert(fname, threshold)
11 fn = fname.split(".")
12 new_fname = fn[0] + "_clean." + fn[1]
---> 13 _generate_text(sentences, new_fname)
14
15 def _read_email(fname):

in _generate_text(sentences, fname, threshold)
43 with open(fname, "w") as new_file:
44 for sentence in sentences:
---> 45 if _prob_block(sentence, tagger) < threshold:
46 new_file.write(sentence)
47

in prob_block(sentence, pos_tagger)
61 doc = pos_tagger(sentence)
62 verb_count = np.sum([token.pos
!= "VERB" for token in doc])
---> 63 return float(verb_count) / len(doc)

ZeroDivisionError: float division by zero

@masterchop
Copy link

This is happening because the text you provided doesnt have a . in it jaja.
AS you see it is spliting the text so you can try/catch that and wen it fails catch it with new_frame = fn[0] + _clean
It works for me.

@kristiewirth
Copy link

@mynameisvinn Would love to help fix this error, but don't have access. 😞

Need to add a try/except statement here to account for any "sentences" that don't contain words and get a length of zero:

I.e. -

    try:
        doc = pos_tagger(sentence)
        verb_count = np.sum([token.pos_ != "VERB" for token in doc])
        return float(verb_count) / len(doc)
    except Exception:
        return 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants