chartbeat-labs / textacy

NLP, before and after spaCy
https://textacy.readthedocs.io
Other
2.21k stars 249 forks source link

Identifying the tense of sentence as Future #287

Closed MaheshChandrra closed 4 years ago

MaheshChandrra commented 4 years ago

Is there any way by which I can find the sentences that are talking about the future,initially I've went by finding the tags of tokens in a sentence searching for tag-MD,but I didn't find it effective in many of the cases.Is there any way to find the same using textacy.

Thanks in advance!!

bdewilde commented 4 years ago

Hi @MaheshChandrra , it looks like spacy should offer access to morphological attributes (e.g. verb tense) via the Morphology class — https://spacy.io/api#architecture-pipeline — but I don't see any documentation on it. I would guess that this functionality is still being worked on, but I don't know for sure.

That said, the Token.morph.tense_ attribute may be all you need. Something like this:

>>> doc = nlp("I played sports when I was young, but now I play board games.")
>>> [(tok, tok.pos_, tok.morph.tense_) for tok in doc]
[(I, 'PRON', ''),
 (played, 'VERB', 'Tense_past'),
 (sports, 'NOUN', ''),
 (when, 'ADV', ''),
 (I, 'PRON', ''),
 (was, 'AUX', 'Tense_past'),
 (young, 'ADJ', ''),
 (,, 'PUNCT', ''),
 (but, 'CCONJ', ''),
 (now, 'ADV', ''),
 (I, 'PRON', ''),
 (play, 'VERB', 'Tense_pres'),
 (board, 'NOUN', ''),
 (games, 'NOUN', ''),
 (., 'PUNCT', '')]