rita 3.0.8 → 3.0.13
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.
- package/README.md +3 -3
- package/dist/rita.cjs +41 -106
- package/dist/rita.cjs.map +1 -1
- package/dist/rita.js +32 -95
- package/dist/rita.js.map +1 -1
- package/dist/rita.min.js +90 -90
- package/dist/rita.min.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ RiTa is implemented in JavaScript and Java, with a common [API](https://github.c
|
|
|
10
10
|
* Smart lexicon search for words matching part-of-speech, syllable, stress and rhyme patterns
|
|
11
11
|
* Fast, heuristic algorithms for inflection, conjugation, stemming, tokenization, and more
|
|
12
12
|
* Letter-to-sound engine for feature analysis of arbitrary words (with/without lexicon)
|
|
13
|
-
* Integration of the [RiScript](https://observablehq.com/@dhowe/riscript) scripting language, designed for writers
|
|
13
|
+
* Integration of the [RiScript](https://observablehq.com/@dhowe/riscript) scripting language, designed for writers, now built with the blazing fast [Chevrotain](https://chevrotain.io/) parser
|
|
14
14
|
* New options for generation via grammars and Markov chains
|
|
15
15
|
* Published in ESM, CommonJS and as an IIFE
|
|
16
16
|
|
|
@@ -32,7 +32,7 @@ let data = RiTa.analyze("The elephant took a bite!");
|
|
|
32
32
|
console.log(data);
|
|
33
33
|
|
|
34
34
|
// to load a grammar
|
|
35
|
-
let grammar = RiTa.grammar(
|
|
35
|
+
let grammar = RiTa.grammar(rulesObjectOrJSON);
|
|
36
36
|
console.log(grammar.expand());
|
|
37
37
|
```
|
|
38
38
|
|
|
@@ -158,7 +158,7 @@ Some of the following extensions may also be useful:
|
|
|
158
158
|
|
|
159
159
|
Here you can see the tests in the VSCode _Testing_ view
|
|
160
160
|
|
|
161
|
-
<img width="800" alt="vscode-tests" src="https://
|
|
161
|
+
<img width="800" alt="vscode-tests" src="https://github.com/dhowe/ritajs/assets/737638/103665fb-3dc8-448b-9ed3-d706be6797fc">
|
|
162
162
|
|
|
163
163
|
|
|
164
164
|
|
package/dist/rita.cjs
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => {
|
|
4
4
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
5
|
return value;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
// src/rita.js
|
|
9
|
-
var _riscript = require('riscript'); var _riscript2 = _interopRequireDefault(_riscript);
|
|
10
|
-
|
|
11
8
|
// src/stemmer.js
|
|
12
9
|
var SnowballStemmer = class {
|
|
13
10
|
constructor() {
|
|
@@ -4789,6 +4786,9 @@ var Util = class _Util {
|
|
|
4789
4786
|
static isNum(n) {
|
|
4790
4787
|
return !isNaN(parseFloat(n)) && isFinite(n);
|
|
4791
4788
|
}
|
|
4789
|
+
static numOpt(opts, name, def = 0) {
|
|
4790
|
+
return _Util.isNum(_optionalChain([opts, 'optionalAccess', _ => _[name]])) ? opts[name] : def;
|
|
4791
|
+
}
|
|
4792
4792
|
};
|
|
4793
4793
|
var RE2 = class {
|
|
4794
4794
|
constructor(regex2, offset, suffix) {
|
|
@@ -26971,41 +26971,8 @@ var Lexicon = class {
|
|
|
26971
26971
|
}
|
|
26972
26972
|
return false;
|
|
26973
26973
|
}
|
|
26974
|
-
|
|
26975
|
-
|
|
26976
|
-
let part = word;
|
|
26977
|
-
let dict = this.data;
|
|
26978
|
-
let words = Object.keys(dict);
|
|
26979
|
-
|
|
26980
|
-
while (part.length > 1) {
|
|
26981
|
-
|
|
26982
|
-
let pattern = new RegExp('^' + part);
|
|
26983
|
-
let guess = words.filter(w => pattern.test(w));
|
|
26984
|
-
if (guess && guess.length) {
|
|
26985
|
-
|
|
26986
|
-
// always look for shorter words first
|
|
26987
|
-
guess.sort((a, b) => a.length - b.length);
|
|
26988
|
-
|
|
26989
|
-
// look for words stem(b)===a
|
|
26990
|
-
for (let i = 0; i < guess.length; i++) {
|
|
26991
|
-
if (this.RiTa.stem(guess[i]) === word) {
|
|
26992
|
-
return guess[i];
|
|
26993
|
-
}
|
|
26994
|
-
}
|
|
26995
|
-
}
|
|
26996
|
-
part = part.slice(0, -1);
|
|
26997
|
-
}
|
|
26998
|
-
|
|
26999
|
-
return undefined;
|
|
27000
|
-
}*/
|
|
27001
|
-
async alliterations(theWord, opts = {}) {
|
|
27002
|
-
return new Promise((resolve, reject) => {
|
|
27003
|
-
try {
|
|
27004
|
-
resolve(this.alliterationsSync(theWord, opts));
|
|
27005
|
-
} catch (e) {
|
|
27006
|
-
reject(e);
|
|
27007
|
-
}
|
|
27008
|
-
});
|
|
26974
|
+
async alliterations(word, options = {}) {
|
|
26975
|
+
return this._promise(this.alliterationsSync, [word, options]);
|
|
27009
26976
|
}
|
|
27010
26977
|
alliterationsSync(theWord, opts = {}) {
|
|
27011
26978
|
this._parseArgs(opts);
|
|
@@ -27052,14 +27019,8 @@ var Lexicon = class {
|
|
|
27052
27019
|
}
|
|
27053
27020
|
return result;
|
|
27054
27021
|
}
|
|
27055
|
-
async rhymes(
|
|
27056
|
-
return
|
|
27057
|
-
try {
|
|
27058
|
-
resolve(this.rhymesSync(theWord, opts));
|
|
27059
|
-
} catch (e) {
|
|
27060
|
-
reject(e);
|
|
27061
|
-
}
|
|
27062
|
-
});
|
|
27022
|
+
async rhymes(word, options = {}) {
|
|
27023
|
+
return this._promise(this.rhymesSync, [word, options]);
|
|
27063
27024
|
}
|
|
27064
27025
|
rhymesSync(theWord, opts = {}) {
|
|
27065
27026
|
this._parseArgs(opts);
|
|
@@ -27097,13 +27058,7 @@ var Lexicon = class {
|
|
|
27097
27058
|
return result;
|
|
27098
27059
|
}
|
|
27099
27060
|
async spellsLike(word, options = {}) {
|
|
27100
|
-
return
|
|
27101
|
-
try {
|
|
27102
|
-
resolve(this.spellsLikeSync(word, options));
|
|
27103
|
-
} catch (e) {
|
|
27104
|
-
reject(e);
|
|
27105
|
-
}
|
|
27106
|
-
});
|
|
27061
|
+
return this._promise(this.spellsLikeSync, [word, options]);
|
|
27107
27062
|
}
|
|
27108
27063
|
spellsLikeSync(word, options = {}) {
|
|
27109
27064
|
if (!word || !word.length)
|
|
@@ -27112,13 +27067,7 @@ var Lexicon = class {
|
|
|
27112
27067
|
return this._byTypeSync(word, options);
|
|
27113
27068
|
}
|
|
27114
27069
|
async soundsLike(word, options = {}) {
|
|
27115
|
-
return
|
|
27116
|
-
try {
|
|
27117
|
-
resolve(this.soundsLikeSync(word, options));
|
|
27118
|
-
} catch (e) {
|
|
27119
|
-
reject(e);
|
|
27120
|
-
}
|
|
27121
|
-
});
|
|
27070
|
+
return this._promise(this.soundsLikeSync, [word, options]);
|
|
27122
27071
|
}
|
|
27123
27072
|
soundsLikeSync(word, opts = {}) {
|
|
27124
27073
|
if (!word || !word.length)
|
|
@@ -27137,9 +27086,10 @@ var Lexicon = class {
|
|
|
27137
27086
|
}
|
|
27138
27087
|
}
|
|
27139
27088
|
opts = opts || {};
|
|
27140
|
-
opts.strictPos = true;
|
|
27141
|
-
opts.shuffle = true;
|
|
27142
27089
|
opts.limit = 1;
|
|
27090
|
+
opts.shuffle = true;
|
|
27091
|
+
opts.strictPos = true;
|
|
27092
|
+
opts.minLength = util_default.numOpt(opts, "minLength", 4);
|
|
27143
27093
|
let result = this.searchSync(regex2, opts);
|
|
27144
27094
|
if (result.length < 1 && opts.hasOwnProperty("pos")) {
|
|
27145
27095
|
opts.strictPos = false;
|
|
@@ -27152,13 +27102,7 @@ var Lexicon = class {
|
|
|
27152
27102
|
return result[0];
|
|
27153
27103
|
}
|
|
27154
27104
|
async search(pattern, options) {
|
|
27155
|
-
return
|
|
27156
|
-
try {
|
|
27157
|
-
resolve(this.searchSync(pattern, options));
|
|
27158
|
-
} catch (e) {
|
|
27159
|
-
reject(e);
|
|
27160
|
-
}
|
|
27161
|
-
});
|
|
27105
|
+
return this._promise(this.searchSync, [pattern, options]);
|
|
27162
27106
|
}
|
|
27163
27107
|
searchSync(pattern, options) {
|
|
27164
27108
|
let words = Object.keys(this.data);
|
|
@@ -27209,15 +27153,6 @@ var Lexicon = class {
|
|
|
27209
27153
|
return dict ? Object.keys(dict).length : 0;
|
|
27210
27154
|
}
|
|
27211
27155
|
//////////////////////////// helpers /////////////////////////////////
|
|
27212
|
-
// async similarByType(pattern, options) {
|
|
27213
|
-
// return new Promise((resolve, reject) => {
|
|
27214
|
-
// try {
|
|
27215
|
-
// resolve(this.similarByTypeSync(pattern, options));
|
|
27216
|
-
// } catch (e) {
|
|
27217
|
-
// reject(e);
|
|
27218
|
-
// }
|
|
27219
|
-
// });
|
|
27220
|
-
// }
|
|
27221
27156
|
_byTypeSync(theWord, opts) {
|
|
27222
27157
|
this._parseArgs(opts);
|
|
27223
27158
|
const dict = this.data;
|
|
@@ -27302,14 +27237,13 @@ var Lexicon = class {
|
|
|
27302
27237
|
// Handles: pos, limit, numSyllables, minLength, maxLength
|
|
27303
27238
|
// potentially appends pluralize, conjugate, targetPos
|
|
27304
27239
|
_parseArgs(opts) {
|
|
27305
|
-
opts.limit = opts
|
|
27306
|
-
opts.minDistance = opts
|
|
27307
|
-
opts.numSyllables = opts
|
|
27308
|
-
opts.maxLength = opts
|
|
27309
|
-
opts.minLength = opts
|
|
27310
|
-
if (
|
|
27240
|
+
opts.limit = util_default.numOpt(opts, "limit", 10);
|
|
27241
|
+
opts.minDistance = util_default.numOpt(opts, "minDistance", 1);
|
|
27242
|
+
opts.numSyllables = util_default.numOpt(opts, "numSyllables", 0);
|
|
27243
|
+
opts.maxLength = util_default.numOpt(opts, "maxLength", Number.MAX_SAFE_INTEGER);
|
|
27244
|
+
opts.minLength = util_default.numOpt(opts, "minLength", 3);
|
|
27245
|
+
if (opts.limit < 1)
|
|
27311
27246
|
opts.limit = Number.MAX_SAFE_INTEGER;
|
|
27312
|
-
}
|
|
27313
27247
|
let tpos = opts.pos || false;
|
|
27314
27248
|
if (tpos && tpos.length) {
|
|
27315
27249
|
opts.pluralize = tpos === "nns";
|
|
@@ -27352,13 +27286,7 @@ var Lexicon = class {
|
|
|
27352
27286
|
}
|
|
27353
27287
|
async _bySoundAndLetter(word, opts) {
|
|
27354
27288
|
let types = ["sound", "letter"];
|
|
27355
|
-
let promises = types.map((type) =>
|
|
27356
|
-
try {
|
|
27357
|
-
resolve(this._byTypeSync(word, { ...opts, type }));
|
|
27358
|
-
} catch (e) {
|
|
27359
|
-
reject(e);
|
|
27360
|
-
}
|
|
27361
|
-
}));
|
|
27289
|
+
let promises = types.map((type) => this._promise(this._byTypeSync, [word, { ...opts, type }]));
|
|
27362
27290
|
let results = await Promise.allSettled(promises);
|
|
27363
27291
|
let [bySound, byLetter] = results.map((r) => r.value);
|
|
27364
27292
|
if (bySound.length < 1 || byLetter.length < 1)
|
|
@@ -27407,6 +27335,15 @@ var Lexicon = class {
|
|
|
27407
27335
|
return w.endsWith("ness") || w.endsWith("ism") || pos.indexOf("vbg") > 0 || util_default.MASS_NOUNS.includes(w);
|
|
27408
27336
|
}
|
|
27409
27337
|
// helpers ---------------------------------------------------------------
|
|
27338
|
+
_promise(fun, args) {
|
|
27339
|
+
return new Promise((resolve, reject) => {
|
|
27340
|
+
try {
|
|
27341
|
+
resolve(fun.apply(this, args));
|
|
27342
|
+
} catch (e) {
|
|
27343
|
+
reject(e);
|
|
27344
|
+
}
|
|
27345
|
+
});
|
|
27346
|
+
}
|
|
27410
27347
|
_parseRegex(regex2, opts) {
|
|
27411
27348
|
if (typeof regex2 === "string") {
|
|
27412
27349
|
if (opts && opts.type === "stresses") {
|
|
@@ -42494,25 +42431,26 @@ var MULTI_SP_RE = / +/g;
|
|
|
42494
42431
|
var markov_default = RiMarkov;
|
|
42495
42432
|
|
|
42496
42433
|
// src/rita.js
|
|
42497
|
-
var
|
|
42434
|
+
var _riscript = require('riscript');
|
|
42435
|
+
var { Grammar: RiGrammar } = _riscript.RiScript;
|
|
42498
42436
|
var RiTa2 = class _RiTa {
|
|
42499
42437
|
static grammar(rules, context) {
|
|
42500
42438
|
return new RiGrammar(...arguments);
|
|
42501
42439
|
}
|
|
42502
42440
|
static addTransform(name, definition) {
|
|
42503
|
-
return
|
|
42441
|
+
return _riscript.RiScript.addTransform(...arguments);
|
|
42504
42442
|
}
|
|
42505
42443
|
static removeTransform(name) {
|
|
42506
|
-
return
|
|
42444
|
+
return _riscript.RiScript.removeTransform(...arguments);
|
|
42507
42445
|
}
|
|
42508
42446
|
static getTransforms() {
|
|
42509
|
-
return
|
|
42447
|
+
return _riscript.RiScript.getTransforms();
|
|
42510
42448
|
}
|
|
42511
42449
|
static articlize(word) {
|
|
42512
|
-
return
|
|
42450
|
+
return _riscript.RiScript.articlize(...arguments);
|
|
42513
42451
|
}
|
|
42514
42452
|
static evaluate(script, context, opts) {
|
|
42515
|
-
return
|
|
42453
|
+
return _riscript.RiScript.evaluate(...arguments);
|
|
42516
42454
|
}
|
|
42517
42455
|
static markov(n, opts) {
|
|
42518
42456
|
return new markov_default(...arguments);
|
|
@@ -42685,7 +42623,7 @@ RiTa2.SILENT = false;
|
|
|
42685
42623
|
RiTa2.SILENCE_LTS = false;
|
|
42686
42624
|
RiTa2.CDN = "https://www.unpkg.com/rita/";
|
|
42687
42625
|
RiTa2.PHONES = ["aa", "ae", "ah", "ao", "aw", "ay", "b", "ch", "d", "dh", "eh", "er", "ey", "f", "g", "hh", "ih", "iy", "jh", "k", "l", "m", "n", "ng", "ow", "oy", "p", "r", "s", "sh", "t", "th", "uh", "uw", "v", "w", "y", "z", "zh"];
|
|
42688
|
-
RiTa2.VERSION = "3.0.
|
|
42626
|
+
RiTa2.VERSION = "3.0.13";
|
|
42689
42627
|
RiTa2.HAS_LEXICON = typeof __NOLEX__ === "undefined";
|
|
42690
42628
|
RiTa2.FIRST = 1;
|
|
42691
42629
|
RiTa2.SECOND = 2;
|
|
@@ -42713,12 +42651,9 @@ RiTa2.GERUND = 2;
|
|
|
42713
42651
|
RiTa2.SPLIT_CONTRACTIONS = false;
|
|
42714
42652
|
var ONLY_PUNCT = /^[\p{P}|\+|-|<|>|\^|\$|\ufffd|`]*$/u;
|
|
42715
42653
|
var IS_LETTER = /^[a-z\u00C0-\u00ff]+$/;
|
|
42716
|
-
RiTa2.RiScript =
|
|
42717
|
-
|
|
42718
|
-
var rita_default = RiTa2;
|
|
42719
|
-
|
|
42654
|
+
RiTa2.RiScript = _riscript.RiScript;
|
|
42655
|
+
_riscript.RiScript.RiTa = RiTa2;
|
|
42720
42656
|
|
|
42721
|
-
exports.default = rita_default;
|
|
42722
42657
|
|
|
42723
|
-
|
|
42658
|
+
exports.RiTa = RiTa2;
|
|
42724
42659
|
//# sourceMappingURL=rita.cjs.map
|