TARファイルにアクセスして処理するGitHubのスクリプトを修正しようとしています。コードには、ファイルが格納されているルートディレクトリを指し示す必要がある変数があります(私はそう思います...)。Pythonの変数にディレクトリを渡す
def make_Dictionary(root_dir):
emails_dirs = [os.path.join(root_dir,f) for f in os.listdir(root_dir)]
all_words = []
for emails_dir in emails_dirs:
emails = [os.path.join(emails_dir,f) for f in os.listdir(emails_dir)]
for mail in emails:
with open(mail) as m:
for line in m:
words = line.split()
all_words += words
dictionary = Counter(all_words)
list_to_remove = dictionary.keys()
for item in list_to_remove:
if item.isalpha() == False:
del dictionary[item]
elif len(item) == 1:
del dictionary[item]
dictionary = dictionary.most_common(4000)
np.save('dict_movie.npy',dictionary)
return dictionary
root_dir = sys.path[0]
dictionary = make_Dictionary(root_dir)
ROOT_DIRが投げている:
File "C:\Users\seand\eclipse-workspace\sentiment_project\src\root\nested\movie-polarity.py", line 22, in make_Dictionary
emails = [os.path.join(emails_dir,f) for f in os.listdir(emails_dir)]
NotADirectoryError: [WinError 267] The directory name is invalid: 'C:\\Users\\seand\\eclipse-workspace\\sentiment_project\\src\\root\\nested\\movie-polarity-tfidf.py'
方向状態「注:コーパスのディレクトリパスをmovie-polarity-tfidf.pyとmovie-polarity.pyニーズにするには、以下のコードがありますそれに応じて設定します。私が指定しているパスには、スクリプトが必要とするコーパスのTARファイルが含まれています。私はなぜ、スクリプトがディレクトリを探している場合、この.pyファイルが取得されているのか分からない。
「sys.path [0]」に保持されている値は何ですか?通常、 'sys.path [0]'はユーザの現在のディレクトリになります。 –
@StephenRauch確かにそうです。一定! – Sean
@KindStranger root_dir変数を表示すると、C:\ Users \ seand \ eclipse-workspace \ sentiment_project \ src \ root \ nestedですが、mark_Dictionary関数に渡されると、最後にファイルを取得しているようです私のディレクトリは無効です。 – Sean