저는 Coursera에서 오래된 Columbia NLP 수업을 들었으며 현재 첫 번째 과제를 수행하려고합니다. 클래스는 Python을 사용하지만 Java/Groovy에 익숙해 졌기 때문에 Groovy의 첫 번째 할당에서 제공 한 모든 도우미 스크립트를 다시 작성하기로 결정했습니다.파이썬에서 단어를 곱할 수 있습니까?
원래 작성자가 곱셈처럼 보이는 것을 보았습니다.
이def get_ngrams(sent_iterator, n):
"""
Get a generator that returns n-grams over the entire corpus,
respecting sentence boundaries and inserting boundary tokens.
Sent_iterator is a generator object whose elements are lists
of tokens.
"""
for sent in sent_iterator:
#Add boundary symbols to the sentence
w_boundary = (n-1) * [(None, "*")]
w_boundary.extend(sent)
w_boundary.append((None, "STOP"))
#Then extract n-grams
ngrams = (tuple(w_boundary[i:i+n]) for i in xrange(len(w_boundary)-n+1))
for n_gram in ngrams: #Return one n-gram at a time
yield n_gram
구체적 내가
w_boundary = (n-1) * [(None, "*")]
내가 여기서 n은 함수 정의에 선언 된 것을 볼이 라인을 이해하지 않습니다하지만 난 정말 안 : 나는 이야기하고있는 특정 기능은 다음과 같습니다 그것이 무엇인지 압니다. "문자열 곱하기 파이썬"을 검색해도 도움이되지 않습니다. 누군가가이 python 기능에 대해 설명하거나 내가 적어도 검색하려고 시도해야하는 것의 더 좋은 아이디어를 줄 수 있습니까?
이것은 목록 곱셈입니다. 왜 그냥 통역관에서 시험해 보지 않으시겠습니까? 'n'은 정수입니다. – jonrsharpe
@jonrsharpe 나는 그것조차 생각조차하지 않았다. 하하. 커맨드 라인에서 Java를 사용하지 않을 것입니다. –