import argparse
import csv
from datetime import datetime, timedelta
from multiprocessing import Pool
import numpy
import os

from modules import cleaner, tokenizer
from modules.similarity import *

parser = argparse.ArgumentParser(description='Evaluate classifier model using ten folds cross validation.')
parser.add_argument('-o', '--output', default='output.csv', help='File name for output CSV, e.g. output.csv')
args = parser.parse_args()

calculations  = [
    {
        name: 'cosine',
        calculation: Cosine(),
        ngrams: 5,
    },
    {
        name: 'dice',
        calculation: Dice(),
        ngrams: 7,
    },
    {
        name: 'jaccard',
        calculation: Jaccard(),
        ngrams: 7,
    },
    {
        name: 'manhattan',
        calculation: Manhattan(),
        ngrams: 7,
    },
    {
        name: 'overlap',
        calculation: Overlap(),
        ngrams: 4,
    }
]

with open(os.path.join(os.path.dirname(__file__), 'tweets_corpus/similarity_dataset_15028.csv'), newline='\n') as csv_input:
    dataset = csv.reader(csv_input, delimiter=',', quotechar='"')
    tweets = [(line[0], line[1], line[2]) for line in dataset]

results = []

cleaned = [(time, tweet, category, cleaner.clean(tweet)) for (time, tweet, category) in tweets]
# tokenized = [(time, tweet, category, tokenizer.ngrams_tokenizer(cleaned_tweets, ngrams)) for (time, tweet, category, cleaned_tweets) in cleaned]

for (time, tweet, category, cleaned_tweets) in cleaned:
    for (time2, tweet2, category2, cleaned_tweets2) in cleaned:
        dt = datetime.strptime(time, '%Y-%m-%d %H:%M:%S')
        dt2 = datetime.strptime(time2, '%Y-%m-%d %H:%M:%S')

        if category2 == 'new' and dt2 > dt:
            cal_res = []
            for cal_obj in calculations:
                tweet_tokens = tokenizer.ngrams_tokenizer(cleaned_tweets, cal_obj.ngrams)
                tweet2_tokens = tokenizer.ngrams_tokenizer(cleaned_tweets2, cal_obj.ngrams)
                index = cal_obj.calculation.index(tweet_tokens, tweet2_tokens)
                cal_res.append(index)
            results.append([tweet, tweet2] + cal_res)

with open(os.path.join(os.path.dirname(__file__), args.output), 'a', newline='\n') as csv_output:
    csv_writer = csv.writer(csv_output, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
    # csv_writer.writerow([calculation, 'limit hours', ngrams, 'threshold', 'tp', 'tn', 'fp', 'fn', 'accuracy', 'precision', 'recall', 'f-score', 'time elapsed'])
    for result in results:
        csv_writer.writerow(result)

@@ -469,20 +469,22 @@
         
+'
 name
+'
 : 'cosin
@@ -487,32 +487,33 @@
 osine',%0A        
+'
 calculation: Cos
@@ -507,16 +507,17 @@
 culation
+'
 : Cosine
@@ -528,22 +528,24 @@
         
+'
 ngrams
+'
 : 5,%0A   
@@ -562,20 +562,22 @@
         
+'
 name
+'
 : 'dice'
@@ -578,32 +578,33 @@
 'dice',%0A        
+'
 calculation: Dic
@@ -598,16 +598,17 @@
 culation
+'
 : Dice()
@@ -609,38 +609,40 @@
 Dice(),%0A        
+'
 ngrams
+'
 : 7,%0A    %7D,%0A    
@@ -651,20 +651,22 @@
         
+'
 name
+'
 : 'jacca
@@ -670,32 +670,33 @@
 ccard',%0A        
+'
 calculation: Jac
@@ -690,16 +690,17 @@
 culation
+'
 : Jaccar
@@ -704,38 +704,40 @@
 card(),%0A        
+'
 ngrams
+'
 : 7,%0A    %7D,%0A    
@@ -746,20 +746,22 @@
         
+'
 name
+'
 : 'manha
@@ -767,32 +767,33 @@
 attan',%0A        
+'
 calculation: Man
@@ -787,16 +787,17 @@
 culation
+'
 : Manhat
@@ -811,22 +811,24 @@
         
+'
 ngrams
+'
 : 7,%0A   
@@ -845,20 +845,22 @@
         
+'
 name
+'
 : 'overl
@@ -872,16 +872,17 @@
         
+'
 calculat
@@ -884,16 +884,17 @@
 culation
+'
 : Overla
@@ -906,22 +906,24 @@
         
+'
 ngrams
+'
 : 4,%0A   
@@ -1863,39 +1863,42 @@
 _tweets, cal_obj
-.
+%5B'
 ngrams
+'%5D
 )%0A              
@@ -1966,23 +1966,26 @@
  cal_obj
-.
+%5B'
 ngrams
+'%5D
 )%0A      
@@ -2009,17 +2009,18 @@
  cal_obj
-.
+%5B'
 calculat
@@ -2022,16 +2022,18 @@
 culation
+'%5D
 .index(t

fix error dict