Generic method to generate a dict of information given a file
(
file,
session = None)
| 516 | |
| 517 | |
| 518 | def build_text_packet( |
| 519 | file, |
| 520 | session = None): |
| 521 | """ |
| 522 | Generic method to generate a dict of information given a file |
| 523 | """ |
| 524 | |
| 525 | file.text_file.serialize(session = session) |
| 526 | tokens = file.text_file.get_text_tokens(file.text_tokenizer) |
| 527 | text_dict = { |
| 528 | 'original_filename': file.text_file.original_filename, |
| 529 | 'signed_expiry': file.text_file.url_signed_expiry, |
| 530 | 'signed_url': file.text_file.url_signed, |
| 531 | 'tokens': tokens |
| 532 | } |
| 533 | |
| 534 | instance_dict_list = [] |
| 535 | relations_list = [] |
| 536 | |
| 537 | instance_list = Instance.list( |
| 538 | session = session, |
| 539 | file_id = file.id) |
| 540 | |
| 541 | for instance in instance_list: |
| 542 | if instance.type == 'relation': |
| 543 | continue |
| 544 | instance_dict_list.append(build_instance(instance, file)) |
| 545 | |
| 546 | for relation in instance_list: |
| 547 | if relation.type != 'relation': |
| 548 | continue |
| 549 | relations_list.append(build_relation(relation = relation)) |
| 550 | |
| 551 | |
| 552 | instance_dict_list = instance_dict_list + relations_list |
| 553 | |
| 554 | return {'file': { |
| 555 | 'id': file.id, |
| 556 | 'original_filename': file.original_filename, |
| 557 | 'blob_url': file.text_file.url_signed, |
| 558 | 'created_time': str(file.created_time), |
| 559 | 'ann_is_complete': file.ann_is_complete, |
| 560 | 'type': file.type |
| 561 | }, |
| 562 | 'text': text_dict, |
| 563 | 'instance_list': instance_dict_list} |
| 564 | |
| 565 | |
| 566 | def build_sensor_fusion_packet( |
no test coverage detected