Inizia subitoInizia gratis

Best practice per le strutture dati

Il codice in questo esempio prova ad analizzare un testo e raccogliere tutti i nomi propri. Se il token che segue il nome proprio è un verbo, dovrebbe essere estratto anche quello. Un oggetto doc è già stato creato.

# Get all tokens and part-of-speech tags
pos_tags = [token.pos_ for token in doc]

for index, pos in enumerate(pos_tags):
    # Check if the current token is a proper noun
    if pos == 'PROPN':
        # Check if the next token is a verb
        if pos_tags[index + 1] == 'VERB':
            print('Found a verb after a proper noun!')

Questo esercizio fa parte del corso

NLP avanzato con spaCy

Visualizza corso

esercizio interattivo pratico

Trasforma la teoria in pratica con uno dei nostri esercizi interattivi

Inizia esercizio