BaşlayınÜcretsiz Başlayın

Sözcüksel öznitelikler

Bu örnekte, metindeki yüzde değerlerini bulmak için spaCy'nin Doc ve Token nesnelerini ve sözcüksel öznitelikleri kullanacaksın. Art arda gelen iki token arayacaksın: bir sayı ve bir yüzde işareti. İngilizce nlp nesnesi zaten oluşturuldu.

Bu egzersiz

spaCy ile İleri Düzey NLP

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • doc içindeki bir token'ın sayıya benzeyip benzemediğini kontrol etmek için like_num token özniteliğini kullan.
  • Belgede geçerli token'dan sonra gelen token'ı al. doc içindeki sonraki token'ın indeksi token.i + 1.
  • Sonraki token'ın text özniteliğinin yüzde işareti "%" olup olmadığını kontrol et.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Process the text
doc = nlp("In 1990, more than 60% of people in East Asia were in extreme poverty. Now less than 4% are.")

# Iterate over the tokens in the doc
for token in doc:
    # Check if the token resembles a number
    if ____.____:
        # Get the next token in the document
        next_token = ____[____]
        # Check if the next token's text equals '%'
        if next_token.____ == '%':
            print('Percentage found:', token.text)
Kodu Düzenle ve Çalıştır