Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Fix bug with checking only the last required group #74

Merged
merged 1 commit into from
May 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/required/completions/1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"completions": [
{
"id": "1001",
"result": []
}
],
"data": {
"text": "To have faith is to trust yourself to the water"
},
"id": 1,
"task_path": "../examples/references/tasks.json"
}
11 changes: 11 additions & 0 deletions examples/required/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<View>
<Text name="text" value="$text"></Text>
<Choices name="validation-label" required="true" toName="text">
<Choice value="Missing words" alias="missing-words"></Choice>
<Choice value="Valid" alias="valid"></Choice>
</Choices>
<Choices name="second" required="true" toName="text">
<Choice value="Don't select me" alias="dont"></Choice>
<Choice value="Me neither" alias="neither"></Choice>
</Choices>
</View>
5 changes: 5 additions & 0 deletions examples/required/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import config from "./config.xml";
import tasks from "./tasks.json";
import completion from "./completions/1.json";

export const Required = { config, tasks, completion };
31 changes: 31 additions & 0 deletions examples/required/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[
{
"data": {
"text": "To have faith is to trust yourself to the water"
},
"predictions": [
{
"model_version": "model 1",
"created_ago": "3 hours",
"result": [
{
"from_name": "validation-label",
"id": "NT0HCnJjv5",
"to_name": "text",
"type": "choices",
"value": {
"choices": [
"valid"
]
}
}
]
}
]
},
{
"data": {
"text": "When you swim you don't grab hold of the water, because if you do you will sink and drown. Instead you relax, and float."
}
}
]
11 changes: 9 additions & 2 deletions src/core/Tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import xml2js from "xml2js";
import Registry from "./Registry";
import { guidGenerator } from "./Helpers";

export const TRAVERSE_SKIP = "skip";
export const TRAVERSE_STOP = "stop";

/**
* Clone React Tree
* @param {*} items
Expand Down Expand Up @@ -327,10 +330,14 @@ function traverseTree(root, cb) {

visitNode = function(node) {
const res = cb(node);
if (res === "break") return;
if (res === TRAVERSE_SKIP) return;
if (res === TRAVERSE_STOP) return TRAVERSE_STOP;

if (node.children) {
node.children.forEach(chld => visitNode(chld));
for (let chld of node.children) {
const visit = visitNode(chld);
if (visit === TRAVERSE_STOP) return TRAVERSE_STOP;
}
}
};

Expand Down
3 changes: 2 additions & 1 deletion src/env/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Messages from "../utils/messages";
import { DialogueAnalysis } from "../examples/dialogue_analysis"; // eslint-disable-line no-unused-vars
import { NamedEntity } from "../examples/named_entity"; // eslint-disable-line no-unused-vars
import { References } from "../examples/references"; // eslint-disable-line no-unused-vars
import { Required } from "../examples/required"; // eslint-disable-line no-unused-vars
import { Sentiment } from "../examples/sentiment_analysis"; // eslint-disable-line no-unused-vars
import { Nested } from "../examples/nested_choices"; // eslint-disable-line no-unused-vars

Expand Down Expand Up @@ -42,7 +43,7 @@ import { Pairwise } from "../examples/pairwise"; // eslint-disable-line no-unuse
*/
// import { AllTypes } from "../examples/all_types"; // eslint-disable-line no-unused-vars

const data = HTMLDocument;
const data = Required;

/**
* Get current config
Expand Down
4 changes: 2 additions & 2 deletions src/stores/CompletionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import RegionStore from "./RegionStore";
import Registry from "../core/Registry";
import RelationStore from "./RelationStore";
import TimeTraveller from "../core/TimeTraveller";
import Tree from "../core/Tree";
import Tree, { TRAVERSE_STOP } from "../core/Tree";
import Types from "../core/Types";
import Utils from "../utils";
import { AllRegionsType } from "../regions";
Expand Down Expand Up @@ -177,7 +177,7 @@ const Completion = types
ok = node.validate();
if (ok === false) {
ok = false;
return "break";
return TRAVERSE_STOP;
}
}
});
Expand Down
3 changes: 2 additions & 1 deletion src/stores/RelationStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { types, destroy, getParentOfType, getRoot } from "mobx-state-tree";
import { cloneNode } from "../core/Helpers";
import { AllRegionsType } from "../regions";
import { RelationsModel } from "../tags/control/Relations";
import { TRAVERSE_SKIP } from "../core/Tree";

/**
* Relation between two different nodes
Expand Down Expand Up @@ -38,7 +39,7 @@ const Relation = types
c.traverseTree(function(node) {
if (node.type === "relations") {
relations = node;
return "break";
return TRAVERSE_SKIP;
}
});

Expand Down