Inserting Span and Arrow Label into Document

In Span Based Labeling, we have 2 different kinds of label:

  • Span Label: Label applied to a span of tokens

  • Arrow Label: Label which points from a Span Label to another Span Label

cURL

Use the following cURL command to get label sets added to a project. You can copy and paste the following template and replace the access_token and the content of the label set items according to your needs.

curl --location --request POST 'https://datasaur.ai/graphql' \
  --header 'Authorization: Bearer access_token' \
  --header 'Content-Type: application/json' \
  --data-raw '{"operationName":"UpdateLabels","variables":{"input":{"documentId":"document-id","signature":"signature","labels":[{"id":"vGOy0ZKA-2rqK7netKz9I:0:0:0:0:0:2:5:0","l":"vGOy0ZKA-2rqK7netKz9I","start":{"sentenceId":0,"tokenId":0,"charId":0},"end":{"sentenceId":0,"tokenId":2,"charId":5},"layer":0,"deleted":false},{"id":"9I-5oYKvnzJRWHgsZrDe_:0:0:14:0:0:18:6:0","l":"9I-5oYKvnzJRWHgsZrDe_","start":{"sentenceId":0,"tokenId":14,"charId":0},"end":{"sentenceId":0,"tokenId":18,"charId":6},"layer":0,"deleted":false},{"id":"A-92mMT_WppaawOOBJbjt:1:9I-5oYKvnzJRWHgsZrDe_:0:0:14:0:0:18:6:0:vGOy0ZKA-2rqK7netKz9I:0:0:0:0:0:2:5:0:0","l":"A-92mMT_WppaawOOBJbjt","start":{"sentenceId":0,"tokenId":0,"charId":0},"end":{"sentenceId":0,"tokenId":18,"charId":6},"layer":1,"deleted":false}],"action":"LABEL"}}, "query":"mutation UpdateLabels($input: UpdateTokenLabelsInput!) { updateLabelsResult: updateLabels(input: $input) { updatedSentences { id } } }"}'

Below is a more readable version of the above curl command's request body.

{
    "operationName": "UpdateLabels",
    "variables": {
        "input": {
            "documentId": "document-id",
            "signature": "signature",
            "labels": [
                {
                    "layer": 0,
                    "start": {
                        "sentenceId": 0,
                        "tokenId": 0,
                        "charId": 0
                    },
                    "end": {
                        "sentenceId": 0,
                        "tokenId": 2,
                        "charId": 5
                    },
                    "l": "vGOy0ZKA-2rqK7netKz9I",
                    "id": "vGOy0ZKA-2rqK7netKz9I:0:0:0:0:0:2:5:0",
                    "deleted": false
                },
                {
                    "layer": 0,
                    "start": {
                        "sentenceId": 0,
                        "tokenId": 14,
                        "charId": 0
                    },
                    "end": {
                        "sentenceId": 0,
                        "tokenId": 18,
                        "charId": 6
                    },
                    "l": "9I-5oYKvnzJRWHgsZrDe_",
                    "id": "9I-5oYKvnzJRWHgsZrDe_:0:0:14:0:0:18:6:0",
                    "deleted": false
                },
                {
                    "layer": 1,
                    "start": {
                        "sentenceId": 0,
                        "tokenId": 0,
                        "charId": 0
                    },
                    "end": {
                        "sentenceId": 0,
                        "tokenId": 18,
                        "charId": 6
                    },
                    "l": "A-92mMT_WppaawOOBJbjt",
                    "id": "A-92mMT_WppaawOOBJbjt:1:9I-5oYKvnzJRWHgsZrDe_:0:0:14:0:0:18:6:0:vGOy0ZKA-2rqK7netKz9I:0:0:0:0:0:2:5:0:0",
                    "deleted": false
                }
            ],
            "action": "LABEL"
        }
    },
    "query": "mutation UpdateLabels($input: UpdateTokenLabelsInput!) { updateLabelsResult: updateLabels(input: $input) { updatedSentences { id } } }"
}

The request above will produce span and arrow labels like the following:

  • operationName: you can fill any alphanumeric string in as the operationName. Refer this page for best practices on choosing an operationName .

  • variables:

    • input:

      • documentId: string, ID of the targeted document where the label will be inserted.

      • signature: hash of the document to ensure the structure of the sentence / spans of the document has not changed when inserting label. You can obtain the signature value by following the instruction in this page.

      • labels:

        • id: the unique identifier of a label.

          1. If the ID has 9 segments, this indicates a span label. For example, INNM0ViFwo8LluMTaTIK9:0:0:14:0:0:18:6:0 and here's the explanation <label set item id>:<layer>:<sidS>:<s>:<charS>:<sidE>:<e>:<charE>:<index>.

          2. If the ID has 21 segments, this indicates an arrow label. For example, tfc1FkbbEk9fOLx6haR1s:0:INNM0ViFwo8LluMTaTIK9:0:0:14:0:0:18:6:0:Oq_VuB0s_N7D8ZY0rgYsg:0:0:0:0:0:2:5:0:0 and here's the explanation <label set item id>:<arrow layer>:<….. origin id>:<….destination id>:<arrow index>.

        • layer: indicates the index of the label set.

        • l: the label set item ID of the label set. You can obtain the label set information of a project including the label set item ID in this page.

        • start:

          • sentenceId: starting line of the label

          • tokenId: starting token of the label

          • charId: starting character index of the label

        • end:

          • sentenceId: ending line of the label

          • tokenId: ending token of the label

          • charId: ending character index of the label

        • deleted: boolean, set true if you want to delete the existing label

  • query: Copy this from the example above.

💡a tag has the same meaning as label. In the near future, we will update the GraphQL Schema to refer to all instances as labels.

Response

Here is the response you can expect after issuing the cURL command. Use the id to create the project.

{
    "data": {
        "updateLabelsResult": {
            "updatedSentences": [
                {
                    "id": 0
                }
            ]
        }
    },
    "extensions": {}
}

Last updated