compromise-sentences
Advanced tools
Comparing version 0.0.6 to 0.1.0
@@ -1,2 +0,2 @@ | ||
/* compromise-sentences 0.0.6 MIT */ | ||
/* compromise-sentences 0.1.0 MIT */ | ||
(function (global, factory) { | ||
@@ -322,4 +322,12 @@ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
var useParticiple = function useParticiple(vb) { | ||
if (vb.has('(could|should|would|may|can|must)')) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
/** he walks -> he walked */ | ||
var toPastTense = function toPastTense() { | ||
@@ -332,4 +340,33 @@ this.forEach(function (doc) { | ||
var obj = parse_1(doc); | ||
var vb = obj.verb.clone(); // support 'he could drive' -> 'he could have driven' | ||
if (useParticiple(vb)) { | ||
vb = vb.verbs().toParticiple(); | ||
obj.verb.replaceWith(vb, false); | ||
} else { | ||
//do a normal conjugation | ||
vb = vb.verbs().toPastTense(); | ||
obj.verb.replaceWith(vb, false); | ||
} // 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 drives -> he has driven */ | ||
var toParticiple = function toParticiple() { | ||
this.forEach(function (doc) { | ||
if (doc.has('has #Participle')) { | ||
return; | ||
} | ||
var obj = parse_1(doc); | ||
var vb = obj.verb.clone(); | ||
vb = vb.verbs().toPastTense(); | ||
vb = vb.verbs().toParticiple(); | ||
obj.verb.replaceWith(vb, false); // trailing gerund/future/present are okay, but 'walked and eats' is not | ||
@@ -339,3 +376,3 @@ | ||
var verbs = obj.object.verbs(); | ||
verbs["if"]('#PresentTense').verbs().toPastTense(); | ||
verbs["if"]('#PresentTense').verbs().toParticiple(); | ||
} | ||
@@ -398,2 +435,3 @@ }); | ||
toPastTense: toPastTense, | ||
toParticiple: toParticiple, | ||
toPresentTense: toPresentTense, | ||
@@ -400,0 +438,0 @@ toFutureTense: toFutureTense |
@@ -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).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}function o(e){var n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}();return function(){var o,s=t(e);if(n){var i=t(this).constructor;o=Reflect.construct(s,arguments,i)}else o=s.apply(this,arguments);return r(this,o)}}var s=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=s(t),r=n.match("#Determiner? (#Noun|#Adjective)+").if("#Noun"),o=n.verbs().eq(0);return{subject:r.eq(0),verb:o,object:o.lookAhead(".*")}},u={toNegative:function(){return this.forEach((function(e){var t=i(e),n=t.verb.clone();n=n.verbs().toNegative(),t.verb.replaceWith(n,!1)})),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)})),this}},c=function(e){var t=e.post(),n=e.clauses();return!0===/\?/.test(t)||!/\.\.$/.test(e.out("text"))&&((!e.has("^#QuestionWord")||!e.has("#Comma"))&&(!!e.has("^#QuestionWord")||(!!e.has("^(do|does|did|is|was|can|could|will|would|may) #Noun")||(!!e.has("^(have|must) you")||(!!n.has("^#QuestionWord")||!!n.has("(do|does|is|was) #Noun+ #Adverb? (#Adjective|#Infinitive)$"))))))},a={isQuestion:function(){return this.filter((function(e){return c(e)}))},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.post("!"),this},toQuestion:function(){return this.post("?"),this},toStatement:function(){return this.post("."),this}},f={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),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),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),t.object&&t.object.found&&t.object.has("(#PastTense|#PresentTense)"))&&t.object.verbs().if("(#PastTense|#PresentTense)").verbs().toInfinitive()})),this}},h=Object.assign({},u,a,f);return function(t){var r=function(t){!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)}(a,t);var r,s,u,c=o(a);function a(e,t,n){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,a),e=e.map((function(e){return e.clone(!0)})),c.call(this,e,t,n)}return r=a,(s=[{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),s=o.post;!0===t&&(s=""),r.append(e+s),o.post=" "})),this}}])&&e(r.prototype,s),u&&e(r,u),a}(t);return h.questions=h.isQuestion,h.exclamations=h.isExclamation,h.statements=h.isStatement,Object.assign(r.prototype,h),t.prototype.sentences=function(e){var t=[];this.list.forEach((function(e){t.push(e.fullSentence())}));var n=new r(t,this,this.world);return"number"==typeof e&&(n=n.get(e)),n},t}})); | ||
!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}function o(e){var n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}();return function(){var o,s=t(e);if(n){var i=t(this).constructor;o=Reflect.construct(s,arguments,i)}else o=s.apply(this,arguments);return r(this,o)}}var s=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=s(t),r=n.match("#Determiner? (#Noun|#Adjective)+").if("#Noun"),o=n.verbs().eq(0);return{subject:r.eq(0),verb:o,object:o.lookAhead(".*")}},u={toNegative:function(){return this.forEach((function(e){var t=i(e),n=t.verb.clone();n=n.verbs().toNegative(),t.verb.replaceWith(n,!1)})),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)})),this}},c=function(e){var t=e.post(),n=e.clauses();return!0===/\?/.test(t)||!/\.\.$/.test(e.out("text"))&&((!e.has("^#QuestionWord")||!e.has("#Comma"))&&(!!e.has("^#QuestionWord")||(!!e.has("^(do|does|did|is|was|can|could|will|would|may) #Noun")||(!!e.has("^(have|must) you")||(!!n.has("^#QuestionWord")||!!n.has("(do|does|is|was) #Noun+ #Adverb? (#Adjective|#Infinitive)$"))))))},a={isQuestion:function(){return this.filter((function(e){return c(e)}))},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.post("!"),this},toQuestion:function(){return this.post("?"),this},toStatement:function(){return this.post("."),this}},f={toPastTense:function(){return this.forEach((function(e){if(!e.has("#PastTense")){var t=i(e),n=t.verb.clone();if(!function(e){return!!e.has("(could|should|would|may|can|must)")}(n)?(n=n.verbs().toPastTense(),t.verb.replaceWith(n,!1)):(n=n.verbs().toParticiple(),t.verb.replaceWith(n,!1)),t.object&&t.object.found&&t.object.has("#PresentTense"))t.object.verbs().if("#PresentTense").verbs().toPastTense()}})),this},toParticiple:function(){return this.forEach((function(e){if(!e.has("has #Participle")){var t=i(e),n=t.verb.clone();if(n=n.verbs().toParticiple(),t.verb.replaceWith(n,!1),t.object&&t.object.found&&t.object.has("#PresentTense"))t.object.verbs().if("#PresentTense").verbs().toParticiple()}})),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),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),t.object&&t.object.found&&t.object.has("(#PastTense|#PresentTense)"))&&t.object.verbs().if("(#PastTense|#PresentTense)").verbs().toInfinitive()})),this}},h=Object.assign({},u,a,f);return function(t){var r=function(t){!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)}(a,t);var r,s,u,c=o(a);function a(e,t,n){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,a),e=e.map((function(e){return e.clone(!0)})),c.call(this,e,t,n)}return r=a,(s=[{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),s=o.post;!0===t&&(s=""),r.append(e+s),o.post=" "})),this}}])&&e(r.prototype,s),u&&e(r,u),a}(t);return h.questions=h.isQuestion,h.exclamations=h.isExclamation,h.statements=h.isStatement,Object.assign(r.prototype,h),t.prototype.sentences=function(e){var t=[];this.list.forEach((function(e){t.push(e.fullSentence())}));var n=new r(t,this,this.world);return"number"==typeof e&&(n=n.get(e)),n},t}})); |
{ | ||
"name": "compromise-sentences", | ||
"description": "plugin for nlp-compromise", | ||
"version": "0.0.6", | ||
"version": "0.1.0", | ||
"author": "Spencer Kelly <spencermountain@gmail.com> (http://spencermounta.in)", | ||
@@ -6,0 +6,0 @@ "main": "./builds/compromise-sentences.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
62775
949