compromise-sentences
Advanced tools
Comparing version 0.0.1 to 0.0.2
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = global || self, global.nlp = factory()); | ||
(global = global || self, global.compromiseSentences = factory()); | ||
}(this, (function () { 'use strict'; | ||
@@ -133,3 +133,4 @@ | ||
var nouns = main.match('#Determiner? (#Noun|#Adjective)+')["if"]('#Noun'); | ||
var verb = main.match('#Verb+').eq(0); | ||
var verb = main.verbs().eq(0); // match('(do|will)? not? #Verb+ not?').eq(0) | ||
return { | ||
@@ -144,2 +145,163 @@ subject: nouns.eq(0), | ||
/** he walks -> he did not walk */ | ||
var toNegative = function toNegative() { | ||
this.forEach(function (doc) { | ||
var obj = parse_1(doc); | ||
var vb = obj.verb.clone(); | ||
vb = vb.verbs().toNegative(); | ||
obj.verb.replaceWith(vb, false, true); | ||
}); | ||
return this; | ||
}; | ||
/** he doesn't walk -> he walks */ | ||
var toPositive = function toPositive() { | ||
this.forEach(function (doc) { | ||
var obj = parse_1(doc); | ||
var vb = obj.verb.clone(); | ||
vb = vb.verbs().toPositive(); | ||
obj.verb.replaceWith(vb, false, true); | ||
}); | ||
return this; | ||
}; | ||
var negate = { | ||
toNegative: toNegative, | ||
toPositive: toPositive | ||
}; | ||
/** return sentences ending with '?' */ | ||
var isQuestion = function isQuestion() { | ||
return this.filter(function (doc) { | ||
var term = doc.lastTerm().termList(0); | ||
return term.hasPost('?'); | ||
}); | ||
}; | ||
/** return sentences ending with '!' */ | ||
var isExclamation = function isExclamation() { | ||
return this.filter(function (doc) { | ||
var term = doc.lastTerm().termList(0); | ||
return term.hasPost('!'); | ||
}); | ||
}; | ||
/** return sentences with neither a question or an exclamation */ | ||
var isStatement = function isStatement() { | ||
return this.filter(function (doc) { | ||
var term = doc.lastTerm().termList(0); | ||
return !term.hasPost('?') && !term.hasPost('!'); | ||
}); | ||
}; | ||
/** 'he is.' -> 'he is!' */ | ||
var toExclamation = function toExclamation() { | ||
return this; | ||
}; | ||
/** 'he is.' -> 'he is?' */ | ||
var toQuestion = function toQuestion() { | ||
return this; | ||
}; | ||
/** 'he is?' -> 'he is.' */ | ||
var toStatement = function toStatement() { | ||
return this; | ||
}; | ||
var punct = { | ||
isQuestion: isQuestion, | ||
isExclamation: isExclamation, | ||
isStatement: isStatement, | ||
toExclamation: toExclamation, | ||
toQuestion: toQuestion, | ||
toStatement: toStatement | ||
}; | ||
/** he walks -> he walked */ | ||
var toPastTense = function toPastTense() { | ||
this.forEach(function (doc) { | ||
if (doc.has('#PastTense')) { | ||
return; | ||
} | ||
var obj = parse_1(doc); | ||
var vb = obj.verb.clone(); | ||
vb = vb.verbs().toPastTense(); | ||
obj.verb.replaceWith(vb, false, true); // trailing gerund/future/present are okay, but 'walked and eats' is not | ||
if (obj.object && obj.object.found && obj.object.has('#PresentTense')) { | ||
var verbs = obj.object.verbs(); | ||
verbs["if"]('#PresentTense').verbs().toPastTense(); | ||
} | ||
}); | ||
return this; | ||
}; | ||
/** he walked -> he walks */ | ||
var toPresentTense = function toPresentTense() { | ||
this.forEach(function (doc) { | ||
var obj = parse_1(doc); | ||
var isPlural = obj.verb.lookBehind('(i|we) (#Adverb|#Verb)?$').found; | ||
var vb = obj.verb.clone(); // 'i look', not 'i looks' | ||
if (isPlural) { | ||
//quick hack for copula verb - be/am | ||
if (vb.has('(is|was|am|be)')) { | ||
vb = vb.replace('will? (is|was|am|be)', 'am'); | ||
} else { | ||
vb = vb.verbs().toInfinitive(); | ||
} | ||
} else { | ||
//'he looks' | ||
vb = vb.verbs().toPresentTense(); | ||
} | ||
obj.verb.replaceWith(vb, false, true); // future is okay, but 'walks and ate' -> 'walks and eats' | ||
if (obj.object && obj.object.found && obj.object.has('#PastTense')) { | ||
var verbs = obj.object.verbs(); | ||
verbs["if"]('#PastTense').verbs().toPresentTense(); | ||
} | ||
}); | ||
return this; | ||
}; | ||
/**he walked -> he will walk */ | ||
var toFutureTense = function toFutureTense() { | ||
this.forEach(function (doc) { | ||
var obj = parse_1(doc); | ||
var vb = obj.verb.clone(); | ||
vb = vb.verbs().toFutureTense(); | ||
obj.verb.replaceWith(vb, false, true); //Present is okay, but 'will walk and ate' -> 'will walk and eat' | ||
if (obj.object && obj.object.found && obj.object.has('(#PastTense|#PresentTense)')) { | ||
var verbs = obj.object.verbs(); | ||
verbs["if"]('(#PastTense|#PresentTense)').verbs().toInfinitive(); | ||
} | ||
}); | ||
return this; | ||
}; // toContinuous() { | ||
// return this | ||
// } | ||
var tense = { | ||
toPastTense: toPastTense, | ||
toPresentTense: toPresentTense, | ||
toFutureTense: toFutureTense | ||
}; | ||
var methods = Object.assign({}, negate, punct, tense); | ||
var addMethod = function addMethod(Doc) { | ||
@@ -205,70 +367,2 @@ /** */ | ||
} | ||
/** he walks -> he walked */ | ||
}, { | ||
key: "toPastTense", | ||
value: function toPastTense() { | ||
this.forEach(function (doc) { | ||
var obj = parse_1(doc); | ||
var vb = obj.verb.clone(); | ||
vb = vb.verbs().toPastTense(); | ||
obj.verb.replaceWith(vb, false, true); | ||
}); | ||
return this; | ||
} | ||
/** he walked -> he walks */ | ||
}, { | ||
key: "toPresentTense", | ||
value: function toPresentTense() { | ||
this.forEach(function (doc) { | ||
var obj = parse_1(doc); | ||
var vb = obj.verb.clone(); | ||
vb = vb.verbs().toPresentTense(); | ||
obj.verb.replaceWith(vb, false, true); | ||
}); | ||
return this; | ||
} | ||
/** he walks -> he will walk */ | ||
}, { | ||
key: "toFutureTense", | ||
value: function toFutureTense() { | ||
this.forEach(function (doc) { | ||
var obj = parse_1(doc); | ||
var vb = obj.verb.clone(); | ||
vb = vb.verbs().toFutureTense(); | ||
obj.verb.replaceWith(vb, false, true); | ||
}); | ||
return this; | ||
} // toContinuous() { | ||
// return this | ||
// } | ||
/** he walks -> he did not walk */ | ||
}, { | ||
key: "toNegative", | ||
value: function toNegative() { | ||
this.forEach(function (doc) { | ||
var obj = parse_1(doc); | ||
var vb = obj.verb.clone(); | ||
vb = vb.verbs().toNegative(); | ||
obj.verb.replaceWith(vb, false, true); | ||
}); | ||
return this; | ||
} | ||
/** he doesn't walk -> he walks */ | ||
}, { | ||
key: "toPositive", | ||
value: function toPositive() { | ||
this.forEach(function (doc) { | ||
var obj = parse_1(doc); | ||
var vb = obj.verb.clone(); | ||
vb = vb.verbs().toPositive(); | ||
obj.verb.replaceWith(vb, false, true); | ||
}); | ||
return this; | ||
} | ||
/** return sentences that are in passive-voice */ | ||
@@ -279,34 +373,4 @@ | ||
value: function isPassive() { | ||
return this.has('was #Adverb? #PastTense #Adverb? by'); //haha | ||
return this["if"]('was #Adverb? #PastTense #Adverb? by'); //haha | ||
} | ||
/** return sentences ending with '?' */ | ||
}, { | ||
key: "isQuestion", | ||
value: function isQuestion() { | ||
return this.filter(function (doc) { | ||
var term = doc.lastTerm().termList(0); | ||
return term.hasPost('?'); | ||
}); | ||
} | ||
/** return sentences ending with '!' */ | ||
}, { | ||
key: "isExclamation", | ||
value: function isExclamation() { | ||
return this.filter(function (doc) { | ||
var term = doc.lastTerm().termList(0); | ||
return term.hasPost('!'); | ||
}); | ||
} | ||
/** return sentences with neither a question or an exclamation */ | ||
}, { | ||
key: "isStatement", | ||
value: function isStatement() { | ||
return this.filter(function (doc) { | ||
var term = doc.lastTerm().termList(0); | ||
return !term.hasPost('?') && !term.hasPost('!'); | ||
}); | ||
} | ||
/** add a word to the start of this sentence */ | ||
@@ -326,2 +390,3 @@ | ||
}); | ||
return this; | ||
} | ||
@@ -348,24 +413,4 @@ /** add a word to the end of this sentence */ | ||
}); | ||
} | ||
/** 'he is.' -> 'he is!' */ | ||
}, { | ||
key: "toExclamation", | ||
value: function toExclamation() { | ||
return this; | ||
} | ||
/** 'he is.' -> 'he is?' */ | ||
}, { | ||
key: "toQuestion", | ||
value: function toQuestion() { | ||
return this; | ||
} | ||
/** 'he is?' -> 'he is.' */ | ||
}, { | ||
key: "toStatement", | ||
value: function toStatement() { | ||
return this; | ||
} | ||
}]); | ||
@@ -376,2 +421,4 @@ | ||
Object.assign(Sentences.prototype, methods); | ||
Doc.prototype.sentences = function (n) { | ||
@@ -378,0 +425,0 @@ var match = this.all(); //grab (n)th result |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).nlp=t()}(this,(function(){"use strict";function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function t(e){return(t=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function n(e,t){return(n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function r(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}var o=function(e){var t=e.clone(!0);return 1===t.length?t:1===(t=t.if("#Verb")).length?t:1===(t=(t=(t=(t=(t=t.ifNo("(after|although|as|because|before|if|since|than|that|though|when|whenever|where|whereas|wherever|whether|while|why|unless|until|once)")).ifNo("^even (if|though)")).ifNo("^so that")).ifNo("^rather than")).ifNo("^provided that")).length?t:1===(t=t.ifNo("(that|which|whichever|who|whoever|whom|whose|whomever)")).length?t:1===(t=t.ifNo("(despite|during|before|through|throughout)")).length?t:(0===t.length&&(t=e),t.eq(0))},i=function(e){var t=e.clauses(),n=o(t),r=n.match("#Determiner? (#Noun|#Adjective)+").if("#Noun"),i=n.match("#Verb+").eq(0);return{subject:r.eq(0),verb:i,object:i.lookAhead(".*")}};return function(o){var u=function(o){function u(e,n,o){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,u),e=e.map((function(e){return e.clone(!0)})),r(this,t(u).call(this,e,n,o))}var s,a,c;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&n(e,t)}(u,o),s=u,(a=[{key:"json",value:function(e){var t=null;"number"==typeof e&&(t=e,e=null),e=e||{text:!0,normal:!0,trim:!0,terms:!0};var n=[];return this.forEach((function(t){var r=t.json(e)[0],o=i(t);r.subject=o.subject.json(e)[0],r.verb=o.verb.json(e)[0],r.object=o.object.json(e)[0],n.push(r)})),null!==t?n[t]:n}},{key:"subjects",value:function(){return this.map((function(e){return i(e).subject}))}},{key:"toPastTense",value:function(){return this.forEach((function(e){var t=i(e),n=t.verb.clone();n=n.verbs().toPastTense(),t.verb.replaceWith(n,!1,!0)})),this}},{key:"toPresentTense",value:function(){return this.forEach((function(e){var t=i(e),n=t.verb.clone();n=n.verbs().toPresentTense(),t.verb.replaceWith(n,!1,!0)})),this}},{key:"toFutureTense",value:function(){return this.forEach((function(e){var t=i(e),n=t.verb.clone();n=n.verbs().toFutureTense(),t.verb.replaceWith(n,!1,!0)})),this}},{key:"toNegative",value:function(){return this.forEach((function(e){var t=i(e),n=t.verb.clone();n=n.verbs().toNegative(),t.verb.replaceWith(n,!1,!0)})),this}},{key:"toPositive",value:function(){return this.forEach((function(e){var t=i(e),n=t.verb.clone();n=n.verbs().toPositive(),t.verb.replaceWith(n,!1,!0)})),this}},{key:"isPassive",value:function(){return this.has("was #Adverb? #PastTense #Adverb? by")}},{key:"isQuestion",value:function(){return this.filter((function(e){return e.lastTerm().termList(0).hasPost("?")}))}},{key:"isExclamation",value:function(){return this.filter((function(e){return e.lastTerm().termList(0).hasPost("!")}))}},{key:"isStatement",value:function(){return this.filter((function(e){var t=e.lastTerm().termList(0);return!t.hasPost("?")&&!t.hasPost("!")}))}},{key:"prepend",value:function(e){this.forEach((function(t){var n=t.match("^.");n.not("#ProperNoun").toLowerCase(),n.prepend(e),n.terms(0).toTitleCase()}))}},{key:"append",value:function(e){var t=/[.?!]\s*$/.test(e);this.forEach((function(n){var r=n.match(".$"),o=r.termList(0),i=o.post;!0===t&&(i=""),r.append(e+i),o.post=" "}))}},{key:"toExclamation",value:function(){return this}},{key:"toQuestion",value:function(){return this}},{key:"toStatement",value:function(){return this}}])&&e(s.prototype,a),c&&e(s,c),u}(o);return o.prototype.sentences=function(e){var t=this.all();return"number"==typeof e&&(t=t.get(e)),new u(t.list,this,this.world)},o}})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).compromiseSentences=t()}(this,(function(){"use strict";function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function t(e){return(t=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function n(e,t){return(n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function r(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}var o=function(e){var t=e.clone(!0);return 1===t.length?t:1===(t=t.if("#Verb")).length?t:1===(t=(t=(t=(t=(t=t.ifNo("(after|although|as|because|before|if|since|than|that|though|when|whenever|where|whereas|wherever|whether|while|why|unless|until|once)")).ifNo("^even (if|though)")).ifNo("^so that")).ifNo("^rather than")).ifNo("^provided that")).length?t:1===(t=t.ifNo("(that|which|whichever|who|whoever|whom|whose|whomever)")).length?t:1===(t=t.ifNo("(despite|during|before|through|throughout)")).length?t:(0===t.length&&(t=e),t.eq(0))},i=function(e){var t=e.clauses(),n=o(t),r=n.match("#Determiner? (#Noun|#Adjective)+").if("#Noun"),i=n.verbs().eq(0);return{subject:r.eq(0),verb:i,object:i.lookAhead(".*")}},s={toNegative:function(){return this.forEach((function(e){var t=i(e),n=t.verb.clone();n=n.verbs().toNegative(),t.verb.replaceWith(n,!1,!0)})),this},toPositive:function(){return this.forEach((function(e){var t=i(e),n=t.verb.clone();n=n.verbs().toPositive(),t.verb.replaceWith(n,!1,!0)})),this}},u={isQuestion:function(){return this.filter((function(e){return e.lastTerm().termList(0).hasPost("?")}))},isExclamation:function(){return this.filter((function(e){return e.lastTerm().termList(0).hasPost("!")}))},isStatement:function(){return this.filter((function(e){var t=e.lastTerm().termList(0);return!t.hasPost("?")&&!t.hasPost("!")}))},toExclamation:function(){return this},toQuestion:function(){return this},toStatement:function(){return this}},c={toPastTense:function(){return this.forEach((function(e){if(!e.has("#PastTense")){var t=i(e),n=t.verb.clone();if(n=n.verbs().toPastTense(),t.verb.replaceWith(n,!1,!0),t.object&&t.object.found&&t.object.has("#PresentTense"))t.object.verbs().if("#PresentTense").verbs().toPastTense()}})),this},toPresentTense:function(){return this.forEach((function(e){var t=i(e),n=t.verb.lookBehind("(i|we) (#Adverb|#Verb)?$").found,r=t.verb.clone();(r=n?r.has("(is|was|am|be)")?r.replace("will? (is|was|am|be)","am"):r.verbs().toInfinitive():r.verbs().toPresentTense(),t.verb.replaceWith(r,!1,!0),t.object&&t.object.found&&t.object.has("#PastTense"))&&t.object.verbs().if("#PastTense").verbs().toPresentTense()})),this},toFutureTense:function(){return this.forEach((function(e){var t=i(e),n=t.verb.clone();(n=n.verbs().toFutureTense(),t.verb.replaceWith(n,!1,!0),t.object&&t.object.found&&t.object.has("(#PastTense|#PresentTense)"))&&t.object.verbs().if("(#PastTense|#PresentTense)").verbs().toInfinitive()})),this}},a=Object.assign({},s,u,c);return function(o){var s=function(o){function s(e,n,o){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,s),e=e.map((function(e){return e.clone(!0)})),r(this,t(s).call(this,e,n,o))}var u,c,a;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&n(e,t)}(s,o),u=s,(c=[{key:"json",value:function(e){var t=null;"number"==typeof e&&(t=e,e=null),e=e||{text:!0,normal:!0,trim:!0,terms:!0};var n=[];return this.forEach((function(t){var r=t.json(e)[0],o=i(t);r.subject=o.subject.json(e)[0],r.verb=o.verb.json(e)[0],r.object=o.object.json(e)[0],n.push(r)})),null!==t?n[t]:n}},{key:"subjects",value:function(){return this.map((function(e){return i(e).subject}))}},{key:"isPassive",value:function(){return this.if("was #Adverb? #PastTense #Adverb? by")}},{key:"prepend",value:function(e){return this.forEach((function(t){var n=t.match("^.");n.not("#ProperNoun").toLowerCase(),n.prepend(e),n.terms(0).toTitleCase()})),this}},{key:"append",value:function(e){var t=/[.?!]\s*$/.test(e);return this.forEach((function(n){var r=n.match(".$"),o=r.termList(0),i=o.post;!0===t&&(i=""),r.append(e+i),o.post=" "})),this}}])&&e(u.prototype,c),a&&e(u,a),s}(o);return Object.assign(s.prototype,a),o.prototype.sentences=function(e){var t=this.all();return"number"==typeof e&&(t=t.get(e)),new s(t.list,this,this.world)},o}})); |
{ | ||
"name": "compromise-sentences", | ||
"description": "plugin for nlp-compromise", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"author": "Spencer Kelly <spencermountain@gmail.com> (http://spencermounta.in)", | ||
@@ -37,3 +37,3 @@ "main": "./builds/compromise-sentences.js", | ||
"devDependencies": { | ||
"rollup": "1.26.3", | ||
"rollup": "1.27.5", | ||
"rollup-plugin-babel": "^4.3.3", | ||
@@ -40,0 +40,0 @@ "rollup-plugin-commonjs": "^10.0.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47180
694