Skip to content

Commit

Permalink
Add word count and JSON validation examples
Browse files Browse the repository at this point in the history
  • Loading branch information
smohan123 committed Sep 24, 2024
1 parent 857191d commit c31f177
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
22 changes: 22 additions & 0 deletions count_words_in_textarea/html.txt
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."
}-->
15 changes: 15 additions & 0 deletions count_words_in_textarea/js.txt
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;
});
5 changes: 5 additions & 0 deletions validate_json_in_textarea/data.json
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"
}
}
16 changes: 16 additions & 0 deletions validate_json_in_textarea/html.txt
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"
}-->
12 changes: 12 additions & 0 deletions validate_json_in_textarea/js.txt
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;
});

0 comments on commit c31f177

Please sign in to comment.