de-compromise 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -251,6 +251,27 @@
251
251
  }, 0)
252
252
  },
253
253
 
254
+ // is the pointer the full sentence?
255
+ isFull: function () {
256
+ let ptrs = this.pointer;
257
+ if (!ptrs) {
258
+ return true
259
+ }
260
+ let document = this.document;
261
+ for (let i = 0; i < ptrs.length; i += 1) {
262
+ let [n, start, end] = ptrs[i];
263
+ // it's not the start
264
+ if (n !== i || start !== 0) {
265
+ return false
266
+ }
267
+ // it's too short
268
+ if (document[n].length > end) {
269
+ return false
270
+ }
271
+ }
272
+ return true
273
+ }
274
+
254
275
  };
255
276
  utils.group = utils.groups;
256
277
  utils.fullSentence = utils.fullSentences;
@@ -391,7 +412,7 @@
391
412
  Object.assign(View.prototype, api$f);
392
413
  var View$1 = View;
393
414
 
394
- var version$1 = '14.6.0';
415
+ var version$1 = '14.7.0';
395
416
 
396
417
  const isObject$6 = function (item) {
397
418
  return item && typeof item === 'object' && !Array.isArray(item)
@@ -1084,6 +1105,9 @@
1084
1105
  // original.freeze()
1085
1106
  let oldTags = (original.docs[0] || []).map(term => Array.from(term.tags));
1086
1107
  // slide this in
1108
+ if (typeof input === 'string') {
1109
+ input = this.fromText(input).compute('id');
1110
+ }
1087
1111
  main.insertAfter(input);
1088
1112
  // are we replacing part of a contraction?
1089
1113
  if (original.has('@hasContraction') && main.contractions) {
@@ -1107,6 +1131,13 @@
1107
1131
  if (keep.case && m.docs[0] && m.docs[0][0] && m.docs[0][0].index[1] === 0) {
1108
1132
  m.docs[0][0].text = titleCase$2(m.docs[0][0].text);
1109
1133
  }
1134
+ // console.log(input.docs[0])
1135
+ // let regs = input.docs[0].map(t => {
1136
+ // return { id: t.id, optional: true }
1137
+ // })
1138
+ // m.after('(a|hoy)').debug()
1139
+ // m.growRight('(a|hoy)').debug()
1140
+ // console.log(m)
1110
1141
  return m
1111
1142
  };
1112
1143
 
@@ -1555,14 +1586,20 @@
1555
1586
  var concat = {
1556
1587
  // add string as new match/sentence
1557
1588
  concat: function (input) {
1558
- const { methods, document, world } = this;
1559
1589
  // parse and splice-in new terms
1560
1590
  if (typeof input === 'string') {
1561
- let json = methods.one.tokenize.fromString(input, world);
1562
- let ptrs = this.fullPointer;
1563
- let lastN = ptrs[ptrs.length - 1][0];
1564
- spliceArr(document, lastN + 1, json);
1565
- return this.compute('index')
1591
+ let more = this.fromText(input);
1592
+ // easy concat
1593
+ if (!this.found || !this.ptrs) {
1594
+ this.document = this.document.concat(more.document);
1595
+ } else {
1596
+ // if we are in the middle, this is actually a splice operation
1597
+ let ptrs = this.fullPointer;
1598
+ let at = ptrs[ptrs.length - 1][0];
1599
+ this.document.splice(at, 0, ...more.document);
1600
+ }
1601
+ // put the docs
1602
+ return this.all().compute('index')
1566
1603
  }
1567
1604
  // plop some view objects together
1568
1605
  if (typeof input === 'object' && input.isView) {
@@ -2195,7 +2232,7 @@
2195
2232
 
2196
2233
  const tokenize$2 = function (phrase, world) {
2197
2234
  const { methods, model } = world;
2198
- let terms = methods.one.tokenize.splitTerms(phrase, model).map(methods.one.tokenize.splitWhitespace);
2235
+ let terms = methods.one.tokenize.splitTerms(phrase, model).map(t => methods.one.tokenize.splitWhitespace(t, model));
2199
2236
  return terms.map(term => term.text.toLowerCase())
2200
2237
  };
2201
2238
 
@@ -3421,6 +3458,10 @@
3421
3458
  if (reg.end === true && index !== length - 1) {
3422
3459
  return false
3423
3460
  }
3461
+ // match an id
3462
+ if (reg.id !== undefined && reg.id === term.id) {
3463
+ return true
3464
+ }
3424
3465
  //support a text match
3425
3466
  if (reg.word !== undefined) {
3426
3467
  // check case-sensitivity, etc
@@ -4127,6 +4168,24 @@
4127
4168
  };
4128
4169
  var getGroup$1 = getGroup;
4129
4170
 
4171
+ const notIf = function (results, not, docs) {
4172
+ results = results.filter(res => {
4173
+ let [n, start, end] = res.pointer;
4174
+ let terms = docs[n].slice(start, end);
4175
+ for (let i = 0; i < terms.length; i += 1) {
4176
+ let slice = terms.slice(i);
4177
+ let found = fromHere(slice, not, i, terms.length);
4178
+ if (found !== null) {
4179
+ return false
4180
+ }
4181
+ }
4182
+ return true
4183
+ });
4184
+ return results
4185
+ };
4186
+
4187
+ var notIf$1 = notIf;
4188
+
4130
4189
  // make proper pointers
4131
4190
  const addSentence = function (res, n) {
4132
4191
  res.pointer[0] = n;
@@ -4202,6 +4261,9 @@
4202
4261
  return docs[n].length === res.pointer[2]
4203
4262
  });
4204
4263
  }
4264
+ if (todo.notIf) {
4265
+ results = notIf$1(results, todo.notIf, docs);
4266
+ }
4205
4267
  // grab the requested group
4206
4268
  results = getGroup$1(results, group);
4207
4269
  // add ids to pointers
@@ -4428,6 +4490,7 @@
4428
4490
  form: 'normal',
4429
4491
  },
4430
4492
  machine: {
4493
+ keepSpace: false,
4431
4494
  whitespace: 'some',
4432
4495
  punctuation: 'some',
4433
4496
  case: 'none',
@@ -4435,6 +4498,7 @@
4435
4498
  form: 'machine',
4436
4499
  },
4437
4500
  root: {
4501
+ keepSpace: false,
4438
4502
  whitespace: 'some',
4439
4503
  punctuation: 'some',
4440
4504
  case: 'some',
@@ -4806,6 +4870,7 @@
4806
4870
  if (starts.hasOwnProperty(t.id)) {
4807
4871
  let { fn, end } = starts[t.id];
4808
4872
  let m = doc.update([[n, i, end]]);
4873
+ text += terms[i].pre || '';
4809
4874
  text += fn(m);
4810
4875
  i = end - 1;
4811
4876
  text += terms[i].post || '';
@@ -4909,7 +4974,11 @@
4909
4974
  /** */
4910
4975
  debug: debug$1,
4911
4976
  /** */
4912
- out: out,
4977
+ out,
4978
+ /** */
4979
+ wrap: function (obj) {
4980
+ return wrap$1(this, obj)
4981
+ },
4913
4982
  };
4914
4983
 
4915
4984
  var out$1 = methods$7;
@@ -4921,26 +4990,30 @@
4921
4990
  var text = {
4922
4991
  /** */
4923
4992
  text: function (fmt) {
4924
- let opts = {
4925
- keepSpace: true,
4926
- keepPunct: true,
4927
- };
4993
+ let opts = {};
4928
4994
  if (fmt && typeof fmt === 'string' && fmts$1.hasOwnProperty(fmt)) {
4929
4995
  opts = Object.assign({}, fmts$1[fmt]);
4930
4996
  } else if (fmt && isObject$1(fmt)) {
4931
- opts = Object.assign({}, opts, fmt);//todo: fixme
4997
+ opts = Object.assign({}, fmt);//todo: fixme
4932
4998
  }
4933
- if (this.pointer) {
4999
+ if (opts.keepSpace === undefined && this.pointer) {
4934
5000
  opts.keepSpace = false;
5001
+ }
5002
+ if (opts.keepPunct === undefined && this.pointer) {
4935
5003
  let ptr = this.pointer[0];
4936
5004
  if (ptr && ptr[1]) {
4937
5005
  opts.keepPunct = false;
4938
5006
  } else {
4939
5007
  opts.keepPunct = true;
4940
5008
  }
4941
- } else {
5009
+ }
5010
+ // set defaults
5011
+ if (opts.keepPunct === undefined) {
4942
5012
  opts.keepPunct = true;
4943
5013
  }
5014
+ if (opts.keepSpace === undefined) {
5015
+ opts.keepSpace = true;
5016
+ }
4944
5017
  return textFromDoc(this.docs, opts)
4945
5018
  },
4946
5019
  };
@@ -5498,6 +5571,9 @@
5498
5571
  if (typeof obj.ifNo === 'string') {
5499
5572
  obj.ifNo = [obj.ifNo];
5500
5573
  }
5574
+ if (obj.notIf) {
5575
+ obj.notIf = parseMatch(obj.notIf, {}, world);
5576
+ }
5501
5577
  // cache any requirements up-front
5502
5578
  obj.needs = getNeeds(obj.regs);
5503
5579
  let { wants, count } = getWants(obj.regs);
@@ -5625,9 +5701,14 @@
5625
5701
  // const no = m.ifNo[k]
5626
5702
  // // quick-check cache
5627
5703
  // if (docCache[n].has(no)) {
5628
- // // console.log(no)
5629
- // if (terms.find(t => t.normal === no || t.tags.has(no))) {
5630
- // // console.log('+' + no)
5704
+ // if (no.startsWith('#')) {
5705
+ // let tag = no.replace(/^#/, '')
5706
+ // if (terms.find(t => t.tags.has(tag))) {
5707
+ // console.log('+' + tag)
5708
+ // return
5709
+ // }
5710
+ // } else if (terms.find(t => t.normal === no || t.tags.has(no))) {
5711
+ // console.log('+' + no)
5631
5712
  // return
5632
5713
  // }
5633
5714
  // }
@@ -6130,6 +6211,7 @@
6130
6211
 
6131
6212
  /** return only the terms that can be this tag */
6132
6213
  canBe: function (tag) {
6214
+ tag = tag.replace(/^#/, '');
6133
6215
  let tagSet = this.model.one.tagSet;
6134
6216
  // everything can be an unknown tag
6135
6217
  if (!tagSet.hasOwnProperty(tag)) {
@@ -6448,6 +6530,10 @@
6448
6530
  }
6449
6531
  const { prefixes, suffixes } = model.one;
6450
6532
 
6533
+ // l-theanine, x-ray
6534
+ if (parts[0].length === 1 && /[a-z]/i.test(parts[0])) {
6535
+ return false
6536
+ }
6451
6537
  //dont split 're-do'
6452
6538
  if (prefixes.hasOwnProperty(parts[0])) {
6453
6539
  return false
@@ -6589,79 +6675,76 @@
6589
6675
  };
6590
6676
  var splitTerms = splitWords;
6591
6677
 
6592
- const allowBefore = [
6593
- '#', //#hastag
6594
- '@', //@atmention
6595
- '_',//underscore
6596
- // '\\-',//-4 (escape)
6597
- '+',//+4
6598
- '.',//.4
6599
- ];
6600
- const allowAfter = [
6601
- '%',//88%
6602
- '_',//underscore
6603
- '°',//degrees, italian ordinal
6604
- // '\'',// \u0027
6605
- ];
6606
-
6607
6678
  //all punctuation marks, from https://en.wikipedia.org/wiki/Punctuation
6608
- let beforeReg = new RegExp(`[${allowBefore.join('')}]+$`, '');
6609
- let afterReg = new RegExp(`^[${allowAfter.join('')}]+`, '');
6610
6679
 
6611
6680
  //we have slightly different rules for start/end - like #hashtags.
6612
- const endings = /[\p{Punctuation}\s]+$/u;
6613
- const startings = /^[\p{Punctuation}\s]+/u;
6614
- const hasApostrophe$1 = /['’]/;
6681
+ const isLetter = /\p{Letter}/u;
6682
+ const isNumber = /[\p{Number}\p{Currency_Symbol}]/u;
6615
6683
  const hasAcronym = /^[a-z]\.([a-z]\.)+/i;
6616
- const shortYear = /^'[0-9]{2}/;
6617
- const isNumber = /^-[0-9]/;
6684
+ const chillin = /[sn]['’]$/;
6618
6685
 
6619
- const normalizePunctuation = function (str) {
6686
+ const normalizePunctuation = function (str, model) {
6687
+ // quick lookup for allowed pre/post punctuation
6688
+ let { prePunctuation, postPunctuation, emoticons } = model.one;
6620
6689
  let original = str;
6621
6690
  let pre = '';
6622
6691
  let post = '';
6623
- // adhoc cleanup for pre
6624
- str = str.replace(startings, found => {
6625
- // punctuation symboles like '@' to allow at start of term
6626
- let m = found.match(beforeReg);
6627
- if (m) {
6628
- pre = found.replace(beforeReg, '');
6629
- return m
6692
+ let chars = Array.from(str);
6693
+
6694
+ // punctuation-only words, like '<3'
6695
+ if (emoticons.hasOwnProperty(str.trim())) {
6696
+ return { str: str.trim(), pre, post: ' ' } //not great
6697
+ }
6698
+
6699
+ // pop any punctuation off of the start
6700
+ let len = chars.length;
6701
+ for (let i = 0; i < len; i += 1) {
6702
+ let c = chars[0];
6703
+ // keep any declared chars
6704
+ if (prePunctuation[c] === true) {
6705
+ continue//keep it
6630
6706
  }
6631
- // support years like '97
6632
- if (pre === `'` && shortYear.test(str)) {
6633
- pre = '';
6634
- return found
6707
+ // keep '+' or '-' only before a number
6708
+ if ((c === '+' || c === '-') && isNumber.test(chars[1])) {
6709
+ break//done
6635
6710
  }
6636
- // support prefix negative signs like '-45'
6637
- if (found === '-' && isNumber.test(str)) {
6638
- return found
6711
+ // '97 - year short-form
6712
+ if (c === "'" && c.length === 3 && isNumber.test(chars[1])) {
6713
+ break//done
6639
6714
  }
6640
- pre = found; //keep it
6641
- return ''
6642
- });
6643
- // ad-hoc cleanup for post
6644
- str = str.replace(endings, found => {
6645
- // punctuation symboles like '@' to allow at start of term
6646
- let m = found.match(afterReg);
6647
- if (m) {
6648
- post = found.replace(afterReg, '');
6649
- return m
6715
+ // start of word
6716
+ if (isLetter.test(c) || isNumber.test(c)) {
6717
+ break //done
6650
6718
  }
6719
+ // punctuation
6720
+ pre += chars.shift();//keep going
6721
+ }
6651
6722
 
6652
- // keep s-apostrophe - "flanders'" or "chillin'"
6653
- if (hasApostrophe$1.test(found) && /[sn]['’]$/.test(original) && hasApostrophe$1.test(pre) === false) {
6654
- post = post.replace(hasApostrophe$1, '');
6655
- return `'`
6723
+ // pop any punctuation off of the end
6724
+ len = chars.length;
6725
+ for (let i = 0; i < len; i += 1) {
6726
+ let c = chars[chars.length - 1];
6727
+ // keep any declared chars
6728
+ if (postPunctuation[c] === true) {
6729
+ continue//keep it
6656
6730
  }
6657
- //keep end-period in acronym
6658
- if (hasAcronym.test(str) === true) {
6659
- post = found.replace(/^\./, '');
6660
- return '.'
6731
+ // start of word
6732
+ if (isLetter.test(c) || isNumber.test(c)) {
6733
+ break //done
6661
6734
  }
6662
- post = found;//keep it
6663
- return ''
6664
- });
6735
+ // F.B.I.
6736
+ if (c === '.' && hasAcronym.test(original) === true) {
6737
+ continue//keep it
6738
+ }
6739
+ // keep s-apostrophe - "flanders'" or "chillin'"
6740
+ if (c === "'" && chillin.test(original) === true) {
6741
+ continue//keep it
6742
+ }
6743
+ // punctuation
6744
+ post = chars.pop() + post;//keep going
6745
+ }
6746
+
6747
+ str = chars.join('');
6665
6748
  //we went too far..
6666
6749
  if (str === '') {
6667
6750
  // do a very mild parse, and hope for the best.
@@ -6676,9 +6759,9 @@
6676
6759
  };
6677
6760
  var tokenize$1 = normalizePunctuation;
6678
6761
 
6679
- const parseTerm = txt => {
6762
+ const parseTerm = (txt, model) => {
6680
6763
  // cleanup any punctuation as whitespace
6681
- let { str, pre, post } = tokenize$1(txt);
6764
+ let { str, pre, post } = tokenize$1(txt, model);
6682
6765
  const parsed = {
6683
6766
  text: str,
6684
6767
  pre: pre,
@@ -6792,7 +6875,7 @@
6792
6875
  input = sentences.map((txt) => {
6793
6876
  let terms = splitTerms(txt, model);
6794
6877
  // split into [pre-text-post]
6795
- terms = terms.map(splitWhitespace);
6878
+ terms = terms.map(t => splitWhitespace(t, model));
6796
6879
  // add normalized term format, always
6797
6880
  terms.forEach((t) => {
6798
6881
  normal(t, world);
@@ -7137,6 +7220,8 @@
7137
7220
  'tri',
7138
7221
  'un',
7139
7222
  'out', //out-lived
7223
+ 'ex',//ex-wife
7224
+
7140
7225
  // 'counter',
7141
7226
  // 'mid',
7142
7227
  // 'out',
@@ -7213,14 +7298,58 @@
7213
7298
  });
7214
7299
  var unicode$3 = unicode$2;
7215
7300
 
7301
+ // https://util.unicode.org/UnicodeJsps/list-unicodeset.jsp?a=%5Cp%7Bpunctuation%7D
7302
+
7303
+ // punctuation to keep at start of word
7304
+ const prePunctuation = {
7305
+ '#': true, //#hastag
7306
+ '@': true, //@atmention
7307
+ '_': true,//underscore
7308
+ '°': true,
7309
+ // '+': true,//+4
7310
+ // '\\-',//-4 (escape)
7311
+ // '.',//.4
7312
+ // zero-width chars
7313
+ '\u200B': true,
7314
+ '\u200C': true,
7315
+ '\u200D': true,
7316
+ '\uFEFF': true
7317
+ };
7318
+
7319
+ // punctuation to keep at end of word
7320
+ const postPunctuation = {
7321
+ '%': true,//88%
7322
+ '_': true,//underscore
7323
+ '°': true,//degrees, italian ordinal
7324
+ // '\'',// sometimes
7325
+ // zero-width chars
7326
+ '\u200B': true,
7327
+ '\u200C': true,
7328
+ '\u200D': true,
7329
+ '\uFEFF': true
7330
+ };
7331
+
7332
+ const emoticons = {
7333
+ '<3': true,
7334
+ '</3': true,
7335
+ '<\\3': true,
7336
+ ':^P': true,
7337
+ ':^p': true,
7338
+ ':^O': true,
7339
+ ':^3': true,
7340
+ };
7341
+
7216
7342
  var model$3 = {
7217
7343
  one: {
7218
7344
  aliases: aliases$1,
7219
7345
  abbreviations,
7220
7346
  prefixes,
7221
7347
  suffixes,
7348
+ prePunctuation,
7349
+ postPunctuation,
7222
7350
  lexicon: lexicon$3, //give this one forward
7223
7351
  unicode: unicode$3,
7352
+ emoticons
7224
7353
  },
7225
7354
  };
7226
7355
 
@@ -7556,6 +7685,8 @@
7556
7685
  nlp$1.extend(lexicon$4); //1kb
7557
7686
  nlp$1.extend(sweep); //1kb
7558
7687
 
7688
+ console.log('local-path');
7689
+
7559
7690
  const prefix$1 = /^.([0-9]+)/;
7560
7691
 
7561
7692
  // handle compressed form of key-value pair
@@ -9958,7 +10089,7 @@
9958
10089
  api: api$1,
9959
10090
  };
9960
10091
 
9961
- var version = '0.0.6';
10092
+ var version = '0.0.7';
9962
10093
 
9963
10094
  nlp$1.plugin(tokenizer);
9964
10095
  nlp$1.plugin(tagset);