Skip to content

Commit

Permalink
updates post-types
Browse files Browse the repository at this point in the history
  • Loading branch information
dhowe committed Dec 13, 2023
1 parent 3f01eb0 commit 007f330
Show file tree
Hide file tree
Showing 29 changed files with 2,004 additions and 593 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
types/*

npnb
dist
misc
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"types": "npx tsc",
"pub": "./npnb/source/cli.js --no-release-draft --test-script test:dist patch",
"prepub": "npm version patch && npm run build && npm run types",
"posttypes": "cp types/rita.d.ts dist"
"_posttypes": "cp types/rita.d.ts dist"
},
"main": "dist/rita.js",
"exports": {
Expand Down
3 changes: 3 additions & 0 deletions src/conjugator.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @memberof module:rita
*/
class RegularExpression {

constructor(regex, offset, suffix) {
Expand Down
1 change: 1 addition & 0 deletions src/markov.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ class RiMarkov {

}

/** @memberof module:rita */
class Node {

constructor(parent, word, count) {
Expand Down
4 changes: 3 additions & 1 deletion src/rita_lts.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class LetterToSound {

////////////////////////////////////////////////////////////////////////////////

/** @memberof module:rita */
class LtsTokenizer {
tokenize(str, delim) {
this.idx = 0;
Expand All @@ -155,6 +156,7 @@ class LtsTokenizer {
}
}

/** @memberof module:rita */
class DecisionState {
constructor(index, c, qtrue, qfalse) {
this.c = c;
Expand All @@ -168,7 +170,7 @@ class DecisionState {
}
DecisionState.TYPE = 1;


/** @memberof module:rita */
class FinalState {

// "epsilon" is used to indicate an empty list.
Expand Down
2 changes: 2 additions & 0 deletions src/stemmer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @memberof module:rita */
class SnowballStemmer {

constructor() {
Expand Down Expand Up @@ -231,6 +232,7 @@ class SnowballStemmer {
}
}

/** @memberof module:rita */
class Among {

constructor(s, substring_i, result) {
Expand Down
2 changes: 1 addition & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class Util {
}
}

// CLASSES ////////////////////////////////////////////////////////////////////
// CLASSES ////////////////////////////////////////////////////

/**
* @class RE
Expand Down
23 changes: 12 additions & 11 deletions test/dist/analyzer-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import { expect } from "chai";
import { RiTa } from "./index.js";
describe("Analyzer", function() {
let hasLex = true;
it("Should call analyze-inline", function() {
let data = RiTa.analyzer.analyze("abandon");
expect(data.phones).eq("ah-b-ae-n-d-ah-n");
expect(data.stresses).eq("0/1/0");
expect(data.syllables).eq("ah/b-ae-n/d-ah-n");
});
it("Should call analyzeWord", function() {
let tmp = RiTa.SILENCE_LTS;
RiTa.SILENCE_LTS = true;
Expand Down Expand Up @@ -97,7 +103,7 @@ describe("Analyzer", function() {
expect(feats.pos).eq("prp vbd dt nn .");
feats = RiTa.analyze("They will be remade into something else.");
feats = RiTa.analyze("She becomes a companion to a foreigner.");
expect(feats.pos).eq("prp vbz dt jj to dt nn .");
expect(feats.pos).eq("prp vbz dt nn to dt nn .");
feats = RiTa.analyze("She has become a companion to a foreigner.");
});
it("Should treat hyphenated words as single tokens", function() {
Expand Down Expand Up @@ -421,6 +427,7 @@ describe("Analyzer", function() {
});
});
it("Should handle number (singular/plural)", function() {
expect(RiTa.inflector.isPlural("dreariness", { dbug: 0 })).eq(true);
expect(RiTa.singularize()).eq("");
expect(RiTa.singularize("")).eq("");
expect(function() {
Expand Down Expand Up @@ -580,7 +587,7 @@ describe("Analyzer", function() {
"menu",
"gurus",
"guru",
"hardnesses",
"hardness",
"hardness",
"fish",
"fish",
Expand Down Expand Up @@ -618,7 +625,7 @@ describe("Analyzer", function() {
"crisis",
"corpora",
"corpus",
"shortnesses",
"shortness",
"shortness",
"dreariness",
"dreariness",
Expand Down Expand Up @@ -828,9 +835,9 @@ describe("Analyzer", function() {
expect(res2).eq(plural, "FAIL2: pluralize(" + singular + ") was " + res2 + ", but expected " + plural + "\n singularize(" + plural + ") was " + res1 + "\n\n");
expect(res3).eq(true, "FAIL3: isPlural(" + plural + ") was false for plural noun\n\n");
let isMass = RiTa.MASS_NOUNS.includes(singular.toLowerCase());
let isModal = singular.endsWith("ness") && !RiTa.MODAL_EXCEPTIONS.includes(singular.toLowerCase());
let isModal = singular.endsWith("ness");
if (!isMass && !isModal) {
expect(res4).eq(false, "FAIL4: isPlural(" + singular + ") was true for singular noun, isMassNoun=" + RiTa.MASS_NOUNS.includes(singular.toLowerCase()) + " isModalException=" + RiTa.MODAL_EXCEPTIONS.includes(singular.toLowerCase()) + "\n\n");
expect(res4).eq(false, "FAIL4: isPlural(" + singular + ") was true for singular noun, isMassNoun=" + RiTa.MASS_NOUNS.includes(singular.toLowerCase()));
}
}
});
Expand All @@ -856,12 +863,6 @@ describe("Analyzer", function() {
it("Should call isPlural", function() {
expect(RiTa.inflector.isPlural()).eq(false);
expect(RiTa.inflector.isPlural("")).eq(false);
expect(function() {
RiTa.inflector.isPlural([1]);
}).to.throw();
expect(function() {
RiTa.inflector.isPlural(1);
}).to.throw();
expect(RiTa.inflector.isPlural("octopus", { dbug: 0 })).eq(false);
expect(RiTa.inflector.isPlural("sheep")).eq(true);
expect(RiTa.inflector.isPlural("apples")).eq(true);
Expand Down
6 changes: 5 additions & 1 deletion test/dist/conjugator-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ describe("Conjugator", function() {
}).to.throw();
expect("swum").eq(RiTa.pastPart("swim"));
expect(RiTa.conjugate("be", { form: RiTa.GERUND })).eq("being");
expect(RiTa.conjugate("are", { number: RiTa.PLURAL, person: RiTa.SECOND, tense: RiTa.PAST })).eq("were");
expect(RiTa.conjugate("are", {
number: RiTa.PLURAL,
person: RiTa.SECOND,
tense: RiTa.PAST
})).eq("were");
s = ["swim", "need", "open"];
a = ["swims", "needs", "opens"];
args = {
Expand Down
3 changes: 3 additions & 0 deletions test/dist/lexicon-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ describe("Lexicon", function() {
this.slow(1e3);
this.timeout(1e4);
it("Should call hasWord", function() {
for (let i = 0; i < 10; i++) {
expect(RiTa.hasWord(RiTa.randomWord())).to.be.true;
}
expect(RiTa.hasWord("random")).to.be.true;
expect(RiTa.hasWord("dog")).to.be.true;
expect(RiTa.hasWord("men")).to.be.true;
Expand Down
4 changes: 4 additions & 0 deletions test/dist/rita-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ describe("Core", () => {
ok(!RiTa.isQuestion(""));
});
it("Should handle articlize", function() {
let tmp = RiTa.SILENCE_LTS;
RiTa.SILENCE_LTS = true;
expect(RiTa.articlize("honor")).eq("an honor");
let data = [
"dog",
"a dog",
Expand All @@ -95,6 +98,7 @@ describe("Core", () => {
for (let i = 0; i < data.length; i += 2) {
expect(RiTa.articlize(data[i])).eq(data[i + 1]);
}
RiTa.SILENCE_LTS = tmp;
});
it("Should handle articlize phrases", function() {
let data = [
Expand Down
99 changes: 37 additions & 62 deletions test/dist/tagger-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ describe("Tagger", () => {
expect(RiTa.pos("Elephants dance".split(/ /), { simple: true })).eql(["n", "v"]);
expect(RiTa.pos("the boy dances".split(/ /), { simple: true })).eql(["-", "n", "v"]);
});
it("Should call pos.array.inline.simple", function() {
it("Should call posInline.array.simple", function() {
let result, answer, txt;
expect(RiTa.pos([], { inline: true, simple: true })).eql("");
expect(RiTa.pos(["asdfaasd"], { inline: true, simple: true })).eql("asdfaasd/n");
result = RiTa.pos(["clothes"], { inline: true, simple: true });
expect(RiTa.posInline([], { simple: true })).eql("");
expect(RiTa.posInline(["asdfaasd"], { simple: true })).eql("asdfaasd/n");
result = RiTa.posInline(["clothes"], { simple: true });
answer = "clothes/n";
expect(result).eql(answer);
result = RiTa.pos(["teeth"], { inline: true, simple: true });
result = RiTa.posInline(["teeth"], { simple: true });
answer = "teeth/n";
expect(result).eql(answer);
result = RiTa.pos("There is a cat".split(/ /), { inline: true, simple: true });
result = RiTa.posInline("There is a cat".split(/ /), { simple: true });
answer = "There/- is/v a/- cat/n";
expect(result).eql(answer);
result = RiTa.pos(RiTa.tokenize("The boy, dressed in red, ate an apple."), { inline: true, simple: true });
result = RiTa.posInline(RiTa.tokenize("The boy, dressed in red, ate an apple."), { simple: true });
answer = "The/- boy/n , dressed/v in/- red/a , ate/v an/- apple/n .";
expect(result).eql(answer);
txt = "The dog ran faster than the other dog. But the other dog was prettier.";
result = RiTa.pos(RiTa.tokenize(txt), { inline: true, simple: true });
result = RiTa.posInline(RiTa.tokenize(txt), { simple: true });
answer = "The/- dog/n ran/v faster/r than/- the/- other/a dog/n . But/- the/- other/a dog/n was/v prettier/a .";
expect(result).eq(answer);
;
Expand Down Expand Up @@ -207,38 +207,6 @@ describe("Tagger", () => {
expect(RiTa.pos("There is a pig")).eql(["ex", "vbz", "dt", "nn"]);
expect(RiTa.pos("There isn't a world that is worth saving")).eql(["ex", "vbz", "dt", "nn", "in", "vbz", "jj", "vbg"]);
});
it("Should call pos.simple", function() {
expect(RiTa.pos("biped", { simple: true })).eql(["n"]);
expect(RiTa.pos("greed", { simple: true })).eql(["n"]);
expect(RiTa.pos("creed", { simple: true })).eql(["n"]);
expect(RiTa.pos("weed", { simple: true })).eql(["n"]);
expect(RiTa.pos("is", { simple: true })).eql(["v"]);
expect(RiTa.pos("am", { simple: true })).eql(["v"]);
expect(RiTa.pos("be", { simple: true })).eql(["v"]);
expect(RiTa.pos("freed", { simple: true })).eql(["a"]);
});
it("Should call pos.inline", function() {
let result, answer, txt;
expect(RiTa.pos("", { inline: true })).eql("");
expect(RiTa.pos("asdfaasd", { inline: true })).eql("asdfaasd/nn");
result = RiTa.pos("clothes", { inline: true });
answer = "clothes/nns";
expect(result).eql(answer);
result = RiTa.pos("teeth", { inline: true });
answer = "teeth/nns";
expect(result).eql(answer);
result = RiTa.pos("There is a cat.", { inline: true });
answer = "There/ex is/vbz a/dt cat/nn .";
expect(result).eql(answer);
result = RiTa.pos("The boy, dressed in red, ate an apple.", { inline: true });
answer = "The/dt boy/nn , dressed/vbn in/in red/jj , ate/vbd an/dt apple/nn .";
expect(result).eql(answer);
txt = "The dog ran faster than the other dog. But the other dog was prettier.";
result = RiTa.pos(txt, { inline: true });
answer = "The/dt dog/nn ran/vbd faster/rbr than/in the/dt other/jj dog/nn . But/cc the/dt other/jj dog/nn was/vbd prettier/jjr .";
expect(result).eq(answer);
;
});
it("Should call posInline", function() {
let result, answer, txt;
expect(RiTa.posInline("")).eql("");
Expand Down Expand Up @@ -314,46 +282,53 @@ describe("Tagger", () => {
expect(result).eq(answer);
;
});
it("Should call pos.inline.simple", function() {
it("Should call pos.simple", function() {
let result, answer, txt;
expect(RiTa.pos("biped", { simple: true })).eql(["n"]);
expect(RiTa.pos("greed", { simple: true })).eql(["n"]);
expect(RiTa.pos("creed", { simple: true })).eql(["n"]);
expect(RiTa.pos("weed", { simple: true })).eql(["n"]);
expect(RiTa.pos("is", { simple: true })).eql(["v"]);
expect(RiTa.pos("am", { simple: true })).eql(["v"]);
expect(RiTa.pos("be", { simple: true })).eql(["v"]);
expect(RiTa.pos("freed", { simple: true })).eql(["a"]);
expect(RiTa.pos("the top seed", { simple: true })).eql(["-", "a", "n"]);
expect(RiTa.pos("", { simple: true })).eql([]);
});
it("Should call posInline.simple", function() {
let result, answer, txt;
expect(RiTa.pos("", { inline: true, simple: true })).eql("");
expect(RiTa.pos("asdfaasd", { inline: true, simple: true })).eql("asdfaasd/n");
result = RiTa.pos("clothes", { inline: true, simple: true });
expect(RiTa.posInline("", { simple: true })).eql("");
expect(RiTa.posInline("asdfaasd", { simple: true })).eql("asdfaasd/n");
result = RiTa.posInline("clothes", { simple: true });
answer = "clothes/n";
expect(result).eql(answer);
result = RiTa.pos("teeth", { inline: true, simple: true });
result = RiTa.posInline("clothes", { simple: true });
answer = "clothes/n";
expect(result).eql(answer);
result = RiTa.posInline("teeth", { simple: true });
answer = "teeth/n";
expect(result).eql(answer);
result = RiTa.pos("There is a cat.", { inline: true, simple: true });
result = RiTa.posInline("There is a cat.", { simple: true });
answer = "There/- is/v a/- cat/n .";
expect(result).eql(answer);
result = RiTa.pos("The boy, dressed in red, ate an apple.", { inline: true, simple: true });
result = RiTa.posInline("The boy, dressed in red, ate an apple.", { simple: true });
answer = "The/- boy/n , dressed/v in/- red/a , ate/v an/- apple/n .";
expect(result).eql(answer);
txt = "The dog ran faster than the other dog. But the other dog was prettier.";
result = RiTa.pos(txt, { inline: true, simple: true });
result = RiTa.posInline(txt, { simple: true });
answer = "The/- dog/n ran/v faster/r than/- the/- other/a dog/n . But/- the/- other/a dog/n was/v prettier/a .";
expect(result).eq(answer);
;
});
it("Should call posInline.simple", function() {
let result, answer, txt;
expect(RiTa.posInline("asdfaasd", { inline: true, simple: true })).eql("asdfaasd/n");
expect(RiTa.posInline("", { inline: true, simple: true })).eql("");
result = RiTa.posInline("clothes", { inline: true, simple: true });
answer = "clothes/n";
expect(result).eql(answer);
result = RiTa.posInline("teeth", { inline: true, simple: true });
result = RiTa.posInline("teeth", { simple: true });
answer = "teeth/n";
expect(result).eql(answer);
result = RiTa.posInline("There is a cat.", { inline: true, simple: true });
result = RiTa.posInline("There is a cat.", { simple: true });
answer = "There/- is/v a/- cat/n .";
expect(result).eql(answer);
result = RiTa.posInline("The boy, dressed in red, ate an apple.", { inline: true, simple: true });
result = RiTa.posInline("The boy, dressed in red, ate an apple.", { simple: true });
answer = "The/- boy/n , dressed/v in/- red/a , ate/v an/- apple/n .";
expect(result).eql(answer);
txt = "The dog ran faster than the other dog. But the other dog was prettier.";
result = RiTa.posInline(txt, { inline: true, simple: true });
result = RiTa.posInline(txt, { simple: true });
answer = "The/- dog/n ran/v faster/r than/- the/- other/a dog/n . But/- the/- other/a dog/n was/v prettier/a .";
expect(result).eq(answer);
;
Expand Down Expand Up @@ -694,7 +669,7 @@ describe("Tagger", () => {
expect(RiTa.tagger.tag(["She", "remade", "this", "video", "."], { inline: true })).eq("She/prp remade/vbd this/dt video/nn .");
expect(RiTa.tagger.tag(["She", "has", "remade", "this", "video", "."], { inline: true })).eq("She/prp has/vbz remade/vbn this/dt video/nn .");
});
it("Should handle hyphenated words in sentence", () => {
it("Should handle hyphenated words", () => {
let pool = [
"He is my father-in-law.",
"We have a off-site meeting yesterday.",
Expand Down
Loading

0 comments on commit 007f330

Please sign in to comment.