# Path: general/filePath.py



import json
import unicodecsv as csv
import numpy as np
from os import path, makedirs
from general.eval import *
from general.filePath import class_name
from scipy.stats import norm
        if ranking <= N:
            list_lessNRank.append([phrase_name,ranking])

    if writecsv and len(list_lessNRank):
        path_less3Lyrics = path.join(currentPath,'..','errorAnalysis/less'+str(N)+'.csv')
        with open(path_less3Lyrics,'wb') as csvfile:
            w = csv.writer(csvfile)
            for lN in list_lessNRank:
                w.writerow(lN)
    return list_lessNRank

def compareMelodicSimiResults(path_largerPyin,list_lessNRank_phrase_name):
    '''
    compare with the results of melodic similarity
    find the intersection set, melodic similarity ranking > N, phonetic similarity ranking < N
    :param path_largerPyin: path of the melodic similarity csv
    :param list_lessNRank_phrase_name: ranking less than N phrase name by phonetic similarity
    :return: intersection set of the phrase name
    '''
    phrase_names_largerN = []
    with open(path_largerPyin,'r') as openfile:
        csv_reader = csv.reader(openfile,delimiter=',')
        for row in csv_reader:
            phrase_names_largerN.append(row[0])

    return set.intersection(set(phrase_names_largerN),set(list_lessNRank_phrase_name))

def resultAnalysisProcess(method, proportionality_std=0, path_json_dict_query_phrases='dummy', am='gmm', cnn_file_name=''):

    # path for storing matching ranking result csv

# Path: general/filePath.py



# Path: phoneticSimilarity/lyricsRecognizer/resultAnalysis.py
import json
import unicodecsv as csv
import numpy as np
from os import path, makedirs
from general.eval import *
from general.filePath import class_name
from scipy.stats import norm

        if ranking <= N:
            list_lessNRank.append([phrase_name,ranking])

    if writecsv and len(list_lessNRank):
        path_less3Lyrics = path.join(currentPath,'..','errorAnalysis/less'+str(N)+'.csv')
        with open(path_less3Lyrics,'wb') as csvfile:
            w = csv.writer(csvfile)
            for lN in list_lessNRank:
                w.writerow(lN)
    return list_lessNRank

def compareMelodicSimiResults(path_largerPyin,list_lessNRank_phrase_name):
    '''
    compare with the results of melodic similarity
    find the intersection set, melodic similarity ranking > N, phonetic similarity ranking < N
    :param path_largerPyin: path of the melodic similarity csv
    :param list_lessNRank_phrase_name: ranking less than N phrase name by phonetic similarity
    :return: intersection set of the phrase name
    '''
    phrase_names_largerN = []
    with open(path_largerPyin,'r') as openfile:
        csv_reader = csv.reader(openfile,delimiter=',')
        for row in csv_reader:
            phrase_names_largerN.append(row[0])

    return set.intersection(set(phrase_names_largerN),set(list_lessNRank_phrase_name))

def resultAnalysisProcess(method, proportionality_std=0, path_json_dict_query_phrases='dummy', am='gmm', cnn_file_name=''):

    # path for storing matching ranking result csv

    results_path = path.join(currentPath, '..', 'results/'+method+'_'+class_name)