我不希望长度小于 3 或大于 7 的术语。在 R 中有一种直接的方法,但在 Python 中我不确定。我试过这个,但还是不行
from sklearn.feature_extraction.text import CountVectorizer
regex1 = '/^[a-zA-Z]{3,7}$/'
vectorizer = CountVectorizer( analyzer='word',tokenizer= tokenize,stop_words = stopwords,token_pattern = regex1,min_df= 2, max_df = 0.9,max_features = 2000)
vectorizer1 = vectorizer.fit_transform(token_dict.values())
也尝试过其他正则表达式 -
"^[a-zA-Z]{3,7}$"
r'^[a-zA-Z]{3,7}$'