EmailParser icon indicating copy to clipboard operation
EmailParser copied to clipboard

ZeroDivisionError

Open Rao2321 opened this issue 6 years ago • 2 comments


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

Rao2321 avatar May 21 '19 10:05 Rao2321

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.

masterchop avatar Jun 11 '19 13:06 masterchop

@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

kristiewirth avatar Oct 17 '19 19:10 kristiewirth