Пример #1
0
def test(x):
    fh = FormatHa3()
    fpath = "data/109556"
    f = open(fpath)
    wf = open("query4test.109556.v1.txt", "a")
    doit = Doit()
    doit.setIndexList(x)
    i = 0
    flist = []
    for line in f:
        print "=========================%d======================" % i
        wf.write(line + "\n")
        line = fh.extractQuery(line)
        query = fh.removeFormula(line)
        query = fh.removeSummary(query)
        query = fh.replaceFormatValue(query)
        wf.write(str(i) + ":\n" + "os:" + query + "\n")
        #生成DSL
        query = fh.removeServiceIdInFilter(query)
        #query = fh.removeHeadAndTailQuoteOfQuery(query)
        if fpath.find("99141") > 0:
            query = fh.specialQuery(query)
        wf.write("es:" + doit.deal_api(query) + "\n")
        i += 1
        #if i >= 5:
        #break
    print flist
Пример #2
0
def beta(x, fpath, outpath):
    fh = FormatHa3()
    f = open(fpath)
    wf = open(outpath, "w")
    ff = open(outpath + ".failed", "w")
    doit = Doit()
    doit.setIndexList(x)
    i = 0
    flist = []
    for line in f:
        try:
            #print "=========================%d======================" % i
            #wf.write(line + "\n")
            query = fh.extractQuery(line)
            query = fh.removeFormula(query)
            query = fh.removeSummary(query)
            query = fh.replaceFormatValue(query)
            wf.write(str(i) + ":\n" + "OS.all:" + query + "\n")
            temp = query.split("&&")
            for item in temp:
                if (item.startswith("config")):
                    wf.write("OS.config:" + item + "\n")
                elif (item.startswith("query")):
                    wf.write("OS.query:" + item + "\n")
                elif (item.startswith("sort")):
                    wf.write("OS.sort:" + item + "\n")
                elif (item.startswith("filter")):
                    wf.write("OS.filter:" + item + "\n")
        #生成DSL
            query = fh.removeServiceIdInFilter(query)
            query = fh.removeHeadAndTailQuoteOfQuery(query)
            if fpath.find("99141") > 0:
                query = fh.specialQuery(query)
            wf.write("ES.all:" + doit.deal_api(query) + "\n")
            temp = doit.get_obj_by_function()
            wf.write("ES.query:" + temp['query'] + "\n")
            wf.write("ES.sort:" + temp['sort'] + "\n")
            wf.write("ES.filter:" + temp['filter'] + "\n")
            wf.write("ES.config:" + temp['config'] + "\n")
            #if i > 500:
            #break
        except Exception:
            wf.write("failed!\n")
            ff.write(line + "\n")
            flist.append(i)
            i += 1
            continue
        i += 1

    print "failed:"
    print flist
    wf.close()
    f.close()
Пример #3
0
        query = pattern.sub("",query)
        return query.replace("filter=&&","")

    def removeHeadAndTailQuoteOfQuery(self, query):
        pattern = re.compile(r"query=\((.*?)\)&&")
        res = re.findall(pattern,query)
        if len(res) == 0:
            return query
        return pattern.sub("query=%s&&" % res[0], query)
        

if "__main__" == __name__:
    fh = FormatHa3()
    f = open("testdata.txt")
    wf = open("outputdata.txt","a")
    doit = Doit()
    for line in f:
        line = fh.extractQuery(line)
        query = fh.removeFormula(line)
        query = fh.removeSummary(query)
        query = fh.replaceFormatValue(query)
        print "before:\n%s\nafter:\n%s" % (line, query)
        wf.write("os:"+query + "\n")
        #生成DSL
        query = fh.removeServiceIdInFilter(query)
        query = fh.removeHeadAndTailQuoteOfQuery(query)
        wf.write("es:"+doit.deal_api(query) + "\n")
        wf.flush()
    wf.close()
    f.close()
        
Пример #4
0
        query = pattern.sub("", query)
        return query.replace("filter=&&", "")

    def removeHeadAndTailQuoteOfQuery(self, query):
        pattern = re.compile(r"query=\((.*?)\)&&")
        res = re.findall(pattern, query)
        if len(res) == 0:
            return query
        return pattern.sub("query=%s&&" % res[0], query)


if "__main__" == __name__:
    fh = FormatHa3()
    f = open("testdata.txt")
    wf = open("outputdata.txt", "a")
    doit = Doit()
    for line in f:
        line = fh.extractQuery(line)
        query = fh.removeFormula(line)
        query = fh.removeSummary(query)
        query = fh.replaceFormatValue(query)
        print "before:\n%s\nafter:\n%s" % (line, query)
        wf.write("os:" + query + "\n")
        #生成DSL
        query = fh.removeServiceIdInFilter(query)
        query = fh.removeHeadAndTailQuoteOfQuery(query)
        wf.write("es:" + doit.deal_api(query) + "\n")
        wf.flush()
    wf.close()
    f.close()