Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Herausforderung: Tokenizing eines Satzes | Grundlagen der Textvorverarbeitung
Einführung in NLP

book
Herausforderung: Tokenizing eines Satzes

Aufgabe

Swipe to start coding

Ihre Aufgabe ist es, den gegebenen Auszug aus 'The Adventures of the Musgrave Ritual' in Sätze zu tokenisieren und dann den letzten Satz in Wörter zu tokenisieren. Verwenden Sie die nltk-Funktionen zu diesem Zweck und verwenden Sie den negativen Index, um den letzten Satz abzurufen und diesen Satz in Kleinbuchstaben umzuwandeln.

Lösung

# Import necessary functions
from nltk.tokenize import sent_tokenize, word_tokenize
import nltk
nltk.download('punkt_tab')
text = 'Sherlock Holmes picked them up one by one, and laid them along the edge of the table. Then he reseated himself in the chair, and looked over with a gleam of satisfaction in his eyes. "These," said he, "are all that I have left to remind me of ‘The Adventure of the Musgrave Ritual’."'
# Tokenize the text into sentences
sentences = sent_tokenize(text)
# Tokenize the last sentence converted to lowercase
tokens = word_tokenize(sentences[-1].lower())
print(tokens)

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 4
# Import necessary functions
from ___ import ___, ___
import nltk
nltk.download('punkt_tab')
text = 'Sherlock Holmes picked them up one by one, and laid them along the edge of the table. Then he reseated himself in the chair, and looked over with a gleam of satisfaction in his eyes. "These," said he, "are all that I have left to remind me of ‘The Adventure of the Musgrave Ritual’."'
# Tokenize the text into sentences
sentences = ___(___)
# Tokenize the last sentence converted to lowercase
tokens = ___(___)
print(tokens)

Fragen Sie AI

expand
ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

We use cookies to make your experience better!
some-alt