Przechwytywanie wzorca tokenów

Analiza sentymentu w Pythonie

Violeta Misheva

Data Scientist

Operatory i porównania ciągów znaków

# Checks if a string is composed only of letters  
my_string.isalpha()
# Checks if a string is composed only of digits 
my_string.isdigit()
# Checks if a string is composed only of alphanumeric characters
my_string.isalnum()
Analiza sentymentu w Pythonie

Operatory ciągów z wyrażeniami listowymi

# Original word tokenization
word_tokens = [word_tokenize(review) for review in reviews.review]
# Keeping only tokens composed of letters
cleaned_tokens = [[word for word in item if word.isalpha()] for item in word_tokens]
len(word_tokens[0])
87
len(cleaned_tokens[0])
78
Analiza sentymentu w Pythonie

Wyrażenia regularne

import re
my_string = '#Wonderfulday'
# Extract #, followed by any letter, small or capital
x = re.search('#[A-Za-z]', my_string)
x
<re.Match object; span=(0, 2), match='#W'>
Analiza sentymentu w Pythonie

Wzorzec tokenów w modelu BOW

# Default token pattern in CountVectorizer
'\b\w\w+\b'
# Specify a particular token pattern
CountVectorizer(token_pattern=r'\b[^\d\W][^\d\W]+\b')
Analiza sentymentu w Pythonie

Czas na ćwiczenia!

Analiza sentymentu w Pythonie

Preparing Video For Download...