Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
248 views
in Technique[技术] by (71.8m points)

python - How to turn the spacy span span to string in order to append the verbs extacted of spacy to the stopwords?

I want to append the list of verbs extracted from spacy, to my spacy stopwords list. I extracted the verbs as you will see below. However, they seem to be spacy.span.span and this does not allow me to append them. Any ideas? I tried to convert them into a string but nothing happened.

import spacy  # the libraries i have imported so far
import textacy
import en_core_web_sm
from spacy.lang.en.stop_words import STOP_WORDS

import string

punctuations = string.punctuation
stopwords = list(STOP_WORDS)
stopwords[:10]

nlp1=spacy.load("en_core_web_sm")
doc=nlp1(one)
sentences=list(doc.sents)
sentence=sentences[2]
patterns=[{'POS':'VERB'}] # extracting the verbs
verbs=textacy.extract.matches(doc, patterns=patterns)

for verb in verbs:
   print(verb)   # it prints all the verbs of my coprus.

#I want to achieve that. Append the extracted verbs to the list of stopwords. 

for i in verb:
    if i not in stopwords:
          stopwords.append(i) # here is the error / bug

I receive the following error: spacy.span.span has no attribute str

Any suggestion would be appreciated

question from:https://stackoverflow.com/questions/65937117/how-to-turn-the-spacy-span-span-to-string-in-order-to-append-the-verbs-extacted

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...