Python に問題があります。ジェネレーターであることがわかったオブジェクトに格納されている情報を理解しようとしています。Python については何も知りませんが、Java に変換するには、このコードがどのように機能するかを理解する必要があります。コードは次のとおりです。
def segment(text):
"Return a list of words that is the best segmentation of text."
if not text: return []
candidates = ([first]+segment(rem) for first,rem in splits(text))
return max(candidates, key=Pwords)
def splits(text, L=20):
"Return a list of all possible (first, rem) pairs, len(first)<=L."
pairs = [(text[:i+1], text[i+1:]) for i in range(min(len(text), L))]
return pairs
def Pwords(words):
"The Naive Bayes probability of a sequence of words."
productw = 1
for w in words:
productw = productw * Pw(w)
return productw
メソッド Pwords と splits がどのように機能するかを理解しましたが (関数 Pw(w) は単に行列から値を取得します)、「セグメント」メソッドの「候補」オブジェクトがどのように構築され、何を理解しようとしています。を含む。また、「max()」関数がこのオブジェクトを分析する方法。
ここでこのオブジェクトを印刷するための実行可能な解決策が見つからなかったため、誰かが私を助けてくれることを願っています。みんなに感謝します。マウロ。