Exemplo n.º 1
0
 def setUp(self):
     loadrules()
     config = configparser.ConfigParser()
     config.read('cam-api.cfg')
     client = MongoClient(config['DATABASE']['dbURI'])
     self.db = client[config['DATABASE']['dbName']]
     self.db.tasks.delete_many({})
     self.priorities = ['high', 'medium', 'low']
Exemplo n.º 2
0
def main():
    rules = loadrules("spanish.yaml")

    trees = []
    ## I like Mary / María me gusta a mi
    trees.append(Tree("(S (NP (PRP I)) (VP (VB like) (NP (NNP Mary))))"))

    ## John usually goes home / Juan suele ir a casa
    trees.append(
        Tree("""
(S (NP (NNP John))
   (VP (RB usually)
       (VP (VBZ goes) (RB home))))
"""))

    ## John entered the house / Juan entró en la casa
    trees.append(
        Tree("""
(S (NP (NNP John))
   (VP (VBD entered) (NP (DT the) (NN house))))
"""))

    ## John broke into the room / Juan forzó la entrada al cuarto.
    trees.append(
        Tree("""
(S (NP (NNP John))
   (VP (VBD broke)
       (PP (IN into)
           (NP (DT the) (NN room)))))"""))

    ## I stabbed John / Yo le di puñaladas a Juan
    trees.append(Tree("(S (NP (PRP I)) (VP (VBD stabbed) (NP (NNP John))))"))

    for tree in trees:
        translate(tree, rules)
Exemplo n.º 3
0
def create_data(tree_file, rule_file, input_file, output_file):
    count = 0
    tried = 0
    rules = loadrules(rule_file)
    f = open(tree_file)
    input = open(input_file, "w+")
    output = open(output_file, "w+")
    line = f.readline()
    while line:
        tried = tried + 1
        tr = Tree.fromstring(line)
        theresults = transduce(tr, rules, "q")
        if (tried % 1000 == 0):
            print("Tried: " + str(tried))
            print("Generated: " + str(count))

        if (len(theresults) > 0):
            count = count + 1
            input.write(line)
            output.write(str(theresults[0].tree) + "\n")
        line = f.readline()
    print("Generated: " + str(count))
    f.close()
    input.close()
    output.close()
Exemplo n.º 4
0
def main():
    rules = loadrules("pokemon.yaml")
    trees = []
    trees.append(Tree.fromstring("(S let me show you my Pokémon)"))
    trees.append(Tree.fromstring("(S let me show you my cats)"))

    for tree in trees:
        translate(tree, rules)
Exemplo n.º 5
0
def main():
    rules = loadrules("pokemon.yaml")
    trees = []
    trees.append(Tree("(S let me show you my Pokémon)"))
    trees.append(Tree("(S let me show you my cats)"))

    for tree in trees: 
        translate(tree, rules)
Exemplo n.º 6
0
def main():
    tr = Tree("(A (B D E) (C F G))")
    rules = loadrules("figure5.yaml")

    theresults = transduce(tr, rules, "q")
    print("[[[done]]]")
    for (i, result) in enumerate(theresults):
        print("*** {0} ***".format(i))
        print(result)
Exemplo n.º 7
0
def main():
    tr = Tree("(A (B D E) (C F G))")
    rules = loadrules("figure5.yaml")

    theresults = transduce(tr, rules, "q")
    print("[[[done]]]")
    for (i, result) in enumerate(theresults):
        print("*** {0} ***".format(i))
        print(result)
Exemplo n.º 8
0
    def test_figure_five(self):
        tree = Tree("(A (B D E) (C F G))")
        rules = loadrules.loadrules("figure5.yaml")
        results = transduce.transduce(tree, rules, "q")
        trees = [ss.tree for ss in results]

        ss1 = transduce.SearchState(Tree("(A (R (T V W) U) (S X))"), {}, 0.27)
        ss2 = transduce.SearchState(Tree("(A (R (T V W) U) (S X))"), {}, 
                                          (1.0 * 0.4 * 1.0 * 0.1 * 0.5))

        self.assertIn(ss1, results)
        self.assertIn(ss2, results)
Exemplo n.º 9
0
def main():
    rules = loadrules("german.yaml")
    trees = []

    ## I like eating / Ich esse gern
    trees.append(Tree("(S (NP (PRP I)) (VP (VB like) (VBG eating)))"))

    ## I am hungry / Ich habe Hunger
    trees.append(Tree("(S (NP (PRP I)) (VP (VB am) (JJ hungry)))"))

    for tree in trees:
        translate(tree, rules)
Exemplo n.º 10
0
    def test_figure_five(self):
        tree = Tree("(A (B D E) (C F G))")
        rules = loadrules.loadrules("figure5.yaml")
        results = transduce.transduce(tree, rules, "q")
        trees = [ss.tree for ss in results]

        ss1 = transduce.SearchState(Tree("(A (R (T V W) U) (S X))"), {}, 0.27)
        ss2 = transduce.SearchState(Tree("(A (R (T V W) U) (S X))"), {},
                                    (1.0 * 0.4 * 1.0 * 0.1 * 0.5))

        self.assertIn(ss1, results)
        self.assertIn(ss2, results)
Exemplo n.º 11
0
def main():
    rules = loadrules("german.yaml")
    trees = []

    ## I like eating / Ich esse gern
    trees.append(Tree("(S (NP (PRP I)) (VP (VB like) (VBG eating)))"))

    ## I am hungry / Ich habe Hunger
    trees.append(Tree("(S (NP (PRP I)) (VP (VB am) (JJ hungry)))"))

    for tree in trees:
        translate(tree, rules)
Exemplo n.º 12
0
def main():
    intree = ImmutableTree("(foo bar)")
    outtree = ImmutableTree("(bar foo)")

    mutable = Tree("(foo bar)")
    imm = immutable(mutable)
    print(imm)

    rules = loadrules("testrules.yaml")
    setofrules = set()
    for rule in rules:
        setofrules.add(rule)
    print(setofrules)
    setofrules = frozenset(setofrules)

    ## XXX(alexr): do we need to make rules be sets?
    ## ah geez. let's just use frozenrules.
    print(produce(intree, outtree, setofrules, "q0", (0), (1)))
Exemplo n.º 13
0
def main():
    rules = loadrules('.'.join(sys.argv[1].split('.')[:-1]) + '.yaml')
    trees = []
    for tr in testerfi.readlines():
        trees.append(Tree(tr))
    for i, tree in enumerate(trees):
        print('input: ', tree._pprint_flat('', ['(', ')'], False))
        transout = translate(tree, rules)
        try:
            if ' '.join(Tree(transout[1]).leaves()).lower() != ' '.join(
                    Tree(outputcheck[i]).leaves()).lower():
                print('FAIL sent', i + 1, ': ')
                print(transout[1])
                print(outputcheck[i])
                print(' '.join(Tree(transout[1]).leaves()).lower())
                print(' '.join(Tree(outputcheck[i]).leaves()).lower())
                bad.append(i + 1)
                input('bad')
                #sys.exit(1)
            #translate(tree, rules)
            else:
                print('sent', i + 1, ': ')
                print(transout[1])
                print(outputcheck[i])
                print(' '.join(Tree(transout[1]).leaves()).lower())
                print(' '.join(Tree(outputcheck[i]).leaves()).lower())
                good.append(i + 1)
                #input('we got one')
        except TypeError:
            print('skipping sent', i + 1, '... no tree produced!')
            #print(transout[1])
            print(outputcheck[i])
            bad.append(i + 1)
            input('bad -- no tree!')
    print('got these right: ')
    print(good)
    print('got these wrong: ')
    print(bad)
Exemplo n.º 14
0
def main():
    rules = loadrules("spanish.yaml")

    trees = []
    ## I like Mary / María me gusta a mi
    trees.append( Tree("(S (NP (PRP I)) (VP (VB like) (NP (NNP Mary))))"))

    ## John usually goes home / Juan suele ir a casa
    trees.append(Tree(
"""
(S (NP (NNP John))
   (VP (RB usually)
       (VP (VBZ goes) (RB home))))
"""))

    ## John entered the house / Juan entró en la casa
    trees.append( Tree(
"""
(S (NP (NNP John))
   (VP (VBD entered) (NP (DT the) (NN house))))
"""))

    ## John broke into the room / Juan forzó la entrada al cuarto.
    trees.append(Tree(
"""
(S (NP (NNP John))
   (VP (VBD broke)
       (PP (IN into)
           (NP (DT the) (NN room)))))"""
    ))

    ## I stabbed John / Yo le di puñaladas a Juan
    trees.append( Tree("(S (NP (PRP I)) (VP (VBD stabbed) (NP (NNP John))))"))

    for tree in trees: 
        translate(tree, rules)
Exemplo n.º 15
0
 def setUp(self):
     self.rules = loadrules.loadrules("testrules.yaml")
Exemplo n.º 16
0
 def setUp(self):
     self.rules = loadrules.loadrules("testrules.yaml")
Exemplo n.º 17
0
#!/usr/bin/env python3

from nltk import Tree

from loadrules import loadrules
from translate import translate

import debugutil, sys
debugutil.DEBUGGING = False  #True

rules = loadrules(sys.argv[1])
testerfi = open(sys.argv[2])

good = []
bad = []


def main():
    trees = []
    for tr in testerfi.readlines():
        trees.append(Tree(tr))
    for i, tree in enumerate(trees):
        #print('input: ', tree._pprint_flat('', ['(', ')'], False))
        transout = translate(tree, rules)


if __name__ == "__main__":
    main()