forked from seanrife/psyLex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
psyLex_dir.py
39 lines (25 loc) · 1.01 KB
/
psyLex_dir.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from psyLex.readDict import *
from psyLex.wordCount import *
import sys
import os
# NOTE: this is VERY alpha. You will almost certainly need to tweak things to make it do what you really want. Read the source code and tread lightly.
# It goes like this: accepts two command line arguments: (1) directory with files to analyze, and (2) the path to the dictionary file we should use.
inValue = sys.argv[1]
inDict = sys.argv[2]
outLine = "file"
dictIn = readDict(inDict)
for cat in dictIn[0]:
outLine = outLine + "," + dictIn[0][cat][0]
with open("out.csv", "a") as outCSV:
outCSV.write(outLine + "\n")
for workingFile in os.listdir(inValue):
outLine = workingFile
with open (inValue + "\\" + workingFile, "r") as myfile:
count = 0
inData=myfile.read().replace('\n', ' ')
# Run the wordCount function using the specified parameters.
out = wordCount(inData, dictIn)
for key, value in out[0].items():
outLine = outLine + "," + str(value)
with open("out.csv", "a") as outCSV:
outCSV.write(outLine + "\n")