Esempio n. 1
0
def on_the_truck_cost(cf):
    state, am = waverly_state_truck()
    print state.orientation
    #state.orientation = 3.14/6
    cf.initialize_state(state)

    extractor = Extractor()
    esdcs = extractor.extractEsdcs("next to the truck.")

    place_esdc = esdcs[0]
    place_esdc.type = "PLACE"
    truck_esdc = place_esdc.l[0]
    print "place", place_esdc, place_esdc.type
    print "truck", truck_esdc

    searcher = BeamSearch(cf)
    annotation = initial_annotation(state, esdcs[0])

    truck = [
        state.getGroundableById(o) for o in state.getObjectsSet()
        if 'flatbed' in state.getGroundableById(o).tags
    ][0]

    annotation.setGrounding(truck_esdc, truck)
    annotation.setGrounding("sequence", [(state, None)])

    obj = prism_from_point(0,
                           0,
                           truck.centroid3d[2] + .2,
                           truck.centroid3d[2] + .5,
                           width=0.5)

    #axes = p.axes()
    featureBrowser = crfFeatureWeights.MainWindow()
    featureBrowser.show()
    axes = featureBrowser.axes
    for o in state.getObjectsSet():
        drawObject(axes, state.getGroundableById(o))

    drawPlaceCostMap(featureBrowser, obj, place_esdc, annotation, searcher, -5,
                     10, 25, 40, .2)
    #p.axes().set_aspect('equal')
    #p.show()
    state, gggs = annotation_to_ggg_map(annotation)
    ggg = gggs[place_esdc]
    #ggg = ggg_from_esdc(esdcs[0])
    factor = ggg.esdc_to_factor(place_esdc)
    print "factor", factor, factor.id
    print "cache", cf.factor_to_cost
    factor_to_cost = cf.factor_to_cost[factor]

    print "cache", factor_to_cost
    featureBrowser.load(cf.lccrf, factor_to_cost)
Esempio n. 2
0
def main():
    parser = OptionParser()
    parser.add_option("--source_corpus",
                      dest="source_corpus",
                      help="The file or directory to read from")
    parser.add_option("--dest_corpus",
                      dest="dest_corpus",
                      help="The yaml file to which data will be written")
    (options, args) = parser.parse_args()

    corpus = readCorpus.Corpus(options.source_corpus)
    extractor = Extractor()
    #oldCorpus = annotationIo.load("%s/dataAnnotation/data/forkliftMturkEsdcs.stefie10.groundings.withPaths.yaml" % os.environ['FORKLIFT_HOME'])
    #oldAssignmentIds = set(a.assignmentId for a in oldCorpus)
    #print len(oldAssignmentIds), "old ids"
    yamlData = []
    print len(corpus.assignments), "assignments"
    filteredAnnotations = [
        x for x in corpus.assignments if (x.scenario.platform == "forklift"
                                          and x.scenario.isSimulated == True)
    ]
    print len(filteredAnnotations), "filtered annotations"
    output_annotations = []
    for i, a in enumerate(filteredAnnotations):
        esdcs = extractor.extractEsdcs(a.command)
        assignmentId = a.assignmentId
        agent = a.agent
        context = a.context
        esdcSource = [assignmentId for esdc in esdcs.flattenedEsdcs]
        output_annotations.append(
            Annotation(assignmentId=assignmentId,
                       esdcs=esdcs,
                       objectGroundings=None,
                       groundingIsCorrect=None,
                       agent=agent,
                       context=context,
                       esdcSource=esdcSource))
        esdcYaml = toYaml(esdcs)
        print "******"
        print a, esdcYaml
        print esdcs

        yamlData.append({"command": esdcYaml, "assignmentId": a.assignmentId})

    print "dumped", i, "commands."
    yaml.dump(yamlData, open(options.dest_corpus, "w"))
Esempio n. 3
0
def approach_the_truck_cost_path(cf):
    state, am = waverly_state_truck()
    cf.initialize_state(state)

    extractor = Extractor()
    esdcs = extractor.extractEsdcs("Approach the truck.")
    event_esdc = esdcs[0]
    truck_esdc = event_esdc.l[0]
    annotation = initial_annotation(state, esdcs[0])

    truck = [o for o in state.objects if 'flatbed' in o.tags][0]

    annotation.setGrounding(truck_esdc, truck)
    featureBrowser = crfFeatureWeights.MainWindow()
    featureBrowser.show()
    ggg = drawAgentPathCostMap(featureBrowser, [event_esdc], annotation, cf,
                               -15, 25, 15, 50, 1)
    factor = ggg.esdc_to_factor(event_esdc)
    featureBrowser.load(annotation.context, cf, factor)
Esempio n. 4
0
def pick_up_the_pallet_cost_pickup(cf):
    state, am = waverly_state_truck()
    cf.initialize_state(state)

    extractor = Extractor()
    esdcs = extractor.extractEsdcs("Pick up the tire pallet.")
    event_esdc = esdcs[0]
    print 'event', event_esdc
    #    pickup_esdc = event_esdc.r
    #    print 'pickup', pickup_esdc
    pallet_esdc = event_esdc.l[0]
    print "pallet", pallet_esdc
    annotation = initial_annotation(state, esdcs[0])

    pallet = [o for o in state.objects if 'tire' in o.tags][0]

    annotation.setGrounding(pallet_esdc, pallet)
    featureBrowser = crfFeatureWeights.MainWindow()
    featureBrowser.show()
    ggg = drawObjectPathCostMap(featureBrowser, pallet_esdc, [event_esdc],
                                annotation, cf, -20, 40, 15, 50, 1)
    factor = ggg.esdc_to_factor(event_esdc)
    featureBrowser.load(annotation.context, cf, factor)
Esempio n. 5
0
def main():

    extractor = Extractor()
    oldCorpus = annotationIo.load("%s/dataAnnotation/data/forkliftMturkEsdcs.stefie10.groundings.withPaths.yaml" % os.environ['FORKLIFT_HOME'])
    annotations = []
    for i, a in enumerate(oldCorpus):
#        if i != 140:
#            continue
        print "doing", i, a.entireText
        automatic_esdcs_groups = extractor.extractTopNEsdcs(a.entireText, n=10)

        
        for automatic_esdc_group in automatic_esdcs_groups:
            annotation = annotationIo.Annotation(a.assignmentId,
                                                 automatic_esdc_group)
            
            for automatic_esdc in automatic_esdc_group.flattenedEsdcs:
                if automatic_esdc in a.flattenedEsdcs:
                    annotation.setGroundingIsCorrect(automatic_esdc, True)
                else:
                    annotation.setGroundingIsCorrect(automatic_esdc, False)

            annotations.append(annotation)
    annotationIo.save(annotationIo.Corpus(annotations), "negativeEsdcs.yaml")
Esempio n. 6
0
def tp_test():
    ex = Extractor()
    #parse = ex.extractEsdcs("Pick up the tire pallet next to the truck.")
    parse = ex.extractEsdcs("Put the tire pallet on storage.")
    esdc = parse[0]

    am = action_map.action_map(
        "../../data/directions/forklift/partitions/forklift_full_part.pck")
    tp = task_planner(am, gen_cost, gen_cost, gen_cost, gen_cost)

    s1 = fork_state.fork_state()
    s1.pallets = [pallet_t(), pallet_t()]
    s1.objects = [object_t(), object_t()]

    s1.pallets[0].id = 0
    s1.pallets[0].label = pallet_t.LABEL_TIRE
    s1.pallets[0].pos = [88, 125, 0]
    s1.pallets[0].bbox_min = [88, 125, 0]
    s1.pallets[0].bbox_max = [89, 126, 0]

    s1.pallets[1].id = 1
    s1.pallets[1].label = pallet_t.LABEL_ENGINE
    s1.pallets[1].pos = [113, 41, 0]
    s1.pallets[1].bbox_min = [113, 41, 0]
    s1.pallets[1].bbox_max = [114, 42, 0]

    s1.objects[0].object_type = object_enum_t.FLATBED_TRUCK
    s1.objects[0].pos = [88, 125, 0]
    s1.objects[0].bbox_min = [88, 125, 0]
    s1.objects[0].bbox_max = [89, 126, 0]

    s1.objects[1].object_type = object_enum_t.FLATBED_TRAILER
    s1.objects[1].pos = [88, 125, 0]
    s1.objects[1].bbox_min = [88, 125, 0]
    s1.objects[1].bbox_max = [89, 126, 0]

    rndf_map = rndf("../../data/directions/forklift/Lee_RNDF_demo.txt")
    s1.zones = rndf_map.zone_polygons[:]

    s1.agent = 0

    plan = tp.find_plan(esdc, s1, 100)
    c, p = plan[0]

    def printMapping(x):
        if hasattr(p[x], 'tag'):
            print 'mapped ', x.type, map(lambda s: s.text,
                                         x.f), ' to ', p[x].tag
        elif x.type == 'EVENT':
            print 'mapped', x.type, 'to:'
            ss = p[x]
            for s, a in ss:
                if a != None:
                    print a, am.index_to_location(a.to_loc)
        else:
            print 'mapped', x.type, '(' + str(x) + ')', ' to ', p[x]
        print '---------------------'

    print '-----------------'
    ds.breadthFirstTraverse(esdc, printMapping)
    print c
Esempio n. 7
0
 def setUpClass(cls):
     cls.extractor = Extractor()
Esempio n. 8
0
from esdcs.extractor.stanfordParserExtractor import Extractor as StanfordExtractor
from g3.esdcs_to_ggg import ggg_from_esdc_group
from yn_dialog.graph import YNGGG
from coreference.merge_coreferences import renumber_ggg_ids, merge_gggs
from dialog.question_answer_corpus import QACorpus

qa_corpus = QACorpus([])

sentence = 'Pick up the tire pallet near the truck.'
# sentence = 'Turn away from the truck and move forward'
# sentence = "I went to the store."
# sentence = 'Raise the forks, turn right, and proceed forward for a few seconds.'

stanford_extractor = StanfordExtractor()
stanford_esdcs = stanford_extractor.extractEsdcs(sentence)
ggg = ggg_from_esdc_group(stanford_esdcs)
ggg, max_id = renumber_ggg_ids(ggg, 0)

target_node_id = '4'
target_node = ggg.node_from_id(target_node_id)
target_factors = ggg.factors_for_node(target_node, 'top')
target_esdc = ggg.factor_to_esdc(target_factors[0])
target_text = target_esdc.text

command_text = ggg.entireText
oid = '??'
question_text = qa_corpus.generate_base_question_text(
    target_text) + " " + oid + "?"
qa_text = question_text + " " + "Yes."
yn_ggg = YNGGG.from_dialog(ggg.entireText, qa_text, True)
yn_ggg, max_id = renumber_ggg_ids(yn_ggg, max_id)