elliptical
Version:
Interactive natural-language interfaces
70 lines (55 loc) • 1.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _match = require('../match');
var _element = require('../element');
var _element2 = _interopRequireDefault(_element);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function compute(input, text, strategy) {
if (text == null) return [];
const matchObj = (0, _match.match)({ input: input, text: text, strategy: strategy });
if (matchObj) {
return [matchObj];
} else {
return [];
}
} /** @jsx createElement */
function decorateFunc(input, text) {
if (input == null || input === '') {
return [];
} else {
return [{
words: [{ text: text, input: false }],
remaining: input,
score: 1
}];
}
}
function describe(_ref) {
let props = _ref.props;
props = _lodash2.default.defaults({}, props, {
text: '',
decorate: false,
allowInput: true,
strategy: 'start',
limitDecoration: true
});
if (props.decorate) {
if (props.allowInput) {
return (0, _element2.default)(
'choice',
{ limit: props.limitDecoration ? 1 : undefined },
(0, _element2.default)('literal', { text: props.text, strategy: props.strategy }),
(0, _element2.default)('raw', { func: option => decorateFunc(option.text, props.text) })
);
} else {
return (0, _element2.default)('raw', { func: option => decorateFunc(option.text, props.text) });
}
} else {
return (0, _element2.default)('raw', { func: option => compute(option.text, props.text, props.strategy) });
}
}
exports.default = { describe: describe };