# Path: util/tools.py
# def readQidQuery(inputfile):
#     data = [ x.strip().split(" ", 1) for x in open(inputfile).readlines()]
#     qid = [x[0] for x in data]
#     query = [x[1] for x in data]
#     return (qid, query)
# 
# Path: basic/common.py
# ROOT_PATH = "/home/b/VisualSearch1"
# 
# def printMessage(message_type, trace, message):
#     print ('%s %s [%s] %s' % (time.strftime('%d/%m/%Y %H:%M:%S'), message_type, trace, message))
# 
# def checkToSkip(filename, overwrite):
#     if os.path.exists(filename):
#         print ("%s exists." % filename),
#         if overwrite:
#             print ("overwrite")
#             return 0
#         else:
#             print ("skip")
#             return 1
#     return 0    
# 
# def makedirsforfile(filename):
#     try:
#         os.makedirs(os.path.split(filename)[0])
#     except:
#         pass


import os,sys
from util.tools import readQidQuery
from basic.common import ROOT_PATH, printMessage, checkToSkip, makedirsforfile
    from optparse import OptionParser

def readAnnotations(inputfile):
    return [(str.split(x)[0], str.split(x)[1].strip()) for x in open(inputfile).readlines()]

def checkSameList(list1, list2):
    if len(list1) == len(list2):
        for i in xrange(len(list1)):
            if list1[i] != list2[i]:
                return False
    else:
        return False
    return True


def process(options, collection):
    rootpath = options.rootpath
    overwrite = options.overwrite
    inputfile = options.inputfile
    resultname = options.resultname

    result_file = os.path.join('result', resultname)
    if checkToSkip(result_file, overwrite):
       sys.exit(0)
    makedirsforfile(result_file)

    # inpute of query
    qid_query_file = os.path.join(rootpath, collection, 'Annotations', 'qid.text.txt')
    qid_list, query_list = readQidQuery(qid_query_file)

    num2file = {}

# Path: util/tools.py
# def readQidQuery(inputfile):
#     data = [ x.strip().split(" ", 1) for x in open(inputfile).readlines()]
#     qid = [x[0] for x in data]
#     query = [x[1] for x in data]
#     return (qid, query)
# 
# Path: basic/common.py
# ROOT_PATH = "/home/b/VisualSearch1"
# 
# def printMessage(message_type, trace, message):
#     print ('%s %s [%s] %s' % (time.strftime('%d/%m/%Y %H:%M:%S'), message_type, trace, message))
# 
# def checkToSkip(filename, overwrite):
#     if os.path.exists(filename):
#         print ("%s exists." % filename),
#         if overwrite:
#             print ("overwrite")
#             return 0
#         else:
#             print ("skip")
#             return 1
#     return 0    
# 
# def makedirsforfile(filename):
#     try:
#         os.makedirs(os.path.split(filename)[0])
#     except:
#         pass


# Path: combine_result.py
import os,sys
from util.tools import readQidQuery
from basic.common import ROOT_PATH, printMessage, checkToSkip, makedirsforfile
    from optparse import OptionParser


def readAnnotations(inputfile):
    return [(str.split(x)[0], str.split(x)[1].strip()) for x in open(inputfile).readlines()]

def checkSameList(list1, list2):
    if len(list1) == len(list2):
        for i in xrange(len(list1)):
            if list1[i] != list2[i]:
                return False
    else:
        return False
    return True


def process(options, collection):
    rootpath = options.rootpath
    overwrite = options.overwrite
    inputfile = options.inputfile
    resultname = options.resultname

    result_file = os.path.join('result', resultname)
    if checkToSkip(result_file, overwrite):
       sys.exit(0)
    makedirsforfile(result_file)

    # inpute of query
    qid_query_file = os.path.join(rootpath, collection, 'Annotations', 'qid.text.txt')
    qid_list, query_list = readQidQuery(qid_query_file)

    num2file = {}

    num2file[0] = os.path.join(rootpath, collection, 'Annotations', 'Image', 'concepts%s.txt' % collection)