doccano / auto-labeling-pipeline

doccano auto labeling pipeline helps doccano to annotate a document automatically.
MIT License
40 stars 16 forks source link

Custom Request does not support lists #16

Open rmporsch opened 3 years ago

rmporsch commented 3 years ago

Given we have the following request body:

{
  "instances": [
    {
      "text": "{{ text }}"
    }
    ]
}

The following method is unable to replace "{{ text }}" with the appropriate text.

def find_and_replace_value(obj, value, target='{{ text }}'):
    for k, v in obj.items():
        if v == target:
            obj[k] = value
            return
        if isinstance(v, dict):
            find_and_replace_value(v, value, target)

The proposed changes would address this issue.

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

How Has This Been Tested?

My test cases

Test A:

test_a = {
    "instances": [
        {
            "text": "{{ text }}"
        }
    ]
}

Test B

test_a = {
    "instances": [[
        {
            "text": "{{ text }}"
        }
    ]]
}

Checklist:

rmporsch commented 3 years ago

As a side question to this PR: image This seems not to be the correct way to do it. Since the value seems to be passed as string if I am not wrong. So how would I pass a nested dict in the body? Is the value ever serialized?

rmporsch commented 3 years ago

@Hironsan not sure who the right person for this is but would love to get this merged.