compromise-sentences
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -1,2 +0,2 @@ | ||
/* compromise-sentences 0.0.5 MIT */ | ||
/* compromise-sentences 0.0.6 MIT */ | ||
(function (global, factory) { | ||
@@ -61,2 +61,15 @@ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
function _isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function _assertThisInitialized(self) { | ||
@@ -78,2 +91,21 @@ if (self === void 0) { | ||
function _createSuper(Derived) { | ||
var hasNativeReflectConstruct = _isNativeReflectConstruct(); | ||
return function _createSuperInternal() { | ||
var Super = _getPrototypeOf(Derived), | ||
result; | ||
if (hasNativeReflectConstruct) { | ||
var NewTarget = _getPrototypeOf(this).constructor; | ||
result = Reflect.construct(Super, arguments, NewTarget); | ||
} else { | ||
result = Super.apply(this, arguments); | ||
} | ||
return _possibleConstructorReturn(this, result); | ||
}; | ||
} | ||
// if a clause starts with these, it's not a main clause | ||
@@ -176,7 +208,67 @@ var subordinate = "(after|although|as|because|before|if|since|than|that|though|when|whenever|where|whereas|wherever|whether|while|why|unless|until|once)"; | ||
//is this sentence asking a question? | ||
var isQuestion = function isQuestion(doc) { | ||
var endPunct = doc.post(); | ||
var clauses = doc.clauses(); | ||
if (/\?/.test(endPunct) === true) { | ||
return true; | ||
} // Has ellipsis at the end means it's probably not a question | ||
// e.g., Is this just fantasy... | ||
if (/\.\.$/.test(doc.out('text'))) { | ||
return false; | ||
} // Starts with question word, but has a comma, so probably not a question | ||
// e.g., Why are we caught in a land slide, no escape from reality | ||
if (doc.has('^#QuestionWord') && doc.has('#Comma')) { | ||
return false; | ||
} // Starts with a #QuestionWord | ||
// e.g., What open your eyes look up to the skies and see | ||
if (doc.has('^#QuestionWord')) { | ||
return true; | ||
} // Second word is a #QuestionWord | ||
// e.g., I'm what a poor boy | ||
// case ts.has('^\w+\s#QuestionWord'): | ||
// return true; | ||
// is it, do you - start of sentence | ||
// e.g., Do I need no sympathy | ||
if (doc.has('^(do|does|did|is|was|can|could|will|would|may) #Noun')) { | ||
return true; | ||
} // these are a little more loose.. | ||
// e.g., Must I be come easy come easy go | ||
if (doc.has('^(have|must) you')) { | ||
return true; | ||
} // Clause starts with a question word | ||
// e.g., Anyway the wind blows, what doesn't really matter to me | ||
if (clauses.has('^#QuestionWord')) { | ||
return true; | ||
} //is wayne gretskzy alive | ||
if (clauses.has('(do|does|is|was) #Noun+ #Adverb? (#Adjective|#Infinitive)$')) { | ||
return true; | ||
} // Probably not a question | ||
return false; | ||
}; | ||
var isQuestion_1 = isQuestion; | ||
/** return sentences ending with '?' */ | ||
var isQuestion = function isQuestion() { | ||
return this.filter(function (doc) { | ||
var term = doc.lastTerm().termList(0); | ||
return term.hasPost('?'); | ||
var isQuestion_1$1 = function isQuestion_1$1() { | ||
return this.filter(function (d) { | ||
return isQuestion_1(d); | ||
}); | ||
@@ -206,2 +298,3 @@ }; | ||
var toExclamation = function toExclamation() { | ||
this.post('!'); | ||
return this; | ||
@@ -213,2 +306,3 @@ }; | ||
var toQuestion = function toQuestion() { | ||
this.post('?'); | ||
return this; | ||
@@ -220,7 +314,8 @@ }; | ||
var toStatement = function toStatement() { | ||
this.post('.'); | ||
return this; | ||
}; | ||
var punct = { | ||
isQuestion: isQuestion, | ||
var types = { | ||
isQuestion: isQuestion_1$1, | ||
isExclamation: isExclamation, | ||
@@ -310,11 +405,11 @@ isStatement: isStatement, | ||
var methods = Object.assign({}, negate, punct, tense); | ||
var methods = Object.assign({}, negate, types, tense); | ||
var addMethod = function addMethod(Doc) { | ||
/** */ | ||
var Sentences = | ||
/*#__PURE__*/ | ||
function (_Doc) { | ||
var Sentences = /*#__PURE__*/function (_Doc) { | ||
_inherits(Sentences, _Doc); | ||
var _super = _createSuper(Sentences); | ||
function Sentences(list, from, world) { | ||
@@ -326,3 +421,3 @@ _classCallCheck(this, Sentences); | ||
}); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(Sentences).call(this, list, from, world)); | ||
return _super.call(this, list, from, world); | ||
} | ||
@@ -422,4 +517,8 @@ /** overload the original json with noun information */ | ||
return Sentences; | ||
}(Doc); | ||
}(Doc); // add some aliases | ||
methods.questions = methods.isQuestion; | ||
methods.exclamations = methods.isExclamation; | ||
methods.statements = methods.isStatement; | ||
Object.assign(Sentences.prototype, methods); | ||
@@ -426,0 +525,0 @@ /** overload original sentences() method and return Sentence class**/ |
@@ -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}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)})),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}},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),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}},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.list.forEach((function(e){t.push(e.fullSentence())}));var n=new s(t,this,this.world);return"number"==typeof e&&(n=n.get(e)),n},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}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}})); |
{ | ||
"name": "compromise-sentences", | ||
"description": "plugin for nlp-compromise", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"author": "Spencer Kelly <spencermountain@gmail.com> (http://spencermounta.in)", | ||
@@ -6,0 +6,0 @@ "main": "./builds/compromise-sentences.js", |
@@ -13,3 +13,3 @@ <div align="center"> | ||
<a href="https://unpkg.com/compromise-sentences/builds/compromise-sentences.min.js"> | ||
<img src="https://badge-size.herokuapp.com/spencermountain/compromise-sentences/master/builds/compromise-sentences.min.js" /> | ||
<img src="https://badge-size.herokuapp.com/spencermountain/compromise/master/plugins/sentences/builds/compromise-sentences.min.js" /> | ||
</a> | ||
@@ -16,0 +16,0 @@ <hr/> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
58436
887