spaCy icon indicating copy to clipboard operation
spaCy copied to clipboard

like_num returns false if a numeric word is not lowercased

Open fucking-signup opened this issue 8 years ago • 3 comments

I am using rule-based matching and noticed that some patterns containing "LIKE_NUM": True are not matching phrases, where numeric words are not in lowercase (in my case some sentences start with numeric words that are capitalized).

It could be easily checked:

import spacy
nlp = spacy.load('en')

def like_num(text):
    doc = nlp(text)
    print(doc[0].like_num)

like_num("twenty") # True
like_num("20")     # True
like_num("Twenty") # False
like_num("TWENTY") # False
like_num("tWenTY") # False

Maybe like_num attribute should check lowercased form of a token?

Environment

  • Operating System: macOS High Sierra
  • Python Version Used: 3.6.3
  • spaCy Version Used: 2.0.3

fucking-signup avatar Dec 27 '17 02:12 fucking-signup

Thanks, good point! The implementation is here:

https://github.com/explosion/spaCy/blob/03a2f540caedf2c92d6a2151a72108ca2a297a50/spacy/lang/en/lex_attrs.py#L15-L25

It looks like just changing it to if text.lower() in _num_words should work, right? If you want to test this and submit a PR, this would be great 👍

ines avatar Jan 03 '18 15:01 ines

@ines sure! Will do within a week or two.

fucking-signup avatar Jan 03 '18 21:01 fucking-signup

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar May 08 '18 01:05 lock[bot]