Example #1
0
def make_eq(q, a, VERBOSE, TRAIN):
    bigtexamples = {x: ([], []) for x in ["+", "*", '/', '-', '=']}
    #wps = open(q).readlines()
    #answs = open(a).readlines()
    #VERBOSE=True
    wps = q

    for k in range(len(wps)):
        if VERBOSE:
            for i in range(len(wps)):
                print(i, wps[i])
            k = int(input())
        print(k)
        problem = wps[k]
        #First preprocessing, tokenize slightly
        problem = problem.strip().split(" ")
        for i, x in enumerate(problem):
            if len(x) == 0: continue
            if x[-1] in [',', '.', '?']:
                problem[i] = x[:-1] + " " + x[-1]
        problem = ' '.join(problem)
        problem = " " + problem + " "
        print(problem)

        story = nlp.parse(problem)
        sets = makesets.makesets(story['sentences'])
        EF.main(sets, k, a[k], sys.argv[1])
        sets = [
            x for x in sets if makesets.floatcheck(x[1].num) or x[1].num == 'x'
        ]
        print(sets)
        for z in sets:
            z[1].details()
Example #2
0
def make_eq(q,a,VERBOSE,TRAIN):
    bigtexamples = {x:([],[]) for x in ["+","*",'/','-','=']}
    #wps = open(q).readlines()
    #answs = open(a).readlines()
    #VERBOSE=True
    wps = q

    for k in range(len(wps)):
        if VERBOSE:
            for i in range(len(wps)):
                print(i,wps[i])
            k = int(input())
        print(k)
        problem = wps[k]
        #First preprocessing, tokenize slightly
        problem = problem.strip().split(" ")
        for i,x in enumerate(problem):
            if len(x)==0:continue
            if x[-1] in [',','.','?']:
                problem[i] = x[:-1]+" "+x[-1]
        problem = ' '.join(problem)
        problem = " " + problem + " "
        print(problem)

        story = read_parse(k)
        sets = makesets.makesets(story['sentences'])
        pickle.dump(sets, open('madesets/'+str(k)+'.pickle','wb'))
        EF.main(sets,k,a[k],sys.argv[1])
        sets = [x for x in sets if makesets.floatcheck(x[1].num) or x[1].num == 'x']
        print(sets)
        for z in sets:
            z[1].details()
Example #3
0
def make_eq(q, a, VERBOSE, TRAIN):
    #wps = open(q).readlines()
    #answs = open(a).readlines()
    #VERBOSE=True
    wps = q

    for k in range(len(wps)):
        if VERBOSE:
            for i in range(len(wps)):
                print(i, wps[i])
            k = int(input())
        print(k)
        #First preprocessing, tokenize slightly
        problem = utils.preprocess_problem(wps[k])
        print(problem)

        story = utils.read_parse(k)
        sets = makesets.makesets(story['sentences'])
        EF.main(sets, k, a[k], sys.argv[1])
        sets = [
            x for x in sets if makesets.floatcheck(x[1].num) or x[1].num == 'x'
        ]
        print(sets)
        for z in sets:
            z[1].details()
Example #4
0
def make_eq(q, a, VERBOSE, TRAIN):
    #wps = open(q).readlines()
    #answs = open(a).readlines()
    #VERBOSE=True
    wps = q

    for k in range(len(wps)):
        if VERBOSE:
            for i in range(len(wps)):
                print(i, wps[i])
            k = int(input())
        print(k)
        #First preprocessing, tokenize slightly
        problem = utils.preprocess_problem(wps[k])
        print(problem)

        story = utils.read_parse(k)
        sets = makesets.makesets(story['sentences'])
        EF.main(sets, k, a[k], sys.argv[1])
        sets = [x for x in sets
                if makesets.floatcheck(x[1].num)
                or x[1].num == 'x']
        print(sets)
        for z in sets:
            z[1].details()
Example #5
0
def make_eq(q, a, VERBOSE, TRAIN):
    wps = q

    for k in range(len(wps)):
        if VERBOSE:
            for i in range(len(wps)):
                print(i, wps[i])
            k = int(input())
        print("Index: " + str(k))
        problem = wps[k]
        #First preprocessing, tokenize slightly
        problem = problem.strip().split(" ")
        for i, x in enumerate(problem):
            if len(x) == 0: continue
            if x[-1] in [',', '.', '?']:
                problem[i] = x[:-1] + " " + x[-1]
        problem = ' '.join(problem)
        problem = " " + problem + " "
        print("Problem: " + problem)
        print("Answer: " + a[k].strip())

        story = nlp.parse(problem)
        sets = makesets.makesets(story['sentences'])
        sets = [
            x for x in sets if makesets.floatcheck(x[1].num) or x[1].num == 'x'
        ]

        ents = [x[1].entity for x in sets]
        print("--- SETS ---")
        for z in sets:
            z[1].details()
Example #6
0
def make_eq(q, a, VERBOSE, TRAIN):
    wps = q

    replacements = {
        ' two ': ' 2 ',
        " three ": ' 3 ',
        ' four ': ' 4 ',
        ' five ': ' 5 ',
        ' six ': ' 6 ',
        ' seven ': ' 7 ',
        ' eight ': ' 8 ',
        ' nine ': ' 9 ',
        ' ten ': ' 10 ',
        ' eleven ': ' 11 ',
        ' twice ': ' 2 '
    }

    for k in range(len(wps)):
        if VERBOSE:
            for i in range(len(wps)):
                print(i, wps[i])
            k = int(input())
        print(k)
        problem = wps[k].lower()
        #First preprocessing, tokenize slightly
        problem = problem.strip().split(" ")
        for i, x in enumerate(problem):
            if len(x) == 0: continue
            if x[-1] in [',', '.', '?']:
                problem[i] = x[:-1] + " " + x[-1]
        problem = ' '.join(problem)
        problem = " " + problem + " "
        print(problem)

        for r in replacements:
            problem = problem.replace(r, replacements[r])

        story = nlp.parse(problem)
        sets = makesets.makesets(story['sentences'])
        EF.main(sets, k, a[k])
        sets = [
            x for x in sets if makesets.floatcheck(x[1].num) or x[1].num == 'x'
        ]
        print(sets)

        ents = [x[1].entity for x in sets]

        for z in sets:
            z[1].details()
Example #7
0
def make_eq(q, a, e, VERBOSE, TRAIN):
    bigtexamples = {x: ([], []) for x in ["+", "*", '/', '-', '=']}
    #wps = open(q).readlines()
    #answs = open(a).readlines()
    #VERBOSE=True
    wps = q

    for k in range(len(wps)):
        if VERBOSE:
            for i in range(len(wps)):
                print(i, wps[i])
            k = int(input())
        print(k)
        problem = wps[k]
        #First preprocessing, tokenize slightly
        problem = problem.strip().split(" ")
        for i, x in enumerate(problem):
            if len(x) == 0: continue
            if x[-1] in [',', '.', '?']:
                problem[i] = x[:-1] + " " + x[-1]
        problem = ' '.join(problem)
        problem = " " + problem + " "
        print(problem)

        story = read_parse(k)
        sets = makesets.makesets(story['sentences'])

        if e[k].strip() != '':
            irrelev = e[k].strip().split(" ")
            imap = [(x[-1], x) for x in irrelev]
            if not all([x[0] for x in imap]) == '0':
                print(imap)
                for x in [x for x in imap if x[0] == '0']:
                    ent, num, v = x[1].split(',')
                    if ent in ["$", "dollar"]: continue
                    else:
                        sets = [x for x in sets if x[1].num != num]

        pickle.dump(sets, open('madesets/' + str(k) + '.pickle', 'wb'))
        EF.main(sets, k, a[k], sys.argv[1])
        sets = [
            x for x in sets if makesets.floatcheck(x[1].num) or x[1].num == 'x'
        ]
        print(sets)
        for z in sets:
            z[1].details()
Example #8
0
def make_eq(q, a, VERBOSE, TRAIN, fold):
    bigtexamples = {x: ([], []) for x in ["+", "*", '/', '-', '=']}
    #wps = open(q).readlines()
    #answs = open(a).readlines()
    #VERBOSE=True
    wps = q
    predicates = []

    for k in range(len(wps)):
        if VERBOSE:
            for i in range(len(wps)):
                print(i, wps[i])
            k = int(input())
        print(k)
        problem = wps[k].lower()
        #First preprocessing, tokenize slightly
        problem = problem.strip().split(" ")
        for i, x in enumerate(problem):
            if len(x) == 0: continue
            if x[-1] in [',', '.', '?']:
                problem[i] = x[:-1] + " " + x[-1]
        problem = ' '.join(problem)
        problem = " " + problem + " "
        print(problem)

        story = nlp.parse(problem)
        sets = makesets.makesets(story['sentences'])
        #EF.main(sets,k)
        sets = [
            x for x in sets if makesets.floatcheck(x[1].num) or x[1].num == 'x'
        ]
        print(sets)
        for z in sets:
            if z[1].verbs:
                predicates.extend(z[1].verbs.split(" "))

    predicates = list(set(predicates))
    pickle.dump(predicates, open("data/predicates" + fold, 'wb'))
Example #9
0
def make_eq(q,a,VERBOSE,TRAIN):
    bigtexamples = {x:([],[]) for x in ["+","*",'/','-','=']}
    #wps = open(q).readlines()
    #answs = open(a).readlines()
    #VERBOSE=True
    wps = q

    IRR = open("output_relevant.txt").readlines()
    IRR = [x.strip().split(" ") for x in IRR]
    IRR = [[y.split(",")[1:] for y in x] for x in IRR]

    wps = pickle.load(open('irrelevSets.pickle','rb'))
    

    


    for k, sets in wps:
        print(k)
        EF.main(sets,k,a[k])
        sets = [x for x in sets if makesets.floatcheck(x[1].num) or x[1].num == 'x']
        print(sets)
        for z in sets:
            z[1].details()
Example #10
0
def make_eq(q, a, VERBOSE, TRAIN):
    bigtexamples = {x: ([], []) for x in ["+", "*", '/', '-', '=']}
    #wps = open(q).readlines()
    #answs = open(a).readlines()
    #VERBOSE=True
    wps = q

    replacements = {
        ' two ': ' 2 ',
        " three ": ' 3 ',
        ' four ': ' 4 ',
        ' five ': ' 5 ',
        ' six ': ' 6 ',
        ' seven ': ' 7 ',
        ' eight ': ' 8 ',
        ' nine ': ' 9 ',
        ' ten ': ' 10 ',
        ' eleven ': ' 11 ',
        ' twice ': ' 2 '
    }

    for k in range(len(wps)):
        if VERBOSE:
            for i in range(len(wps)):
                print(i, wps[i])
            k = int(input())
        print(k)
        problem = wps[k].lower()
        #First preprocessing, tokenize slightly
        problem = problem.strip().split(" ")
        for i, x in enumerate(problem):
            if len(x) == 0: continue
            if x[-1] in [',', '.', '?']:
                problem[i] = x[:-1] + " " + x[-1]
        problem = ' '.join(problem)
        problem = " " + problem + " "
        print(problem)

        for r in replacements:
            problem = problem.replace(r, replacements[r])
        '''
        if " how " in problem:
            left,right = problem.split(" how ")
        else: left = problem

        for r in replacements:
            left = left.replace(r,replacements[r])
        if " how " in problem:
            problem = left + ' how ' + right
        else:
            problem = left
        '''

        story = nlp.parse(problem)
        sets = makesets.makesets(story['sentences'])
        #EF.main(sets,k)
        sets = [
            x for x in sets if makesets.floatcheck(x[1].num) or x[1].num == 'x'
        ]
        print(sets)
        for z in sets:
            z[1].details()