Functions available:
Code Block |
---|
|
this.allowSubmitallowSubmission(Boolean)
this.changeFormValue(field_name, new_value)
this.enableField(field_name, Boolean)
this.disableField(field_name)
this.mandatoryField(field_name, Boolean)
this.changeInputValue(field_name, value)
let value = JSON.stringify(finalValues)
this.updateAnnotations(value)
let errorMsgs = []if(errorMsgs.length > 0) {
this.displayErrors(errorMsgs)
this.disAllowSubmit(true)
} else {
this.disAllowSubmit(false)
}
this.changeAnnotationClasses(newClass);
let inputText = inputValues[field_name]
let currentUserId = localStorage.getItem("userId")
if(currentUserLevel === 1) {
this.changeFormValue(field_name, `${currentUserId}`)
}
For NER:
let entities = _.get(annotations, "[0].value.annotations.entities", _.get(annotations, "annotations.entities", []))
To access form values in On-Change/on-hideOutputField(["field_name1", "field_name2"],"template_name")
this.unHideOutputField(["field_name1", "field_name2"],"template_name")
this.hideInputField(["field_name1", "field_name2"],"template_name")
this.unHideInputField(["field_name1", "field_name2"],"template_name")
this.hideUserBulkTaskButtons(["button 1 name", "button 2 name", …n])
this.unHideUserBulkTaskButtons(["button 1 name", "button 2 name", …n])
let value = JSON.stringify(finalValues)
this.updateAnnotations(value)
let errorMsgs = []if(errorMsgs.length > 0) {
this.displayErrors(errorMsgs)
this.disAllowSubmit(true)
} else {
this.disAllowSubmit(false)
}
this.changeAnnotationClasses(newClass);
let inputText = inputValues[field_name]
let currentUserId = localStorage.getItem("userId")
if(currentUserLevel === 1) {
this.changeFormValue(field_name, `${currentUserId}`)
}
For NER:
let entities = _.get(annotations, "[0].value.annotations.entities", _.get(annotations, "annotations.entities", []))
To access form values in On-Change/on-Validation/On-save(also console the values coming from values and formValues then use as required):
let fieldNameValue = formValuesvalues["field_name"] |
Examples
Audio transcription validation: No special characters allowed, tags validations, etc.
Code Block |
---|
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.":
To access previous values in the on change code: (Useful to check if a particular field's value has changed')
let preValues = oldValues["field_name"]
To access annotations data in any annotation project
let anns = annotations
|
Examples:
Audio transcription validation: No special characters allowed, tags validations, etc.
Code Block |
---|
let regexNotToMatch = {
"Add at least one space before the normal start tag.": /[^ ]<[^>]*^\/>[^ ]|*[^ ]<[^>]*\/>|<[^>]*\/>[^ ]/g,
"Numbers are not allowedAdd at least one space after the normal end tag.": /<\/[0-9\s*[^>]*>[^ ]/g,
"Special character: ^ ( ) { } [ ] ; : $ % * =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 }); |
...
Code Block |
---|
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)
} |
16. Excel View validations and manipulations:
...
...
Extract ASIN,customID and keywords from Amazon URL’s
Code Block |
---|
|
let getUrl = values["Competitor Exact URL"]
function ExtractASIN(url){
var ASINreg = new RegExp(/(?:\/)([A-Z0-9]{10})(?:$|\/|\?)/)
var cMatch = url.match(ASINreg)
if(cMatch == null){
return null
}
return cMatch[1]
}
function ExtractCID(urls){
var CustomCID = new RegExp(/customId=([A-Za-z0-9]+)/)
var cMatch1 = (urls).match(CustomCID)
if(cMatch1 == null){
return null
}
return cMatch1[1]
}
function ExtractKeywords(url) {
const regex = /keywords=([^&]+)/;
const match = url.match(regex);
const keywords = match ? decodeURIComponent(match[1].replace(/\+/g, ' ')) : null;
return keywords.replace(/\+/g, ' ');;
}
this.changeFormValue("Comp_ASIN", ExtractASIN(getUrl))
if (ExtractCID(getUrl)== null){
this.changeFormValue("CustomID", "Not available")
}
else{
this.changeFormValue("CustomID", ExtractCID(getUrl))
}
if (ExtractKeywords(getUrl)== null){
this.changeFormValue("Source_Of_Search", "Not available")
}
else {
this.changeFormValue("Source_Of_Search", ExtractKeywords(getUrl))
} |
17. Generate rows in a name-value pair field
Code Block |
---|
|
let lineItems = []
let i = 0
/* To generate two empty rows */
while(i < 2) {
lineItems.push({
"weight": "",
"unit": ""
})
i += 1
}
/* Variant is the field name */
if(Array.isArray(lineItems)){
this.changeFormValue("Variant", JSON.stringify(lineItems))
} |
Calculation of IOU at level 3 for rejection logic
Code Block |
---|
|
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")
}
} |