compromise
Version:
natural language processing in the browser
43 lines (35 loc) • 911 B
JavaScript
;
const Terms = require('../../terms');
const splitMethods = (Text) => {
const methods = {
/**tag all the terms in this result as something */
tag: function (tag, reason) {
this.list.forEach((ts) => {
ts.tagAs(tag, reason);
});
return this;
},
/**remove a tag in all the terms in this result (that had it) */
unTag: function (tag, reason) {
this.list.forEach((ts) => {
ts.unTag(tag, reason);
});
return this;
},
/** see if these terms can become this tag*/
canBe: function (tag) {
this.list.forEach((ts) => {
ts.terms = ts.terms.filter((t) => {
return t.term.canBe(tag)
})
})
return this
},
}
//hook them into result.proto
Object.keys(methods).forEach((k) => {
Text.prototype[k] = methods[k];
});
return Text;
};
module.exports = splitMethods;