...
Code Block | ||
---|---|---|
| ||
this.allowSubmission(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 = 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:
...
language | js |
---|
...
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, "endTime": i + 1, "startTime": i , "UIstartTime": i + 1, "UIendTime": i, "split": 0, "audiourl": "", "pos": 0, "editedTexttransliterationData": ""abc def ghi })) }) }jxy lzg".split(" ").map(w => ({ let x = JSON.stringify(finalValues) this.updateAnnotations(x) |
3. Load classes for annotation projects using custom code:
Code Block | ||
---|---|---|
| ||
let newClass = { Books: JSON.stringify({ "word": w, "colortags": "#FFEBE8"[], "hotkey": "", "attributeslanguageTag": ["", { "editedText": "" })) "name": "Price",}) } let x = JSON.stringify(finalValues) this.updateAnnotations(x) |
3. Load classes for annotation projects using custom code:
Code Block | ||
---|---|---|
| ||
let newClass = { "fieldType": "Text", Books: JSON.stringify({ "color": "#FFEBE8", "mandatoryFieldhotkey": false"", "attributes": [ { "name": "Price", "fieldType": "Text", "mandatoryField": false, "possible_value": [ "" ], "default_value": "" } ] }), Car: JSON.stringify({ "color": "#FF000", "hotkey": "c", "attributes": [ { "name": "attr1", "fieldType": "DropDown", "mandatoryField": false, "possible_value": [ "attr1_v1", "attr1_v2" ], "default_value": "attr1_v1" }, { "name": "attr2", "fieldType": "DropDown", "mandatoryField": false, "possible_value": [ "attr2_v1", "attr2_v2" ], "default_value": "attr2_v1" } ] }), Quills: JSON.stringify({ "color": "#C23456", "hotkey": "q", "attributes": [ { "name": "Colour", "fieldType": "Text", "mandatoryField": false, "possible_value": [ "Blue", "Green", "Yellow", "Red", "White", "Orange" ], "default_value": "blue" } ] }), 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": "" } ] }), Van: JSON.stringify({ "color": "#F24110", "hotkey": "v", "attributes": [ { "name": "Vans", "fieldType": "DropDown", "mandatoryField": false, "possible_value": [ "Ferrari", "Kia", "MG" ], "default_value": "" } ] }) }; this.changeAnnotationClasses(newClass); |
...
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)) 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")
}
} |