Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

  • this.allowSubmission(Boolean) :

A function that enables the submission of tasks based on boolean values “true” and” false".

Ex:

if (values["Field_check"] == "No") {
    let mandatoryFields = ["Field1", "Field2"]
    for (let field of mandatoryFields) {
        if (!values[field] || values[field] === "") {
            alert("Please fill field " + field)
            this.allowSubmission(false)
            break
        }
    }
}

  • this.disAllowSubmit(Boolean)

A function that disables the submission of tasks based on boolean values “true” and” false".

Ex:

if (values["Field_check"] == "No") {
    let mandatoryFields = ["Field1", "Field2"]
    for (let field of mandatoryFields) {
        if (!values[field] || values[field] === "") {
            alert("Please fill field " + field)
            this.disAllowSubmit(true)
            break
        }
    }
}

  • this.changeFormValue(field_name, new_value)

A function to assign a value to an output field, which can either be a new value or the value from another field.

Ex:

this.changeFormValue("field_name", inputValues["field_name_new"])(Assign value of an input field to any output field)
or
this.changeFormValue("field_name", values["field_name_new"])(assign a value from an output field to an output field)
or
this.changeFormValue("field_name", “Any value“)(Assign any string value to an output field)

  • this.changeInputValue(field_name, value)

A function to assign a value to an input field, which can either be a new value or the value from another field.

Ex:

if (currentUserLevel == 1) {
    this.changeInputValue(“field_name”, “value”)
    or
    this.changeInputValue(“field_name”, inputValues[“input field name”])
}

  • this.enableField(field_name, Boolean)

A function that enables a field which was previously disabled

Ex :

if (values["field_check"] == "Yes") {
    this.enableField(“field_name”, true)
}

  • this.disableField(field_name)

A function that disables a field that was previously enabled

Ex :

if (values["field_check"] == "No") {
    this.disableField(“field_name”)
}

  • this.mandatoryField(field_name, Boolean)

A function that sets a field as mandatory or non-mandatory based on the boolean value, used to conditionally change the field's mandatory state. Ensure the field is not marked mandatory in the Task Design section of the project configuration. Use 'true' or 'false' to toggle the state.

Ex:

if (values["field_check"] == "") {
    this.mandatoryField(“field_name”, true)
} else {
    this.mandatoryField(“field_name”, false)
}

  • this.hideInputField(["field_name1", "field_name2"],"template_name")

A function used to conditionally hide input fields.

Ex:

if (currentUserLevel == 1) {
    this.hideInputField(["field_name1", "field_name2"], "template_name")
}

  • this.unHideInputField(["field_name1", "field_name2"],"template_name")

A function used to conditionally unhide input fields that were previously hidden

Ex:

if (values["field_check"] == “Yes”]) {
    this.unHideInputField(["field_name1", "field_name2"], "template_name")
} else {
    this.hideInputField(["field_name1", "field_name2"], "template_name")
}

  • this.hideOutputField(["field_name1", "field_name2"],"template_name")

A function used to conditionally hide output fields.

Ex:

if (currentUserLevel == 1) {
this.hideOutputField(["field_name1", "field_name2"],"template_name")
}

  • this.unHideOutputField(["field_name1", "field_name2"],"template_name")

A function used to conditionally unhide output fields that were previously hidden

Ex:

if (values["field_check"] == “Yes”]) {
    this.unHideOutputField(["field_name1", "field_name2"], "template_name")
} else {
    this.hideOutputField(["field_name1", "field_name2"], "template_name")
}

  • this.hideTemplateSection(["Template1", "Template2"])

A function used to conditionally display or hide templates. This can be highly effective when managing projects with numerous input and output fields. By grouping these fields based on a common theme, separate templates can be utilized to show relevant information only when needed, while hiding the rest. This approach helps reduce unnecessary scrolling and prevents accidental entries in fields that aren't currently required.

if (currentUserLevel == 1) {
this.hideTemplateSection(["Template1","Template2","Template3"])
}

  • this.unhideTemplateSection(["Template1"])

A function used to unhide/display a hidden template.

if (checkInput == "Section1") {
    this.unhideTemplateSection(["Template1"])
    this.hideTemplateSection(["Template2", "Template3", "Template3"])
}

  • this.hideUserBulkTaskButtons(["button 1 name", "button 2 name", …n])

A function used to conditionally hide task buttons in excel view/bulk task labelling UI.

if (currentUserLevel == 1) {
this.hideUserBulkTaskButtons(["SUBMIT", "SAVE & EXIT",” SKIP TASKS”],” SUBMIT & EXIT”])
}

  • this.unHideUserBulkTaskButtons(["button 1 name", "button 2 name", …n])

A function used to conditionally unhide task buttons that were previously hidden in excel view/bulk task labelling UI.

Ex:

if (values["field_check"] == “Yes”]) {
    this.unHideUserBulkTaskButtons(["SUBMIT", "SAVE & EXIT", ”SKIP TASKS”], ”SUBMIT & EXIT”])
} else {
    this.hideUserBulkTaskButtons(["SUBMIT", "SAVE & EXIT", ”SKIP TASKS”], ”SUBMIT & EXIT”])
}

  • this.changeAnnotationClasses(newClass).

A function to load classes for annotation projects using custom code.

Ex:

let newClass = {
    Books: JSON.stringify({
        "color": "#FFEBE8",
        "hotkey": "",
        "attributes": [{
            "name": "Price",
            "fieldType": "Text",
            "mandatoryField": false,
            "possible_value": [""],
            "default_value": ""
        }]
    }),
    Tree: JSON.stringify({
        "color": "#CCC",
        "hotkey": "t",
        "attributes": [{
            "name": "attr1",
            "fieldType": "MultiDropDown",
            "mandatoryField": false,
            "possible_value": ["attr1_v1", "attr1_v2"],
            "default_value": ""
        }, {
            "name": "attr2",
            "fieldType": "Text",
            "mandatoryField": false,
            "possible_value": [""],
            "default_value": ""
        }]
    })
};
this.changeAnnotationClasses(newClass)

  • this.updateAnnotations(x)

A function that generates new annotations on load, updates existing annotations, or loads pre-annotations from an input field which is in JSON format.

Ex1: Generate 100 segments of transcription on load of a task

let finalValues = []
let i = 0
while (i < 100) {
    i = i + 1
    finalValues.push({
        "id": i,
        "curTime": 0,
        "endTime": i + 1,
        "startTime": i,
        "UIstartTime": i + 1,
        "UIendTime": i,
        "split": 0,
        "audiourl": "",
        "pos": 0,
        "transliterationData": "abc def ghi jxy lzg".split(" ").map(w => ({
            "word": w,
            "tags": [],
            "languageTag": "",
            "editedText": ""
        }))
    })
}
let x = JSON.stringify(finalValues)
this.updateAnnotations(x)
Ex2: Load pre - annotations from an input field(When imported from cloud json files)
let preAnno = inputValues["Preannotations"]
if (!isNaN(currentUserLevel) && currentUserLevel == 1 && Array.isArray(annotations) && annotations.length > 0) {
    let annoData = []
    let preAnnoArr = _.get(preAnno, "document.page[0].block", [])
    let tmAnnoFormat = preAnnoArr.map((val, i) => {
        return ({
            "id": i,
            "label": ["car"],
            "shape": "rectangle",
            "points": [firstPoint, secondPoint, thirdPoint, fourthPoint],
            "notes": "",
            "annotationGroups": "",
            "attributes": {},
            "imageWidth": undefined,
            "imageHeight": undefined
        })
    })
    let x = JSON.stringify(tmAnnoFormat)
    this.updateAnnotations(x)
}

Ex3 : Load pre-annotations from an input field (when imported locally)

let inputJsonData = JSON.parse(inputValues["jsontext"])
let x = JSON.stringify(inputJsonData);
if (currentUserLevel === 1 && annotations.length == 0) {
    this.updateAnnotations(x);
}

  • this.addNerPreRelRules(preRelRules)

A function to define rules in NER, specifying the starting and ending entities of a relation. Multiple relations can exist between two entities and can be defined as a comma separated list

Ex:

let preRelRules = {
    entityLvlRelRules: [{
        eStart: "from_entity1",
        eEnd: "to_entity1",
        rName: "relation_name1,”relation_name2"
    }, {
        eStart: "from_entity2",
        eEnd: "to_entity2",
        rName: "relation_name3"
    }, {
        eStart: "from_entity3",
        eEnd: "to_entity3",
        rName: "relation_name3"
    }],
    restrictOtherRel: true
}
this.addNerPreRelRules(preRelRules)

  • this.displayErrors(alertMessage)

A function used to display an error message when a specific condition is met.

Ex:

let alertMessage = []
annotations.forEach(anno => {
    if (!_.get(anno, "annotationGroups") && !_.get(anno, "label", []).includes("other_value_text")) {
        this.allowSubmit = false
        alertMessage.push(`One of the objects of class ${_.get(anno, "label", [])[0]} of shape ${_.get(anno, "shape", "")} has not been added to a group.`)
    }
})
if (alertMessage.length) {
    this.displayErrors(alertMessage)
} else {
    this.allowSubmit = true
}

  • this.changeRowDataCC(rowData)

A function to write or update values in the sub-fields (line items) of Annotations for digitization projects.

Ex:

let lineItems = inputJSON["LineItems"];
if (lineItems && lineItems.length) {
    let rowData = lineItems.map(itemRow => {
        return {
            "id": _.uniqueId(`${itemRow.Id ? itemRow.Id : ""}-`),
            "Id": {
                "value": itemRow.Id !== undefined ? itemRow.Id : "",
                "ocrIndex": [],
                "imageIndex": undefined
            },
            "subRows": [],
            "Product": {
                "value": itemRow.ProductKey !== undefined ? itemRow.Product : "",
                "ocrIndex": [],
                "imageIndex": undefined
            },
            "Order": {
                "value": itemRow.Order !== undefined ? itemRow.Order : "",
                "ocrIndex": [],
                "imageIndex": undefined
            },
            "Description": {
                "value": itemRow.Description !== undefined ? itemRow.Description : "",
                "ocrIndex": [],
                "imageIndex": undefined
            }
        };
    });
    await this.changeRowDataCC(rowData);
}
};

  • this.addToDropDown("fieldName",["value1",”value2”,...])

A function to add new values to an existing drop-down based on a condition.

Ex:

if (values["Things"] == "Fruits") {
    this.addToDropDown("Fruit List", ["Mango", "Pineapple"])
}

  • this.removeFromDropDown("fieldName",["value1",”value2”..])

A function to remove values to an existing drop-down based on a condition.

Ex:

if (values["Things"] == "Cities") {
    this.removeFromDropDown("City List", ["Paris", "Austin"])
}

  • this.removeAllFromDropdown("fieldName",[])

A function to remove all values from an existing drop-down

Ex:

if (values["Things"] !== "Cities") {
this.removeAllFromDropdown("City List",[])
}

  • this.updateLinkedChild("fieldname", "parentValue", ["childValue1","childValue2"....], ","add" / "delete"")

A function used to add or remove the possible value of linked Field Child based on selection of the parent possible values.

Ex:

if (values["ParentColour"] !== "Red") {
    this.updateLinkedChild("ChildColour", "Red", ["18"], "add")
} else {
    this.updateLinkedChild("ChildColour", "Green", ["18"], "delete")
}

  • values["field name"]

Used to retrieve values from any output field. This can be used to compare values between two output fields, assign the value of one field to another, or check a field's value and perform operations on other fields based on that value.

Ex:

if (values["Things"] == "Fruits") {
    this.enableField("Fruits", true)
    this.mandatoryField("Fruits", true)
} else {
    this.disableField("Fruits")
    this.changeFormValue("Fruits", "")
    this.mandatoryField("Fruits", false)
}

  • oldValues["field_name"]

Used to access previous values of an output field in the on-change code, making it useful for determining whether a specific field's value has changed. This helps prevent unnecessary execution of a code block when the field value hasn't actually changed.

Ex:

if (values["Things"] == "Animal" && values["Things"] !== oldValues["Things"]) {
    this.unHideOutputField("Animal", "Template1")
    this.mandatoryField("Animal", true)
} else {
    this.hideOutputField("Animal", "Template1")
    this.changeFormValue("Animal", "")
    this.mandatoryField("Animal", false)
}

  • inputValues[field_name]

It is used to access the values of input fields, enabling checks on specific field values and triggering operations on dependent fields. The value can also serve as a reference for other calculations or processes.

Ex:

let inputText = inputValues["Reference_text"]
const regex = /(agent:|customer:)/g;
const formattedText = inputText.replace(regex, '\n$1');
if (currentUserLevel == 1 && values["TextToEdit"] !== undefined) {
    this.changeFormValue("TextToEdit", formattedText)
}

Examples

  • To get current user id in a task

let currentUserId = localStorage.getItem("userId")
if (currentUserLevel === 1) {
this.changeFormValue(field_name, `${currentUserId}`)
}

  • A code for audio transcription validation that ensures no special characters are allowed, while also validating tags and other criteria. This helps maintain transcription accuracy and consistency by enforcing proper formatting rules.

let regexNotToMatch = {
    "Add at least one space before the normal start tag.": /[^ ]<[^\/]*[^\/]*>/g,
    "Add at least one space after the normal end tag.": /<\/\s*[^>]*>[^ ]/g,
    "Add at least one space before and after a single tag.": /[^ ]<[^>]*\/>[^ ]|[^ ]<[^>]*\/>|<[^>]*\/>[^ ]/g,
    "Numbers are not allowed.": /[0-9]/g,
    "Special character: ^ ( ) { } [ ] ; : $ % * = are not allowed.": /[\^(){}\[\];:$%*=]/g,
    "New line/Enter is not allowed.": /\n/g,
};
this.setState({
    audioRegexNotToMatch: regexNotToMatch
});

  • A code to load pre-annotations and class labels from YOLO data.

let yoloData = inputValues["yolo-data"]
// split yolo annotation data to array of individual anno data
let re = /\b[\w.]+(?:[^\w\n]+[\w.]+){0,4}\b/g
let arrYoloAnno = yoloData.match(re);
let newClass = {
    "0": "Person",
    "1": "Class1",
    "2": "Class2",
    "99": "Face"
}
/**/
/* Start: convert yolo data to TM anno format and setting it as pre anno */
/*

The format of the YOLO label file is

Label_ID_1 X_CENTER_NORM Y_CENTER_NORM WIDTH_NORM HEIGHT_NORM

*/
let preAnno = arrYoloAnno.map((singleYoloAnno, ind) => {
    let singleAnnoSplitData = singleYoloAnno.split(" ")
    let X_CENTER = parseFloat(singleAnnoSplitData[1])
    let Y_CENTER = parseFloat(singleAnnoSplitData[2])
    let WIDTH_NORM = parseFloat(singleAnnoSplitData[3]) / 2
    let HEIGHT_NORM = parseFloat(singleAnnoSplitData[4]) / 2
    let firstPoint = [X_CENTER - WIDTH_NORM, Y_CENTER - HEIGHT_NORM]
    let secondPoint = [X_CENTER + WIDTH_NORM, Y_CENTER - HEIGHT_NORM]
    let thirdPoint = [X_CENTER + WIDTH_NORM, Y_CENTER + HEIGHT_NORM]
    let fourthPoint = [X_CENTER - WIDTH_NORM, Y_CENTER + HEIGHT_NORM]
    return ({
        "id": ind,
        "label": [newClass[singleAnnoSplitData[0]]],
        "shape": "rectangle",
        "points": [firstPoint, secondPoint, thirdPoint, fourthPoint],
        "notes": "",
        "annotationGroups": "",
        "attributes": {},
        "imageWidth": undefined,
        "imageHeight": undefined
    })
})
/* End */
let x = JSON.stringify(preAnno)
this.updateAnnotations(x)

  • A code to track QC rejections using custom field.

let currentUserId = localStorage.getItem("userId")
if (currentUserLevel === 1) {
    this.changeFormValue("annotator_id", `${currentUserId}`)
}
if (currentUserLevel === 2) {
    this.changeFormValue("QA_id", `${currentUserId}`)
    if (rejectTaskDetails.commentHistory.length > 0) {
        console.log("QA_Flag set to true on load")
        this.changeFormValue("QA_Flag", true)
    }
}

  • A code to format the NER output to plain text and write to an output field.

/* O/P format: "gemini(brand),100 grams(quantity) */
let entities = _.get(annotations, "[0].value.annotations.entities", _.get(annotations, "annotations.entities", []))
if (entities.length > 0) {
    entities.sort((a, b) => a.start_offset - b.start_offset)
    var requiredOp = entities.reduce((accumulator, currentValue) => accumulator + `${currentValue.text}(${currentValue.entity_type}),`, "")
    if (requiredOp[requiredOp.length - 1] == ",") {
        requiredOp = requiredOp.slice(0, requiredOp.length - 1)
    }
    this.changeFormValue("tagged_output", requiredOp)

  • Code to convert SRT to Taskmonk JSON and load pre-annotation for audio transcription.

function time2sec(dateTime) {
    let ms = dateTime.split(',')[1]
    let hh = dateTime.split(':')[0]
    let mm = dateTime.split(':')[1]
    let ss = dateTime.split(':')[2].split(',')[0]
    let ts = (parseInt(hh) * 3600) + (parseInt(mm) * 60) + parseInt(ss) + (parseInt(ms) / 1000)
    return ts
}
let finalValues = []
let inputArray = inputValues["TEXT"].split(/\n\s*\n/)
let i = 0
while (i < inputArray.length) {
    i = i + 1
    if (inputArray[i]) {
        let startTime = time2sec(inputArray[i].split('\n')[1].split('-->')[0])
        let endTime = time2sec(inputArray[i].split('\n')[1].split('-->')[1])
        finalValues.push({
            "id": i,
            "curTime": 0,
            "endTime": endTime,
            "startTime": startTime,
            "UIstartTime": startTime,
            "UIendTime": endTime,
            "split": 0,
            "audiourl": "",
            "pos": 0,
            "transliterationData": inputArray[i].split('\n')[2].split(" ").map(w => ({
                "word": w,
                "tags": [],
                "languageTag": "",
                "editedText": ""
            }))
        })
    }
}
let x = JSON.stringify(finalValues)
this.updateAnnotations(x)

  • On load custom code to convert gdrive sharing urls to viewing url.

function getIdFromUrl(url) {
    return url.match(/[-\w]{25,}/);
}
let inputUrl = getIdFromUrl(inputValues["image"])[0]
this.changeInputValue("image", "https://drive.google.com/uc?export=view&id=" + inputUrl)

  • Code to update all visible tasks based on changes in one task in Excel view.

function getDupProdIds(tId, selectedInputValues, that) {
    let dupProdIds = []
    let selectedItemId = selectedInputValues["CATLG_ITEM_ID"]
    for (let i = 0; i < allTasks.length; i++) {
        let currentTaskInput = that.getInputValueByID(allTasks[i].taskValues.taskId)
        let currentTaskItemId = currentTaskInput["CATLG_ITEM_ID"]
        if (currentTaskItemId == selectedItemId) dupProdIds.push(currentTaskInput["productID"])
    }
    return dupProdIds
}
let that = this
let tIdsInputValues = this.getInputValueByID(tID)
let val = values["Select Action"];
if (val == "Duplicate") {
    let dpValuIds = getDupProdIds(tID, tIdsInputValues, that)
    //dpValuIds()
    console.log("dup", dpValuIds)
    this.changeFormValue("dup_productID", dpValuIds.join(), tID)
} else {
    this.changeFormValue("dup_productID", tIdsInputValues["productID"], tID)
}

  • Code to enable/disable fields in Excel View/Bulk tasks.

let intentValue = values["Field_name"]
if (intentValue == "Field_name") {
    this.enableField("Field_name", tID)
    this.enableField("Field_name", tID)
    this.mandatoryField("Field_name", true, tID)
    this.mandatoryField("Field_name", true, tID)
} else if (intentValue == "Field_value" || intentValue == "Field_value" || intentValue == "Field_value" || intentValue == "Field_value" || intentValue == "Field_value") {
    this.disableField("Field_name", tID)
    this.disableField("Field_name", tID)
    this.changeFormValue("Field_name", " ", tID)
    this.changeFormValue("Field_name", " ", tID)
}
Code to write values into Name Value pair fields on load
let lineItems = inputArray["LineItems"];
let newLineItems = [];
let i = 1;
if (currentUserLevel == 1 && values["LineItems"] === undefined) {
    if (Array.isArray(lineItems) && lineItems.length > 0) {
        for (let item of lineItems) {
            let newItem = {};
            for (let key in item) {
                newItem[key] = ensureString(item[key]);
            }
            newItem["id"] = String(i);
            newLineItems.push(newItem);
            i += 1;
        }
        this.changeFormValue("LineItems", JSON.stringify(newLineItems));
    } else {
        this.changeFormValue("LineItems", "");
    }
}

  • Code to write values into a Dynamic field on load

if (currentUserLevel == 1) {
    let jsonFormat = inputValues["json_format"].replace(": nan", ": \"nan\"")
    let parsedData = JSON.parse(jsonFormat);
    let outVal = [];
    for (let i = 0; i < parsedData.length; i++) {
        console.log(parsedData[i], "parsedData[i]")
        outVal.push({
            imgURL: parsedData[i].img_url,
            widget: "productComparison",
            id: parsedData[i].id,
            metaData: {},
            ...parsedData[i],
        })
    }
    this.initializeDYNFormValue("output1", outVal);
}

  • Code to map OCR-generated data to the attributes of a class, where the "notes" value is mapped to the "Value" attribute of the class.

if (currentUserLevel === 1 && annotations.length == 0) {
    let preAnno = annotations.map((ele, i) => ({
        ...ele,
        id: i,
        label: ["TextGroup"],
        annotationGroups: "",
        attributes: {
            "Value": ele.notes
        }
    }));
    preAnno.shift();
    this.updateAnnotations(preAnno);
}

  • Code to calculate IOU at level 3 for rejection logic

if (currentUserLevel == 3) {
    let totalIOU = 0
    let totalAnnotations = annotations.length
    for (let step = 0; step < totalAnnotations; step++) {
        // Current level annotation points for a box
        let ann1 = annotations[step]["points"]
        // Get previous level annotation points for the same box
        let ann2 = JSON.parse(initialValues["Annotations"])[step]["points"]
        let x1 = ann1[0][0]
        let x2 = ann1[2][0]
        let x3 = ann2[0][0]
        let x4 = ann2[2][0]
        let y1 = ann1[0][1]
        let y2 = ann1[2][1]
        let y3 = ann2[0][1]
        let y4 = ann2[2][1]
        let x_inter1 = Math.max(x1, x3)
        let x_inter2 = Math.min(x2, x4)
        let y_inter1 = Math.max(y1, y3)
        let y_inter2 = Math.min(y2, y4)
        console.log(x_inter1, y_inter2)
        let width = x_inter2 - x_inter1
        let height = y_inter2 - y_inter1
        let area_inter = width * height
        let width_box1 = x2 - x1
        let width_box2 = x4 - x3
        let height_box1 = y2 - y1
        let height_box2 = y4 - y3
        let area_box1 = width_box1 * height_box1
        let area_box2 = width_box2 * height_box2
        let area_union = area_box1 + area_box2 - area_inter
        let iou = area_inter / area_union
        totalIOU = totalIOU + iou
    }
    //Average IOU between level 3 and previous level annotations
    let avgIOU = totalIOU / totalAnnotations
    if (avgIOU < 0.90) {
        alert("IOU dropped below 0.9")
    }
}

  • Code to add groups for image and video annotation projects

let groupList = ["a", "b", "c", "d"]
localStorage.setItem("groups", JSON.stringify(groupList))
  • No labels