I’m trying to understand a Key-Bigram extractor’s working and I cannot understand what does the following block of code do.
Here is the source code.
JavaScript
x
18
18
1
import spacy
2
nlp = spacy.load("en_core_web_sm")
3
4
string = '1 2 3 4 5 6 7 8 9'
5
6
7
def textProcessing(doc):
8
Words = []
9
doc = nlp(doc)
10
11
for possible_words in doc:
12
Words.append([possible_words , [child for child in possible_words.children]])
13
14
print(Words)
15
16
textProcessing(string)
17
18
Everything else is workin fine and I understood well, however I can not understand what child for child in possible_words.children
does.
Advertisement
Answer
token.children
uses the dependency parse to get all tokens that directly depend on the token in question. In a visualization (try displacy), this will be all the tokens with arrows pointing away from a token; if the word is a verb this could be the subject and any objects, if the word is a noun it could be any adjectives modifying it, for example.