Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

compromise-sentences

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

compromise-sentences - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

305

builds/compromise-sentences.js

@@ -1,2 +0,2 @@

/* compromise-sentences 0.2.0 MIT */
/* compromise-sentences 0.3.0 MIT */
(function (global, factory) {

@@ -8,87 +8,2 @@ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :

function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
if (superClass) _setPrototypeOf(subClass, superClass);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
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) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _possibleConstructorReturn(self, call) {
if (call && (typeof call === "object" || typeof call === "function")) {
return call;
}
return _assertThisInitialized(self);
}
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);
};
}
var tags = {

@@ -118,3 +33,3 @@ // Phrase: {},

var tagger = function tagger(doc) {
const tagger = function (doc) {
doc.match('#Noun').tag('NounPhrase');

@@ -157,6 +72,6 @@ doc.match('#Verb').tag('VerbPhrase'); // NounPhrase

/** add a word to the start of this sentence */
var prepend = function prepend(str) {
this.forEach(function (doc) {
var prepend = function (str) {
this.forEach(doc => {
// repair the titlecase
var firstTerms = doc.match('^.');
let firstTerms = doc.match('^.');
firstTerms.not('#ProperNoun').toLowerCase(); // actually add the word

@@ -174,8 +89,8 @@

var append_1 = function append_1(str) {
var hasEnd = /[.?!]\s*$/.test(str);
this.forEach(function (doc) {
var end = doc.match('.$');
var lastTerm = end.termList(0);
var punct = lastTerm.post;
var append_1 = function (str) {
let hasEnd = /[.?!]\s*$/.test(str);
this.forEach(doc => {
let end = doc.match('.$');
let lastTerm = end.termList(0);
let punct = lastTerm.post;

@@ -201,7 +116,7 @@ if (hasEnd === true) {

// if a clause starts with these, it's not a main clause
var subordinate = "(after|although|as|because|before|if|since|than|that|though|when|whenever|where|whereas|wherever|whether|while|why|unless|until|once)";
var relative = "(that|which|whichever|who|whoever|whom|whose|whomever)"; //try to remove secondary clauses
const subordinate = `(after|although|as|because|before|if|since|than|that|though|when|whenever|where|whereas|wherever|whether|while|why|unless|until|once)`;
const relative = `(that|which|whichever|who|whoever|whom|whose|whomever)`; //try to remove secondary clauses
var mainClause = function mainClause(og) {
var m = og.clone(true);
const mainClause = function (og) {
let m = og.clone(true);

@@ -213,3 +128,3 @@ if (m.length === 1) {

m = m["if"]('#Verb');
m = m.if('#Verb');

@@ -255,7 +170,7 @@ if (m.length === 1) {

var parse = function parse(doc) {
var clauses = doc.clauses();
var main = mainClause_1(clauses);
var nouns = main.match('#Determiner? (#Noun|#Adjective)+')["if"]('#Noun');
var verb = main.verbs().eq(0); // match('(do|will)? not? #Verb+ not?').eq(0)
const parse = function (doc) {
let clauses = doc.clauses();
let main = mainClause_1(clauses);
let nouns = main.match('#Determiner? (#Noun|#Adjective)+').if('#Noun');
let verb = main.verbs().eq(0); // match('(do|will)? not? #Verb+ not?').eq(0)

@@ -273,4 +188,4 @@ return {

var json_1 = function json_1(options) {
var n = null;
var json_1 = function (options) {
let n = null;

@@ -288,7 +203,7 @@ if (typeof options === 'number') {

};
var res = [];
this.forEach(function (doc) {
var json = doc._json(options)[0];
let res = [];
this.forEach(doc => {
let json = doc._json(options)[0];
var obj = parse_1(doc);
let obj = parse_1(doc);
json.subject = obj.subject.json(options)[0];

@@ -313,6 +228,6 @@ json.verb = obj.verb.json(options)[0];

var toNegative = function toNegative() {
this.forEach(function (doc) {
var obj = parse_1(doc);
var vb = obj.verb.clone();
var toNegative = function () {
this.forEach(doc => {
let obj = parse_1(doc);
let vb = obj.verb.clone();
vb = vb.verbs().toNegative();

@@ -326,6 +241,6 @@ obj.verb.replaceWith(vb, false);

var toPositive = function toPositive() {
this.forEach(function (doc) {
var obj = parse_1(doc);
var vb = obj.verb.clone();
var toPositive = function () {
this.forEach(doc => {
let obj = parse_1(doc);
let vb = obj.verb.clone();
vb = vb.verbs().toPositive();

@@ -343,5 +258,5 @@ obj.verb.replaceWith(vb, false);

//is this sentence asking a question?
var isQuestion = function isQuestion(doc) {
var endPunct = doc.post();
var clauses = doc.clauses();
const isQuestion = function (doc) {
let endPunct = doc.post();
let clauses = doc.clauses();

@@ -405,6 +320,4 @@ if (/\?/.test(endPunct) === true) {

var isQuestion_1 = function isQuestion_1() {
return this.filter(function (d) {
return isQuestion_1$1(d);
});
var isQuestion_1 = function () {
return this.filter(d => isQuestion_1$1(d));
};

@@ -414,5 +327,5 @@ /** return sentences ending with '!' */

var isExclamation = function isExclamation() {
return this.filter(function (doc) {
var term = doc.lastTerm().termList(0);
var isExclamation = function () {
return this.filter(doc => {
let term = doc.lastTerm().termList(0);
return term.hasPost('!');

@@ -424,5 +337,5 @@ });

var isStatement = function isStatement() {
return this.filter(function (doc) {
var term = doc.lastTerm().termList(0);
var isStatement = function () {
return this.filter(doc => {
let term = doc.lastTerm().termList(0);
return !term.hasPost('?') && !term.hasPost('!');

@@ -434,3 +347,3 @@ });

var toExclamation = function toExclamation() {
var toExclamation = function () {
this.post('!');

@@ -442,3 +355,3 @@ return this;

var toQuestion = function toQuestion() {
var toQuestion = function () {
this.post('?');

@@ -450,3 +363,3 @@ return this;

var toStatement = function toStatement() {
var toStatement = function () {
this.post('.');

@@ -465,3 +378,3 @@ return this;

var useParticiple = function useParticiple(vb) {
const useParticiple = function (vb) {
if (vb.has('(could|should|would|may|can|must)')) {

@@ -476,4 +389,4 @@ return true;

var toPastTense = function toPastTense() {
this.forEach(function (doc) {
var toPastTense = function () {
this.forEach(doc => {
if (doc.has('#PastTense')) {

@@ -483,4 +396,4 @@ return;

var obj = parse_1(doc);
var vb = obj.verb.clone(); // support 'he could drive' -> 'he could have driven'
let obj = parse_1(doc);
let vb = obj.verb.clone(); // support 'he could drive' -> 'he could have driven'

@@ -491,11 +404,16 @@ if (useParticiple(vb)) {

} else {
// //do a normal conjugation
//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
} // force agreement with any 2nd/3rd verbs:
// 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();
let verbs = obj.object.verbs(); // remove any sorta infinitive - 'to engage'
verbs = verbs.filter(v => {
return !v.lookBehind('to$').found;
});
verbs.if('#PresentTense').notIf('#Gerund').verbs().toPastTense();
}

@@ -508,4 +426,4 @@ });

var toParticiple = function toParticiple() {
this.forEach(function (doc) {
var toParticiple = function () {
this.forEach(doc => {
if (doc.has('has #Participle')) {

@@ -515,4 +433,4 @@ return;

var obj = parse_1(doc);
var vb = obj.verb.clone();
let obj = parse_1(doc);
let vb = obj.verb.clone();
vb = vb.verbs().toParticiple();

@@ -522,4 +440,4 @@ 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().toParticiple();
let verbs = obj.object.verbs();
verbs.if('#PresentTense').verbs().toParticiple();
}

@@ -532,7 +450,7 @@ });

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'
var toPresentTense = function () {
this.forEach(doc => {
let obj = parse_1(doc);
let isPlural = obj.verb.lookBehind('(i|we) (#Adverb|#Verb)?$').found;
let vb = obj.verb.clone(); // 'i look', not 'i looks'

@@ -554,4 +472,4 @@ if (isPlural) {

if (obj.object && obj.object.found && obj.object.has('#PastTense')) {
var verbs = obj.object.verbs();
verbs["if"]('#PastTense').verbs().toPresentTense();
let verbs = obj.object.verbs();
verbs.if('#PastTense').notIf('#Gerund').verbs().toPresentTense();
}

@@ -564,6 +482,6 @@ });

var toFutureTense = function toFutureTense() {
this.forEach(function (doc) {
var obj = parse_1(doc);
var vb = obj.verb.clone();
var toFutureTense = function () {
this.forEach(doc => {
let obj = parse_1(doc);
let vb = obj.verb.clone();
vb = vb.verbs().toFutureTense();

@@ -573,4 +491,12 @@ obj.verb.replaceWith(vb, false); //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();
let verbs = obj.object.verbs(); // add 'that attempts'
verbs = verbs.if('(#PastTense|#PresentTense)').notIf('#Gerund');
verbs.forEach(v => {
if (v.lookBehind('(that|which|who|whom)$').found === true) {
v.verbs().toPresentTense();
} else {
v.verbs().toInfinitive();
}
});
}

@@ -583,5 +509,5 @@ });

var subjects = function subjects() {
return this.map(function (doc) {
var res = parse_1(doc);
var subjects = function () {
return this.map(doc => {
let res = parse_1(doc);
return res.subject;

@@ -593,4 +519,4 @@ });

var isPassive = function isPassive() {
return this["if"]('was #Adverb? #PastTense #Adverb? by'); //haha
var isPassive = function () {
return this.if('was #Adverb? #PastTense #Adverb? by'); //haha
};

@@ -607,5 +533,5 @@

var phrases_1 = function phrases_1() {
var arr = [];
this.forEach(function (s) {
var phrases_1 = function () {
let arr = [];
this.forEach(s => {
s = s.splitOn('#VerbPhrase+');

@@ -623,5 +549,5 @@ s = s.splitOn('#NounPhrase+');

var methods = Object.assign({}, append, json, negative, questions, tense, phrases);
const methods = Object.assign({}, append, json, negative, questions, tense, phrases);
var plugin = function plugin(Doc, world) {
const plugin = function (Doc, world) {
// our new tags

@@ -633,18 +559,9 @@ world.addTags(tags); // run our tagger

var Sentences = /*#__PURE__*/function (_Doc) {
_inherits(Sentences, _Doc);
var _super = _createSuper(Sentences);
function Sentences(list, from, w) {
_classCallCheck(this, Sentences);
list = list.map(function (p) {
return p.clone(true);
});
return _super.call(this, list, from, w);
class Sentences extends Doc {
constructor(list, from, w) {
list = list.map(p => p.clone(true));
super(list, from, w);
}
return Sentences;
}(Doc); // add some aliases
} // add some aliases

@@ -663,6 +580,4 @@

Sentences.prototype.buildFrom = function (list) {
list = list.map(function (p) {
return p.clone(true);
});
var doc = new Sentences(list, this, this.world);
list = list.map(p => p.clone(true));
let doc = new Sentences(list, this, this.world);
return doc;

@@ -680,7 +595,7 @@ };

Doc.prototype.sentences = function (n) {
var arr = [];
this.list.forEach(function (p) {
let arr = [];
this.list.forEach(p => {
arr.push(p.fullSentence());
});
var s = new Sentences(arr, this, this.world);
let s = new Sentences(arr, this, this.world);

@@ -687,0 +602,0 @@ if (typeof n === 'number') {

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).compromiseSentences=t()}(this,(function(){"use strict";function e(t){return(e=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(t)}function t(e,r){return(t=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,r)}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 n(t){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=e(t);if(n){var a=e(this).constructor;o=Reflect.construct(s,arguments,a)}else o=s.apply(this,arguments);return r(this,o)}}var o={NounPhrase:{notA:["VerbPhrase","AdjectivePhrase"],color:"blue"},VerbPhrase:{notA:["AdjectivePhrase","NounPhrase"],color:"green"},AdjectivePhrase:{notA:["VerbPhrase","NounPhrase"],color:"magenta"},Subordinate:{notA:[]}},s=function(e){e.match("#Noun").tag("NounPhrase"),e.match("#Verb").tag("VerbPhrase"),e.match("(this|that|those|these)").tag("NounPhrase"),e.match("#Adjective+ #NounPhrase").tagSafe("NounPhrase"),e.match("#NounPhrase #Adjective+").tagSafe("NounPhrase"),e.match("#Value #NounPhrase").tag("NounPhrase"),e.match("#Determiner #NounPhrase").tag("NounPhrase"),e.match("#Determiner #Adverb+? #Adjective+ #NounPhrase").tag("NounPhrase"),e.match("(many|most|all|one|some|plenty) of #NounPhrase").tag("NounPhrase"),e.match("such a #NounPhrase").tag("NounPhrase"),e.match("#VerbPhrase #Adverb+").tagSafe("VerbPhrase"),e.match("#Adverb+ #VerbPhrase").tagSafe("VerbPhrase"),e.match("#Auxiliary+ #VerbPhrase").tagSafe("VerbPhrase"),e.match("#VerbPhrase no").tagSafe("VerbPhrase"),e.match("not #VerbPhrase").tagSafe("VerbPhrase"),e.match("#VerbPhrase [that]",0).unTag("NounPhrase"),e.match("#VerbPhrase #Conjunction #VerbPhrase").tagSafe("VerbPhrase"),e.match("(who|what|which)").tag("NounPhrase"),e.match("#Adverb+ #Adjective").tagSafe("AdjectivePhrase"),e.match("#Adjective").tagSafe("AdjectivePhrase"),e.match("#Value").tagSafe("NounPhrase"),e.match("#Date").tagSafe("NounPhrase"),e.match("#Date at #Date").tagSafe("NounPhrase")},a={prepend:function(e){return this.forEach((function(t){var r=t.match("^.");r.not("#ProperNoun").toLowerCase(),r._prepend(e),r.terms(0).toTitleCase()})),this},append:function(e){var t=/[.?!]\s*$/.test(e);return this.forEach((function(r){var n=r.match(".$"),o=n.termList(0),s=o.post;!0===t&&(s=""),n._append(e+s),o.post=" "})),this}},i=function(e){var t=e.clone(!0);return 1===t.length||1===(t=t.if("#Verb")).length||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||1===(t=t.ifNo("(that|which|whichever|who|whoever|whom|whose|whomever)")).length||1===(t=t.ifNo("(despite|during|before|through|throughout)")).length?t:(0===t.length&&(t=e),t.eq(0))},c=function(e){var t=e.clauses(),r=i(t),n=r.match("#Determiner? (#Noun|#Adjective)+").if("#Noun"),o=r.verbs().eq(0);return{subject:n.eq(0),verb:o,object:o.lookAhead(".*")}},u={json:function(e){var t=null;"number"==typeof e&&(t=e,e=null),e=e||{text:!0,normal:!0,trim:!0,terms:!0};var r=[];return this.forEach((function(t){var n=t._json(e)[0],o=c(t);n.subject=o.subject.json(e)[0],n.verb=o.verb.json(e)[0],n.object=o.object.json(e)[0],r.push(n)})),null!==t?r[t]:r}},h={toNegative:function(){return this.forEach((function(e){var t=c(e),r=t.verb.clone();r=r.verbs().toNegative(),t.verb.replaceWith(r,!1)})),this},toPositive:function(){return this.forEach((function(e){var t=c(e),r=t.verb.clone();r=r.verbs().toPositive(),t.verb.replaceWith(r,!1)})),this}},f=function(e){var t=e.post(),r=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")||(!!r.has("^#QuestionWord")||!!r.has("(do|does|is|was) #Noun+ #Adverb? (#Adjective|#Infinitive)$"))))))},b={isQuestion:function(){return this.filter((function(e){return f(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}},l={toPastTense:function(){return this.forEach((function(e){if(!e.has("#PastTense")){var t=c(e),r=t.verb.clone();if(!function(e){return!!e.has("(could|should|would|may|can|must)")}(r)?(r=r.verbs().toPastTense(),t.verb.replaceWith(r,!1)):(r=r.verbs().toParticiple(),t.verb.replaceWith(r,!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=c(e),r=t.verb.clone();if(r=r.verbs().toParticiple(),t.verb.replaceWith(r,!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=c(e),r=t.verb.lookBehind("(i|we) (#Adverb|#Verb)?$").found,n=t.verb.clone();(n=r?n.has("(is|was|am|be)")?n.replace("will? (is|was|am|be)","am"):n.verbs().toInfinitive():n.verbs().toPresentTense(),t.verb.replaceWith(n,!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=c(e),r=t.verb.clone();(r=r.verbs().toFutureTense(),t.verb.replaceWith(r,!1),t.object&&t.object.found&&t.object.has("(#PastTense|#PresentTense)"))&&t.object.verbs().if("(#PastTense|#PresentTense)").verbs().toInfinitive()})),this},subjects:function(){return this.map((function(e){return c(e).subject}))},isPassive:function(){return this.if("was #Adverb? #PastTense #Adverb? by")}},p={phrases:function(){var e=[];return this.forEach((function(t){t=(t=(t=t.splitOn("#VerbPhrase+")).splitOn("#NounPhrase+")).splitOn("#AdjectivePhrase+"),e=e.concat(t.list)})),this.buildFrom(e)}},v=Object.assign({},a,u,h,b,l,p);return function(e,r){r.addTags(o),r.postProcess(s);var a=function(e){!function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),r&&t(e,r)}(o,e);var r=n(o);function o(e,t,n){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),e=e.map((function(e){return e.clone(!0)})),r.call(this,e,t,n)}return o}(e);return v.questions=v.isQuestion,v.exclamations=v.isExclamation,v.statements=v.isStatement,v._prepend=a.prototype.prepend,v._append=a.prototype.append,v._json=a.prototype.json,Object.assign(a.prototype,v),a.prototype.buildFrom=function(e){return e=e.map((function(e){return e.clone(!0)})),new a(e,this,this.world)},a.prototype.toDoc=function(){return e.prototype.buildFrom(this.list)},e.prototype.sentences=function(e){var t=[];this.list.forEach((function(e){t.push(e.fullSentence())}));var r=new a(t,this,this.world);return"number"==typeof e&&(r=r.get(e)),r},e}}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).compromiseSentences=t()}(this,(function(){"use strict";var e={NounPhrase:{notA:["VerbPhrase","AdjectivePhrase"],color:"blue"},VerbPhrase:{notA:["AdjectivePhrase","NounPhrase"],color:"green"},AdjectivePhrase:{notA:["VerbPhrase","NounPhrase"],color:"magenta"},Subordinate:{notA:[]}};var t=function(e){e.match("#Noun").tag("NounPhrase"),e.match("#Verb").tag("VerbPhrase"),e.match("(this|that|those|these)").tag("NounPhrase"),e.match("#Adjective+ #NounPhrase").tagSafe("NounPhrase"),e.match("#NounPhrase #Adjective+").tagSafe("NounPhrase"),e.match("#Value #NounPhrase").tag("NounPhrase"),e.match("#Determiner #NounPhrase").tag("NounPhrase"),e.match("#Determiner #Adverb+? #Adjective+ #NounPhrase").tag("NounPhrase"),e.match("(many|most|all|one|some|plenty) of #NounPhrase").tag("NounPhrase"),e.match("such a #NounPhrase").tag("NounPhrase"),e.match("#VerbPhrase #Adverb+").tagSafe("VerbPhrase"),e.match("#Adverb+ #VerbPhrase").tagSafe("VerbPhrase"),e.match("#Auxiliary+ #VerbPhrase").tagSafe("VerbPhrase"),e.match("#VerbPhrase no").tagSafe("VerbPhrase"),e.match("not #VerbPhrase").tagSafe("VerbPhrase"),e.match("#VerbPhrase [that]",0).unTag("NounPhrase"),e.match("#VerbPhrase #Conjunction #VerbPhrase").tagSafe("VerbPhrase"),e.match("(who|what|which)").tag("NounPhrase"),e.match("#Adverb+ #Adjective").tagSafe("AdjectivePhrase"),e.match("#Adjective").tagSafe("AdjectivePhrase"),e.match("#Value").tagSafe("NounPhrase"),e.match("#Date").tagSafe("NounPhrase"),e.match("#Date at #Date").tagSafe("NounPhrase")},r={prepend:function(e){return this.forEach((t=>{let r=t.match("^.");r.not("#ProperNoun").toLowerCase(),r._prepend(e),r.terms(0).toTitleCase()})),this},append:function(e){let t=/[.?!]\s*$/.test(e);return this.forEach((r=>{let s=r.match(".$"),o=s.termList(0),n=o.post;!0===t&&(n=""),s._append(e+n),o.post=" "})),this}};var s=function(e){let t=e.clone(!0);return 1===t.length?t:(t=t.if("#Verb"),1===t.length?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)"),t=t.ifNo("^even (if|though)"),t=t.ifNo("^so that"),t=t.ifNo("^rather than"),t=t.ifNo("^provided that"),1===t.length?t:(t=t.ifNo("(that|which|whichever|who|whoever|whom|whose|whomever)"),1===t.length?t:(t=t.ifNo("(despite|during|before|through|throughout)"),1===t.length?t:(0===t.length&&(t=e),t.eq(0))))))};var o=function(e){let t=e.clauses(),r=s(t),o=r.match("#Determiner? (#Noun|#Adjective)+").if("#Noun"),n=r.verbs().eq(0);return{subject:o.eq(0),verb:n,object:n.lookAhead(".*")}},n={json:function(e){let t=null;"number"==typeof e&&(t=e,e=null),e=e||{text:!0,normal:!0,trim:!0,terms:!0};let r=[];return this.forEach((t=>{let s=t._json(e)[0],n=o(t);s.subject=n.subject.json(e)[0],s.verb=n.verb.json(e)[0],s.object=n.object.json(e)[0],r.push(s)})),null!==t?r[t]:r}},a={toNegative:function(){return this.forEach((e=>{let t=o(e),r=t.verb.clone();r=r.verbs().toNegative(),t.verb.replaceWith(r,!1)})),this},toPositive:function(){return this.forEach((e=>{let t=o(e),r=t.verb.clone();r=r.verbs().toPositive(),t.verb.replaceWith(r,!1)})),this}};var h=function(e){let t=e.post(),r=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")||(!!r.has("^#QuestionWord")||!!r.has("(do|does|is|was) #Noun+ #Adverb? (#Adjective|#Infinitive)$"))))))},i={isQuestion:function(){return this.filter((e=>h(e)))},isExclamation:function(){return this.filter((e=>e.lastTerm().termList(0).hasPost("!")))},isStatement:function(){return this.filter((e=>{let 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}};var c={toPastTense:function(){return this.forEach((e=>{if(e.has("#PastTense"))return;let t=o(e),r=t.verb.clone();if(!function(e){return!!e.has("(could|should|would|may|can|must)")}(r)?(r=r.verbs().toPastTense(),t.verb.replaceWith(r,!1)):(r=r.verbs().toParticiple(),t.verb.replaceWith(r,!1)),t.object&&t.object.found&&t.object.has("#PresentTense")){let e=t.object.verbs();e=e.filter((e=>!e.lookBehind("to$").found)),e.if("#PresentTense").notIf("#Gerund").verbs().toPastTense()}})),this},toParticiple:function(){return this.forEach((e=>{if(e.has("has #Participle"))return;let t=o(e),r=t.verb.clone();if(r=r.verbs().toParticiple(),t.verb.replaceWith(r,!1),t.object&&t.object.found&&t.object.has("#PresentTense")){t.object.verbs().if("#PresentTense").verbs().toParticiple()}})),this},toPresentTense:function(){return this.forEach((e=>{let t=o(e),r=t.verb.lookBehind("(i|we) (#Adverb|#Verb)?$").found,s=t.verb.clone();if(s=r?s.has("(is|was|am|be)")?s.replace("will? (is|was|am|be)","am"):s.verbs().toInfinitive():s.verbs().toPresentTense(),t.verb.replaceWith(s,!1),t.object&&t.object.found&&t.object.has("#PastTense")){t.object.verbs().if("#PastTense").notIf("#Gerund").verbs().toPresentTense()}})),this},toFutureTense:function(){return this.forEach((e=>{let t=o(e),r=t.verb.clone();if(r=r.verbs().toFutureTense(),t.verb.replaceWith(r,!1),t.object&&t.object.found&&t.object.has("(#PastTense|#PresentTense)")){let e=t.object.verbs();e=e.if("(#PastTense|#PresentTense)").notIf("#Gerund"),e.forEach((e=>{!0===e.lookBehind("(that|which|who|whom)$").found?e.verbs().toPresentTense():e.verbs().toInfinitive()}))}})),this},subjects:function(){return this.map((e=>o(e).subject))},isPassive:function(){return this.if("was #Adverb? #PastTense #Adverb? by")}},u={phrases:function(){let e=[];return this.forEach((t=>{t=(t=(t=t.splitOn("#VerbPhrase+")).splitOn("#NounPhrase+")).splitOn("#AdjectivePhrase+"),e=e.concat(t.list)})),this.buildFrom(e)}};const l=Object.assign({},r,n,a,i,c,u);return function(r,s){s.addTags(e),s.postProcess(t);class o extends r{constructor(e,t,r){super(e=e.map((e=>e.clone(!0))),t,r)}}return l.questions=l.isQuestion,l.exclamations=l.isExclamation,l.statements=l.isStatement,l._prepend=o.prototype.prepend,l._append=o.prototype.append,l._json=o.prototype.json,Object.assign(o.prototype,l),o.prototype.buildFrom=function(e){return e=e.map((e=>e.clone(!0))),new o(e,this,this.world)},o.prototype.toDoc=function(){return r.prototype.buildFrom(this.list)},r.prototype.sentences=function(e){let t=[];this.list.forEach((e=>{t.push(e.fullSentence())}));let r=new o(t,this,this.world);return"number"==typeof e&&(r=r.get(e)),r},r}}));

@@ -0,2 +1,9 @@

### 0.3.0 [April 2020]
- **[change]** - drop ie11 polyfill
- **[change]** - dont compile esm build w/ babel anymore
- **[fix]** - sentence conjugation fixes
### 0.2.0 [Feb 2020]
- update deps, fix peerDependency issue
- update deps, fix peerDependency issue
{
"name": "compromise-sentences",
"description": "plugin for nlp-compromise",
"version": "0.2.0",
"version": "0.3.0",
"author": "Spencer Kelly <spencermountain@gmail.com> (http://spencermounta.in)",

@@ -27,2 +27,7 @@ "main": "./builds/compromise-sentences.js",

},
"browserslist": [
"defaults",
"not IE 11",
"maintained node versions"
],
"files": [

@@ -38,8 +43,7 @@ "builds/",

},
"dependencies": {},
"devDependencies": {
"@rollup/plugin-commonjs": "17.1.0",
"@rollup/plugin-commonjs": "18.0.0",
"@rollup/plugin-json": "4.1.0",
"@rollup/plugin-node-resolve": "11.2.0",
"rollup": "2.40.0",
"@rollup/plugin-node-resolve": "11.2.1",
"rollup": "2.45.2",
"rollup-plugin-babel": "4.4.0",

@@ -49,5 +53,5 @@ "rollup-plugin-filesize-check": "0.0.1",

"tap-dancer": "0.3.1",
"tape": "5.2.0"
"tape": "5.2.2"
},
"license": "MIT"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc