-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add word count and JSON validation examples
- Loading branch information
Showing
6 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<View> | ||
<Header value="Classify the text and describe it in the text box"/> | ||
<Text name="text" value="$text" /> | ||
<View style="position: sticky; top: 0; height: 50px; overflow: auto;"> | ||
<Labels name="label" toName="text"> | ||
<Label value="label_1"/> | ||
<Label value="label_2"/> | ||
</Labels> | ||
</View> | ||
<Taxonomy name="taxonomy" toName="text"> | ||
<Choice value="Alakazam!" /> | ||
<Choice value="Brick" /> | ||
<Choice value="Creature"> | ||
<Choice value="Human" /> | ||
<Choice value="Opossum" /> | ||
<Choice value="Extraterrestial" /> | ||
</Choice> | ||
</Taxonomy> | ||
<TextArea name="textarea" toName="text" /> | ||
</View><!--{ | ||
"text": "The quick brown fox jumps over the lazy dog." | ||
}--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
let dismissed = false; | ||
|
||
LSI.on("beforeSaveAnnotation", (store, annotation) => { | ||
const textAreaResult = annotation.results.find(r => r.type === 'textarea' && r.from_name.name === 'textarea'); | ||
if (textAreaResult) { | ||
words = textAreaResult.value.text[0] | ||
word_count = words.split(/(\s+)/).length; | ||
if (word_count > 10) { | ||
Htx.showModal("Word count is " + word_count + ". Please reduce to 10 or less."); | ||
dismissed = true; | ||
return false; | ||
} | ||
} | ||
return true; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"data": { | ||
"text": "The quick brown fox jumps over the lazy dog" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<View> | ||
<Header value="Classify the text and represent the data in JSON"/> | ||
<Text name="text" value="$text"/> | ||
<Taxonomy name="taxonomy" toName="text"> | ||
<Choice value="Alakazam!" /> | ||
<Choice value="Brick" /> | ||
<Choice value="Creature"> | ||
<Choice value="Human" /> | ||
<Choice value="Opossum" /> | ||
<Choice value="Extraterrestial" /> | ||
</Choice> | ||
</Taxonomy> | ||
<TextArea name="textarea" toName="text"/> | ||
</View><!--{ | ||
"text": "The quick brown fox jumps over the lazy dog" | ||
}--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
LSI.on("beforeSaveAnnotation", (store, annotation) => { | ||
const textAreaResult = annotation.results.find(r => r.type === 'textarea' && r.from_name.name === 'textarea'); | ||
if (textAreaResult) { | ||
try { | ||
JSON.parse(textAreaResult.value.text[0]); | ||
} catch (e) { | ||
Htx.showModal("Invalid JSON format. Please correct the JSON and try again.", "error"); | ||
return false; | ||
} | ||
} | ||
return true; | ||
}); |