...
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-Validation/On-save(also console the values coming from values and formValues then use as required):
let fieldNameValue = formValues["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.": /[^ ]<[^>]*\/>[^ ]|[^ ]<[^>]*\/>|<[^>]*\/>[^ ]/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 }); |
2. Generate 100 segments of transcription on load of a task:
...
...
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 = values["field_name"]
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,
"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 }); |
2. Generate 100 segments of transcription on load of a task:
Code Block |
---|
|
let finalValues =[]
let i=0
while(i < 100 ) {
i = i + 1
finalValues.push( {
"id": i,
"curTime": 0,
"transliterationDataendTime": "abci def ghi jxy lzg".split(" ").map(w => ({
+ 1,
"startTime": i ,
"UIstartTime": i + 1,
"wordUIendTime": wi,
"split": 0,
"tagsaudiourl": []"",
"pos": 0,
"languageTagtransliterationData": "",abc def ghi jxy lzg".split(" ").map(w => ({
"editedText": "" }"word": w,
"tags": [],
"languageTag": "",
"editedText": ""
}))
})
}
let x = JSON.stringify(finalValues)
this.updateAnnotations(x) |
...
Code Block |
---|
|
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"){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)
} |
14. Enable/Disable Buttons:
The following custom code can be plugged in to disable/enable a few actions buttons conditionally.
i. To hide user action buttons
Code Block |
---|
this.hideUserTaskButtons(["button 1 name", "button 2 name", …n]) |
ii. To unhide user action buttons
Code Block |
---|
this.unhideUserTaskButtons(["button 1 name", "button 2 name", …n]) |
Available options for button names:
Code Block |
---|
|
"SUBMIT & GET NEXT TASK"
"SAVE & EXIT"
"SKIP & GET NEXT TASK"
"SUBMIT TASK & EXIT" |
15. Enable/Disable fields in Excel View/Bulk tasks.
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. 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 dpValuIdsx_inter1 = getDupProdIdsMath.max(tIDx1, tIdsInputValues, thatx3)
let x_inter2 = //dpValuIds(Math.min(x2, x4)
console.log("dup", dpValuIds let y_inter1 = Math.max(y1, y3)
let y_inter2 = thisMath.changeFormValue("dup_productID", dpValuIds.join(), tID)
} else {min(y2, y4)
thisconsole.changeFormValuelog("dupx_productID", tIdsInputValues["productID"], tID)
} |
14. Enable/Disable Buttons:
The following custom code can be plugged in to disable/enable a few actions buttons conditionally.
...
Code Block |
---|
this.hideUserTaskButtons(["button 1 name", "button 2 name", …n]) |
ii. To unhide user action buttons
Code Block |
---|
this.unhideUserTaskButtons(["button 1 name", "button 2 name", …n]) |
Available options for button names:
Code Block |
---|
|
"SUBMIT & GET NEXT TASK"
"SAVE & EXIT"
"SKIP & GET NEXT TASK"
"SUBMIT TASK & EXIT" |
15. Enable/Disable fields in Excel View/Bulk tasks.
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:
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)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")
}
} |