def parse_QA(data, image_map): """ Helper to parse a list of question answers. """ qas = [] for info in data: qos = [] aos = [] if 'question_objects' in info: for qo in info['question_objects']: synset = Synset(qo['synset_name'], qo['synset_definition']) qos.append( QAObject(qo['entity_idx_start'], qo['entity_idx_end'], qo['entity_name'], synset)) pass if 'answer_objects' in info: for ao in info['answer_objects']: synset = Synset(ao['synset_name'], ao['synset_definition']) aos.append( QAObject(ao['entity_idx_start'], ao['entity_idx_end'], ao['entity_name'], synset)) pass qas.append( QA(info['id'], image_map[info['image']], info['question'], info['answer'], qos, aos)) pass return qas
def ParseQA(data, image_map): qas = [] for d in data: qos = [] aos = [] if 'question_objects' in d: for qo in d['question_objects']: synset = Synset(qo['synset_name'], qo['synset_definition']) qos.append(QAObject(qo['entity_idx_start'], qo['entity_idx_end'], qo['entity_name'], synset)) if 'answer_objects' in d: for ao in d['answer_objects']: synset = Synset(o['synset_name'], ao['synset_definition']) aos.append(QAObject(ao['entity_idx_start'], ao['entity_idx_end'], ao['entity_name'], synset)) qas.append(QA(d['id'], image_map[d['image']], d['question'], d['answer'], qos, aos)) return qas
def parse_synset(canon): """ Helper to Extract Synset from canon object. """ if len(canon) == 0: return None return Synset(canon[0]['synset_name'], canon[0]['synset_definition'])
def InitSynsets(scene_graph, synset_file): syn_data = json.load(open(synset_file, 'r')) syn_class = {s['synset_name'] : Synset(s['synset_name'], s['synset_definition']) for s in syn_data} for obj in scene_graph.objects: obj.synsets = [syn_class[sn] for sn in obj.synsets] for rel in scene_graph.relationships: rel.synset = [syn_class[sn] for sn in rel.synset] for attr in scene_graph.attributes: obj.synset = [syn_class[sn] for sn in attr.synset] return scene_graph
def ParseSynset(canon): if len(canon) == 0: return None return Synset(canon[0]['synset_name'], canon[0]['synset_definition'])