Пример #1
0
 def _get_invalid_choices(self, saved_field: DocumentField) -> set:
     # old_choices = set()
     # if not saved_field.allow_values_not_specified_in_choices and \
     #         not self.object.allow_values_not_specified_in_choices:
     old_choices = set(saved_field.get_choice_values())
     for choice_value in self.object.get_choice_values():
         if choice_value in old_choices:
             old_choices.remove(choice_value)
     return old_choices
Пример #2
0
    def save_detected_values(document: Document, field: DocumentField,
                             field_type_adapter: FieldType,
                             detected_values: List[DetectedFieldValue],
                             do_not_write: bool):
        if len(detected_values) == 0:
            return 0

        try:
            if field.is_choice_field() and not field_type_adapter.multi_value:
                values_order = field.get_choice_values()
                for choice_value in values_order:
                    for dv in detected_values:
                        if choice_value == dv.value:
                            if not do_not_write:
                                field_type_adapter.save_value(
                                    document,
                                    field,
                                    dv.get_annotation_start(),
                                    dv.get_annotation_end(),
                                    dv.get_annotation_text(),
                                    dv.text_unit,
                                    dv.value,
                                    user=None,
                                    allow_overwriting_user_data=False,
                                    extraction_hint=dv.hint_name)
                            return 1
            else:
                for dv in detected_values:
                    if not do_not_write:
                        field_type_adapter.save_value(
                            document,
                            field,
                            dv.get_annotation_start(),
                            dv.get_annotation_end(),
                            dv.get_annotation_text(),
                            dv.text_unit,
                            dv.value,
                            user=None,
                            allow_overwriting_user_data=False,
                            extraction_hint=dv.hint_name)
                return len(detected_values)
        finally:
            document.cache_field_values()
def save_detected_values(document: Document, field: DocumentField,
                         detected_values: List[DetectedFieldValue]):
    if len(detected_values) == 0:
        return 0

    field_type_adapter = FIELD_TYPES_REGISTRY[field.type]  # type: FieldType

    if field.is_choice_field() and not field_type_adapter.multi_value:
        values_order = field.get_choice_values()
        for choice_value in values_order:
            for dv in detected_values:
                if choice_value == dv.value:
                    field_type_adapter.save_value(
                        document,
                        field,
                        dv.get_annotation_start(),
                        dv.get_annotation_end(),
                        dv.get_annotation_text(),
                        dv.text_unit,
                        dv.value,
                        user=dv.user,
                        allow_overwriting_user_data=dv.user is not None,
                        extraction_hint=dv.hint_name)
                    return 1
    else:
        for dv in detected_values:
            field_type_adapter.save_value(document,
                                          field,
                                          dv.get_annotation_start(),
                                          dv.get_annotation_end(),
                                          dv.get_annotation_text(),
                                          dv.text_unit,
                                          dv.value,
                                          user=dv.user,
                                          allow_overwriting_user_data=dv.user
                                          is not None,
                                          extraction_hint=dv.hint_name)
        return len(detected_values)
Пример #4
0
 def get_categories(cls, field: DocumentField) -> List[str]:
     categories = set(field.get_choice_values())
     if field.unsure_choice_value:
         categories.remove(field.unsure_choice_value)
     return sorted(categories)
Пример #5
0
 def get_categories(cls, field: DocumentField) -> List[str]:
     return sorted(field.get_choice_values())
Пример #6
0
 def _get_invalid_choices(self, saved_field: DocumentField) -> set:
     old_choices = set(saved_field.get_choice_values())
     for choice_value in self.object.get_choice_values():
         if choice_value in old_choices:
             old_choices.remove(choice_value)
     return old_choices