私は初めてここに投稿する初心者プログラマーです。任意の提案やアドバイスをいただければ幸いです!たとえば、test.csvとref.csv(両方とも3〜4語の文字列を含む単一の列)の内容を比較し、test.csvの各文字列に、最も類似しているものとの類似性に基づいてスコアを割り当てるプロジェクトに取り組んでいます。 ref.csvの文字列。ファジーウージー文字列照合モジュールを使用して、類似度スコアを割り当てています。
次のコードスニペットは、2つの入力ファイルを取得し、それらを配列に変換して、配列を出力します。
import csv
# Load text matching module
from fuzzywuzzy import fuzz
from fuzzywuzzy import process
# Import reference and test lists and assign to variables
ref_doc = csv.reader(open('ref.csv', 'rb'), delimiter=",", quotechar='|')
test_doc = csv.reader(open('test.csv', 'rb'), delimiter=",", quotechar='|')
# Define the arrays into which to load these lists
ref = []
test = []
# Assign the reference and test docs to arrays
for row in ref_doc:
ref.append(row)
for row in test_doc:
test.append(row)
# Print the arrays to make sure this all worked properly
# before we procede to run matching operations on the arrays
print ref, "\n\n\n", test
問題は、このスクリプトをIDLEで実行すると期待どおりに機能するが、bashから呼び出すと次のエラーが返されることです。
['one', 'two']
Traceback (most recent call last):
File "csvimport_orig.py", line 4, in <module>
from fuzzywuzzy import fuzz
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/fuzzywuzzy/fuzz.py", line 32, in <module>
import utils
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/fuzzywuzzy/utils.py", line 6, in <module>
table_from=string.punctuation+string.ascii_uppercase
AttributeError: 'module' object has no attribute 'punctuation'
これが正しく機能するためにbashで構成する必要があるものはありますか?それとも、IDLEがキャッチしていない根本的な問題がありますか?簡単にするために、このスニペットではfuzzywuzzyモジュールとは呼びませんが、IDLEでは期待どおりに機能します。
最終的には、pylevenshteinを使用したいのですが、このスクリプトを使用することに価値があるかどうかを確認してから、その作業に時間をかけます。
前もって感謝します。