PacktPublishing / Mastering-spaCy

Mastering spaCy, published by Packt
MIT License
126 stars 73 forks source link

Emoji extraction Chapter #11

Open mauuuuu5 opened 1 year ago

mauuuuu5 commented 1 year ago

Hi in case you want to upload the emoji drill here is the code

import spacy
from spacy.matcher import Matcher
from spacymoji import Emoji
nlp = spacy.load("en_core_web_md")

pos_emoji = ["😀", "😃", "😂", "😊", "😊", "😍"]  
neg_emoji = ["😞", "😠", "😩", "😢", "😭", "😒"]
pos_patterns = [[{"ORTH": emoji}] for emoji in pos_emoji]
neg_patterns = [[{"ORTH": emoji}] for emoji in neg_emoji]
matcher = Matcher(nlp.vocab)
matcher.add("posEmoji", pos_patterns)
matcher.add("negEmoji", neg_patterns)
doc = nlp(" I love Zara 😍")
for mid, start, end in matcher(doc):
      print(start, end, doc[start:end])

Cheers