<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def add_value(self, field_name: str, value: object = None, json_path: str = None, json_path_extraction: str = None, keep_empty: bool = False) -> None: """ Add a value to knowledge graph. Input can either be a value or a json_path. If the input is json_path, the helper function _add_doc_value is called. If the input is a value, then it is handled Args: field_name: str, the field name in the knowledge graph value: the value to be added to the knowledge graph json_path: str, if json_path is provided, then get the value at this path in the doc json_path_extraction: str, discard_empty: bool, Returns: """


        def validate(v):
            if v is not None:
                if isinstance(v, str):
                    if v.strip() != "" or keep_empty:
                        return True
                    else:
                        return False
                else:
                    return True
            return False

        self.validate_field(field_name)
        if field_name not in self._kg:
            self._kg[field_name] = []

        if json_path:
            self._add_doc_value(field_name, json_path)

        if validate(value):
            if not isinstance(value, list):
                value = [value]

            all_valid = True
            invalid = []
            for a_value in value:
                if isinstance(a_value, Extraction):
                    valid = self._add_single_value(field_name, a_value.value, provenance_path=str(json_path_extraction),
                                                   keep_empty=keep_empty)
                elif isinstance(a_value, Segment):
                    valid = self._add_single_value(field_name, a_value.value, provenance_path=a_value.json_path,
                                                   keep_empty=keep_empty)
                else:
                    valid = self._add_single_value(field_name, a_value, provenance_path=json_path_extraction,
                                                   reference_type="constant", keep_empty=keep_empty)

                all_valid = all_valid and valid
                if not valid:
                    invalid.append(field_name + ":" + str(a_value))
            if not all_valid:
                print("Some kg value type invalid according to schema:" + json.dumps(invalid))
                # raise KgValueError("Some kg value type invalid according to schema")
        # IF we did not add any value, remove the empty field we just added to kg
        if len(self._kg[field_name]) == 0:
            self._kg.pop(field_name)