私はPythonプログラムをRubyに移植しようとしていますが、私はPythonについて全く知らないです。PythonプログラムをRubyに移植する方法
私に助言をいただけますか?
sampletrain
メソッドを実行したいです。しかし、なぜfeatures=self.getfeatures(item)
が利用できるのか分かりません。 getfeatures
は単なるインスタンス変数ですね。それは方法として使われるようです。
docclass.py:Pythonで
class classifier:
def __init__(self,getfeatures,filename=None):
# Counts of feature/category combinations
self.fc={}
# Counts of documents in each category
self.cc={}
self.getfeatures=getfeatures
def train(self,item,cat):
features=self.getfeatures(item)
# Increment the count for every feature with this category
for f in features:
self.incf(f,cat)
# Increment the count for this category
self.incc(cat)
self.con.commit()
def sampletrain(cl):
cl.train('Nobody owns the water.','good')
cl.train('the quick rabbit jumps fences','good')
cl.train('buy pharmaceuticals now','bad')
cl.train('make quick money at the online casino','bad')
cl.train('the quick brown fox jumps','good')
次のように推測します。おそらく、初期化時に渡された2番目の引数は関数です。初期化中はプロパティに割り当てられますが、後で括弧で呼び出すこともできます。 (これはJavaScriptと似ていますが、Pythonではありません) – Phrogz
@ThiefMasterとsteenslag :)ちょうど作業する..あなたの素敵なコメントに感謝します。 – zono
@Phrogz 'JSと似ています。私にとって理解しやすいです。おかげで – zono