Last active
July 18, 2019 08:55
-
-
Save yongjun823/0491efd597289ae8a1bf9e853014827c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import concurrent.futures | |
import os | |
import pandas as pd | |
import time | |
# from tqdm import tqdm_notebook as tqdm | |
from tqdm import tqdm | |
# import matplotlib.pyplot as plt | |
from textblob import TextBlob | |
def f(x): | |
polarity = TextBlob(x).polarity | |
return polarity | |
def main(): | |
dir_name = 'val/' | |
jsons = os.listdir(dir_name) | |
df_arr = [] | |
for val in tqdm(jsons): | |
df_t = pd.read_json(dir_name + val) | |
df_arr.append(df_t) | |
df = pd.concat(df_arr, ignore_index=True) | |
text_arr = list(df['text']) | |
sent_arr = [] | |
with concurrent.futures.ProcessPoolExecutor() as executor: | |
for sent in executor.map(f, tqdm(text_arr)): | |
sent_arr.append(sent) | |
print(sum(sent_arr) / len(sent_arr)) | |
if __name__ == '__main__': | |
s_time = time.time() | |
main() | |
print(f'end time {time.time() - s_time}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment