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ırEgzersiz talimatları
dociçindeki bir token'ın sayıya benzeyip benzemediğini kontrol etmek içinlike_numtoken özniteliğini kullan.- Belgede geçerli token'dan sonra gelen token'ı al.
dociçindeki sonraki token'ın indeksitoken.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)