How this code will look in the language ?

Joined
Feb 2, 2023
Messages
3
Reaction score
0
import spacy
from spacy.matcher import DependencyMatcher

nlp = spacy.load("en_core_web_sm")

pattern = [
{
"RIGHT_ID": "chips_id",
"RIGHT_ATTRS": {"ORTH": "chips"}
},

{
"LEFT_ID": "chips_id",
"REL_OP": "<<",
"RIGHT_ID": "other_words",
"RIGHT_ATTRS": {"POS": '*'}
}
]

matcher = DependencyMatcher(nlp.vocab)
matcher.add("chips", [pattern])

doc = nlp("The pizza is great but the chips aren't the best")
for id_, (_, other_words) in matcher(doc):
print(doc[other_words])
 
Joined
Jan 30, 2023
Messages
107
Reaction score
13
The output of this code will be:

Code:
arent the best

This is because the code is using the DependencyMatcher to find words in the sentence that immediately precede the word "chips". The words "aren't the best" meet this criteria and are therefore returned as the output.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,560
Members
45,035
Latest member
HoTaKeDai

Latest Threads

Top