elliptical
Version:
Interactive natural-language interfaces
54 lines (41 loc) • 1.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const defaultProps = {
suppress: true,
suppressEmpty: true
};
function* visit(option, _ref, traverse) {
let props = _ref.props;
let children = _ref.children;
props = _lodash2.default.defaults({}, props, defaultProps);
const child = children[0];
if (props.suppress && option.text == null || props.suppressEmpty && option.text === '' || props.suppressWhen && props.suppressWhen(option.text)) {
yield outputSelf(option, child, props);
} else {
yield* parseChild(option, child, props, traverse);
}
}
function* parseChild(option, child, props, traverse) {
for (let output of traverse(child, option)) {
yield output;
}
}
function outputSelf(option, child, props) {
const word = {
label: props.label,
placeholder: true
};
const modification = {
score: 0.01,
result: undefined,
text: null,
words: option.words.concat(word)
};
return _lodash2.default.assign({}, option, modification);
}
exports.default = { visit: visit };