# Path: basic/common.py
# 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    


import os
import sys
import numpy as np
from basic.common import checkToSkip
    from optparse import OptionParser
    

def process(options):

    overwrite = options.overwrite
    inputeFile = options.inputeFile
    weightFile = options.weightFile
    resultFile = options.resultFile

        
    weightFile = os.path.join('result', weightFile)
    weight = open(weightFile).readline().strip().split()
    weight = np.array(weight, dtype=np.float)

    resultFile = os.path.join('result', resultFile)
    if checkToSkip(resultFile, overwrite):
        sys.exit(0)
    fout = open(resultFile, 'w')

    done = 0
    for line in open(os.path.join('result', inputeFile)):
        elems = line.strip().split()
        vecs = map(float, elems[3:])
        vecs = np.array(vecs, dtype=np.float)

# Path: basic/common.py
# 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    


# Path: relevanceFusion.py
import os
import sys
import numpy as np
from basic.common import checkToSkip
    from optparse import OptionParser

    

def process(options):

    overwrite = options.overwrite
    inputeFile = options.inputeFile
    weightFile = options.weightFile
    resultFile = options.resultFile

        
    weightFile = os.path.join('result', weightFile)
    weight = open(weightFile).readline().strip().split()
    weight = np.array(weight, dtype=np.float)

    resultFile = os.path.join('result', resultFile)
    if checkToSkip(resultFile, overwrite):
        sys.exit(0)
    fout = open(resultFile, 'w')

    done = 0
    for line in open(os.path.join('result', inputeFile)):
        elems = line.strip().split()
        vecs = map(float, elems[3:])
        vecs = np.array(vecs, dtype=np.float)

        assert(len(weight) == len(vecs))