UNPKG

compromise

Version:
30 lines (26 loc) 752 B
'use strict'; const paths = require('../paths'); const Term = paths.Term; const log = paths.log; const path = 'tagger/combine'; //merge two term objects.. carefully const makeText = (a, b) => { let text = a.whitespace.before + a.text + a.whitespace.after; text += b.whitespace.before + b.text + b.whitespace.after; return text; }; const combine = function(s, i) { let a = s.terms[i]; let b = s.terms[i + 1]; if (!b) { return; } log.tell('--combining: "' + a.normal + '"+"' + b.normal + '"', path); let text = makeText(a, b); s.terms[i] = new Term(text, a.context); s.terms[i].normal = a.normal + ' ' + b.normal; s.terms[i + 1] = null; s.terms = s.terms.filter((t) => t !== null); return; }; module.exports = combine;