Create Label Set

When creating a Token-Based Labeling Project, we often want to create a label set as well. This example shows you how to create a simple label set consisting of 3 labels, along with their corresponding colors.

cURL

Use the following cURL command to create 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 '{"query":"mutation CreateLabelSetMutation($input: CreateLabelSetInput!) {    createLabelSet(input: $input) {      id   }}","variables":{"input":{"name": "Give your new label set a name","tagItems":[{"id":"qgvxaa-svCwj18KIcoCBu","parentId":null,"desc":null,"color":"red","tagName":"PER"},{"id":"qgvxbb-svCwj18KIcoCBu","parentId":null,"desc":null,"color":"green","tagName":"GEO"},{"id":"qgvxMd-svCwj18KIcoCBu","parentId":null,"desc":null,"color":null,"tagName":"GPE"}]}}}'

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

{
    "operationName": "CreateLabelSetMutation",
    "variables": {
        "input": {
            "name": "Give your new label set a name",
            "tagItems": [
                {
                    "id": "qgvxaa-svCwj18KIcoCBu",
                    "parentId": null,
                    "desc": null,
                    "color": "red",
                    "tagName": "PER"
                },
                {
                    "id": "qgvxbb-svCwj18KIcoCBu",
                    "parentId": null,
                    "desc": null,
                    "color": "green",
                    "tagName": "GEO"
                },
                {
                    "id": "qgvxMd-svCwj18KIcoCBu",
                    "parentId": null,
                    "desc": null,
                    "color": null,
                    "tagName": "GPE"
                }
            ]
        }
    },
    "query": "mutation CreateLabelSetMutation($input: CreateLabelSetInput!) {\n  createLabelSet(input: $input) {\n    ...LabelSetFragment\n    __typename\n  }\n}\n\nfragment LabelSetFragment on LabelSet {\n  id\n  name\n  tagItems {\n    ...TagItemFragment\n    __typename\n  }\n  lastUsedBy {\n    name\n    __typename\n  }\n  __typename\n}\n\nfragment TagItemFragment on TagItem {\n  id\n  parentId\n  color\n  desc\n  tagName\n  __typename\n}\n"
}
  • operationName: you can fill any alphanumeric string in as the operationName. Refer this page for best practices on choosing an operationName .

  • variables:

    • input:

      • name: optional, You may give this label set a name so you could refer it in the future from Label Set Library.

      • tagItems:

        • Each tag item includes 3 required fields

          • id: Fill with a random id. You can use any string as long as it is unique.

          • parentId: This is used for hierarchical labels. Use any existing ids that you have defined. If there is no parentId, use null.

          • tagName: Fill with the actual labels you'd like to use and the user will see e.g. person, geopolitical entity

        • A tag item also has 2 optional fields

          • desc: label description

          • color: You can set the color of the label. Refer to this page.

  • query: Copy this from the cURL example.

💡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": {
        "createLabelSet": {
            "id": "366"
        }
    },
    "extensions": {}
}

Last updated