I have been using spaCy to look for most used nouns and noun_phrases
I can successfully get rid of punctuation and stop words when looking for single nouns
docx = nlp('The bird is flying high in the sky blue of color')
# Just looking at nouns
nouns = []
for token in docx:
if token.is_stop != True and token.is_punct != True and token.pos_ == 'NOUN':
nouns.append(token)
# Count and look at the most frequent nouns #
word_freq = Counter(nouns)
common_nouns = word_freq.most_common(10)
Using noun_chunks in order to determine phrases however results in Attribute error
noun_phrases = []
for noun in docx.noun_chunks:
if len(noun) > 1 and '-PRON-' not in noun.lemma_ and noun.is_stop:
noun_phrases.append(noun)
AttributeError: 'spacy.tokens.span.Span' object has no attribute> 'is_stop'
I understand the nature of message, but I can't for the life of me get the syntax correctly where the presence of a stop word in a lemmatized string would excluded from being appended to the noun_phrases list
Output without removing stopwords
[{'word': 'The bird', 'lemma': 'the bird', 'len': 2}, {'word': 'the sky blue', 'lemma': 'the sky blue', 'len': 3}]
Intended Output (removing lemma containing stopwords, which include "the"
[{}]