mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 09:26:27 +03:00
Add emoji sentiment to lightning tour matcher example
This commit is contained in:
parent
1203959625
commit
ae11c8d60f
|
@ -149,9 +149,14 @@ p
|
||||||
|
|
||||||
nlp = spacy.load('en')
|
nlp = spacy.load('en')
|
||||||
matcher = Matcher(nlp.vocab)
|
matcher = Matcher(nlp.vocab)
|
||||||
# match "Google I/O" or "Google i/o"
|
|
||||||
pattern = [{'ORTH': 'Google'}, {'UPPER': 'I'}, {'ORTH': '/'}, {'UPPER': 'O'}]
|
def set_sentiment(matcher, doc, i, matches):
|
||||||
matcher.add('GoogleIO', None, pattern)
|
doc.sentiment += 0.1
|
||||||
|
|
||||||
|
pattern1 = [{'ORTH': 'Google'}, {'UPPER': 'I'}, {'ORTH': '/'}, {'UPPER': 'O'}]
|
||||||
|
pattern2 = [[{'ORTH': emoji, 'OP': '+'}] for emoji in ['😀', '😂', '🤣', '😍']]
|
||||||
|
matcher.add('GoogleIO', None, pattern1) # match "Google I/O" or "Google i/o"
|
||||||
|
matcher.add('HAPPY', set_sentiment, pattern2) # match one or more happy emoji
|
||||||
matches = nlp(LOTS_OF TEXT)
|
matches = nlp(LOTS_OF TEXT)
|
||||||
|
|
||||||
+infobox
|
+infobox
|
||||||
|
|
Loading…
Reference in New Issue
Block a user