compromise
Version:
natural language processing in the browser
40 lines (37 loc) • 802 B
JavaScript
;
const fixContraction = require('./fix');
//the formulaic contraction types:
const easy_ends = {
'll': 'will',
'd': 'would',
've': 'have',
're': 'are',
'm': 'am',
'n\'t': 'not'
//these ones are a bit tricksier:
// 't': 'not',
// 's': 'is' //or was
};
//unambiguous contractions, like "'ll"
const easyOnes = (ts) => {
for(let i = 0; i < ts.terms.length; i++) {
//skip existing
if (ts.terms[i].silent_term) {
continue;
}
let parts = ts.terms[i].term.contraction();
if (parts) {
//make sure its an easy one
if (easy_ends[parts.end]) {
let arr = [
parts.start,
easy_ends[parts.end]
];
ts = fixContraction(ts, arr, i);
i += 1;
}
}
}
return ts;
};
module.exports = easyOnes;