현재 다음과 같은 목록을 만들었습니다.
stopfile = os.path.join(baseDir, inputPath, STOPWORDS_PATH)
stopwords = set(sc.textFile(stopfile).collect())
print 'These are the stopwords: %s' % stopwords
def tokenize(string):
""" An implementation of input string tokenization that excludes stopwords
Args:
string (str): input string
Returns:
list: a list of tokens without stopwords
"""
res = list()
for word in simpleTokenize(string):
if word not in stopwords:
res.append(word)
return res
simpleTokenize는 문자열 목록을 반환하는 문자열의 기본 분할 함수입니다.
이건 괜찮아. 좀 더 "Pythonic"방식 (4 대신 한 줄의 코드)으로 수행하려면 목록 이해를 사용할 수 있습니다.
res = [word for word in simpleTokenize(string) if word not in stopwords]
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다