Как я могу получить все предшествующие атрибуты токена в spacy do c, если следующий token.pos_ равен "AUX"? - PullRequest
0 голосов
/ 16 марта 2020

Это то, что у меня есть:

some_txt = ["Random Records has cancelled the anticipated release of its 2020 compilation album.",
            "Associated Songwriters has announced a boycott of Random Records"]

all_tokens = []

for doc in nlp_md.pipe(some_txt):
    # Check if the current token is a proper noun
    for token in doc:
        if token.pos_ == "PROPN":
            tokens = (token.text, token.pos_, token.dep_)
            all_tokens.append(tokens)
            # Check if the next token is an auxillary
            if this_txt[token.i + 1].pos_ == "AUX":
                break

all_tokens

[('Random', 'PROPN', 'compound'),
 ('Records', 'PROPN', 'nsubj'),
 ('Associated', 'PROPN', 'compound'),
 ('Songwriters', 'PROPN', 'nsubj')]

Что мне нужно:

[[('Random', 'PROPN', 'compound'), ('Records', 'PROPN', 'nsubj')],
 [('Associated', 'PROPN', 'compound'), ('Songwriters', 'PROPN', 'nsubj')]]

У меня есть большое количество текста для повторения, и все они следуют похожему шаблону. PROPN х раз, тогда AUX.

Спасибо

...