Skip to content

Commit

Permalink
cleanup long symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
dhowe committed Nov 28, 2020
1 parent c7eb7bc commit 5f0bcdf
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 82 deletions.
2 changes: 1 addition & 1 deletion src/analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Analyzer {
let stressyls = rawPhones.split(' ');
for (let j = 0; j < stressyls.length; j++) {
if (!stressyls[j].length) continue;
stresses += stressyls[j].includes(RiTa.STRESSED) ? RiTa.STRESSED : RiTa.UNSTRESSED;
stresses += stressyls[j].includes(RiTa.STRESS) ? RiTa.STRESS : RiTa.NOSTRESS;
if (j < stressyls.length - 1) stresses += slash;
}
} else {
Expand Down
44 changes: 22 additions & 22 deletions src/conjugator.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class Conjugator {

reset() {
this.perfect = this.progressive = this.passive = this.interrogative = false;
this.tense = this.RiTa.PRESENT_TENSE;
this.person = this.RiTa.FIRST_PERSON;
this.tense = this.RiTa.PRESENT;
this.person = this.RiTa.FIRST;
this.number = this.RiTa.SINGULAR;
this.form = this.RiTa.NORMAL;
}
Expand Down Expand Up @@ -49,7 +49,7 @@ class Conjugator {
actualModal = "to";
}

if (this.tense === RiTa.FUTURE_TENSE) {
if (this.tense === RiTa.FUTURE) {
actualModal = "will";
}

Expand Down Expand Up @@ -139,31 +139,31 @@ class Conjugator {
switch (numb) {
case RiTa.SINGULAR:
switch (pers) {
case RiTa.FIRST_PERSON: break;
case RiTa.THIRD_PERSON: return "was";
case RiTa.SECOND_PERSON: return "were";
case RiTa.FIRST: break;
case RiTa.THIRD: return "was";
case RiTa.SECOND: return "were";
}
break;
case RiTa.PLURAL:
return "were";
}
}
return this.checkRules(PAST_TENSE_RULESET, theVerb);
return this.checkRules(PAST_RULESET, theVerb);
}

presentTense(theVerb, person, number) {
const RiTa = this.RiTa;
person = person || this.person;
number = number || this.number;
if (person === RiTa.THIRD_PERSON && number === RiTa.SINGULAR) {
return this.checkRules(PRESENT_TENSE_RULESET, theVerb);
if (person === RiTa.THIRD && number === RiTa.SINGULAR) {
return this.checkRules(PRESENT_RULESET, theVerb);
}
else if (theVerb === "be") {
if (number === RiTa.SINGULAR) {
switch (person) {
case RiTa.FIRST_PERSON: return "am";
case RiTa.SECOND_PERSON: return "are";
case RiTa.THIRD_PERSON: return "is";
case RiTa.FIRST: return "am";
case RiTa.SECOND: return "are";
case RiTa.THIRD: return "is";
}
} else {
return "are";
Expand All @@ -183,9 +183,9 @@ class Conjugator {

verbForm(theVerb, tense, person, number) {
switch (tense) {
case this.RiTa.PRESENT_TENSE:
case this.RiTa.PRESENT:
return this.presentTense(theVerb, person, number);
case this.RiTa.PAST_TENSE:
case this.RiTa.PAST:
return this.pastTense(theVerb, person, number);
}
return theVerb;
Expand Down Expand Up @@ -412,7 +412,7 @@ const PAST_PARTICIPLE_RULES = [
RE("^" + VERBAL_PREFIX + "?(cast|thrust|typeset|cut|bid|upset|wet|bet|cut|hit|hurt|inset|let|cost|burst|beat|beset|set|upset|hit|offset|put|quit|" + "wed|typeset|wed|spread|split|slit|read|run|rerun|shut|shed)$", 0)
];

const PAST_TENSE_RULES = [
const PAST_RULES = [
RE("^(reduce)$", 0, "d"),
RE("e$", 0, "d", 1),
RE("^" + VERBAL_PREFIX + "?[pls]ay$", 1, "id", 1),
Expand Down Expand Up @@ -670,7 +670,7 @@ const PAST_TENSE_RULES = [
RE("^" + VERBAL_PREFIX + "?(cast|thrust|typeset|cut|bid|upset|wet|bet|cut|hit|hurt|inset|" + "let|cost|burst|beat|beset|set|upset|offset|put|quit|wed|typeset|" + "wed|spread|split|slit|read|run|shut|shed|lay)$", 0)
];

const PRESENT_TENSE_RULES = [
const PRESENT_RULES = [
RE("^aby$", 0, "es"),
RE("^bog-down$", 5, "s-down"),
RE("^chivy$", 1, "vies"),
Expand Down Expand Up @@ -832,17 +832,17 @@ const PRESENT_PARTICIPLE_RULESET = {
doubling: true
};

const PAST_TENSE_RULESET = {
name: "PAST_TENSE",
const PAST_RULESET = {
name: "PAST",
defaultRule: RE(ANY_STEM_RE, 0, "ed", 2),
rules: PAST_TENSE_RULES,
rules: PAST_RULES,
doubling: true
};

const PRESENT_TENSE_RULESET = {
name: "PRESENT_TENSE",
const PRESENT_RULESET = {
name: "PRESENT",
defaultRule: RE(ANY_STEM_RE, 0, "s", 2),
rules: PRESENT_TENSE_RULES,
rules: PRESENT_RULES,
doubling: false
};

Expand Down
14 changes: 7 additions & 7 deletions src/lexicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ class Lexicon {
case 'vbd':
return RiTa.conjugate(word, {
number: RiTa.SINGULAR,
person: RiTa.FIRST_PERSON,
tense: RiTa.PAST_TENSE
person: RiTa.FIRST,
tense: RiTa.PAST
});
case 'vbg':
return RiTa.presentParticiple(word);
Expand All @@ -336,8 +336,8 @@ class Lexicon {
case 'vbz':
return RiTa.conjugate(word, {
number: RiTa.SINGULAR,
person: RiTa.THIRD_PERSON,
tense: RiTa.PRESENT_TENSE
person: RiTa.THIRD,
tense: RiTa.PRESENT
});
default: throw Error('Unexpected pos: ' + pos);
}
Expand Down Expand Up @@ -382,7 +382,7 @@ class Lexicon {

_firstPhone(rawPhones) {
if (rawPhones && rawPhones.length) {
let phones = rawPhones.split(this.RiTa.PHONEME_BOUNDARY);
let phones = rawPhones.split(this.RiTa.PHONE_BOUNDARY);
if (phones) return phones[0];
}
}
Expand All @@ -395,7 +395,7 @@ class Lexicon {
if (word && word.length) {
let raw = this.rawPhones(word);
if (raw) {
let idx = raw.lastIndexOf(this.RiTa.STRESSED);
let idx = raw.lastIndexOf(this.RiTa.STRESS);
if (idx >= 0) {
let c = raw.charAt(--idx);
while (c != '-' && c != ' ') {
Expand Down Expand Up @@ -430,7 +430,7 @@ class Lexicon {
_firstStressedSyl(word) {
let raw = this.rawPhones(word);
if (raw) {
let idx = raw.indexOf(this.RiTa.STRESSED);
let idx = raw.indexOf(this.RiTa.STRESS);
if (idx >= 0) {
let c = raw.charAt(--idx);
while (c != ' ') {
Expand Down
35 changes: 12 additions & 23 deletions src/rita.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ const Inflector = require('./inflector');
const SeededRandom = require('./random');
const Operator = require('./operator');

/**
* TODO:
* implement pos opt for rhymes/alliterations/soundsLike/spellsLike
* add docs for evaluate and addTransform (link to README#riscript)
*/

class RiTa {

static addTransform() {
Expand Down Expand Up @@ -75,9 +69,9 @@ class RiTa {

static isAbbreviation(input, { caseSensitive = false } = {}) {
if (typeof input === 'string') {
if (caseSensitive) return RiTa.ABBREVIATIONS.includes(input.trim());
if (caseSensitive) return RiTa.ABRV.includes(input.trim());
let check = input.trim().toLowerCase();
return RiTa.ABBREVIATIONS.filter(a => a.toLowerCase() === check).length > 0;
return RiTa.ABRV.filter(a => a.toLowerCase() === check).length > 0;
}
}

Expand Down Expand Up @@ -276,25 +270,23 @@ RiTa.DOWNLOAD_URL = 'https://rednoise.org/rita/downloads';
// CONSTANTS
RiTa.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'];
RiTa.VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'DEV';
RiTa.NODE = 'node';
RiTa.BROWSER = 'browser';
RiTa.FIRST_PERSON = 1;
RiTa.SECOND_PERSON = 2;
RiTa.THIRD_PERSON = 3;
RiTa.PAST_TENSE = 4;
RiTa.PRESENT_TENSE = 5;
RiTa.FUTURE_TENSE = 6;
RiTa.FIRST = 1;
RiTa.SECOND = 2;
RiTa.THIRD = 3;
RiTa.PAST = 4;
RiTa.PRESENT = 5;
RiTa.FUTURE = 6;
RiTa.SINGULAR = 7;
RiTa.PLURAL = 8;
RiTa.NORMAL = 9;
RiTa.STRESSED = '1';
RiTa.UNSTRESSED = '0';
RiTa.PHONEME_BOUNDARY = '-';
RiTa.STRESS = '1';
RiTa.NOSTRESS = '0';
RiTa.PHONE_BOUNDARY = '-';
RiTa.WORD_BOUNDARY = " ";
RiTa.SYLLABLE_BOUNDARY = "/";
RiTa.SENTENCE_BOUNDARY = "|";
RiTa.VOWELS = "aeiou";
RiTa.ABBREVIATIONS = ["Adm.", "Capt.", "Cmdr.", "Col.", "Dr.", "Gen.", "Gov.", "Lt.", "Maj.", "Messrs.", "Mr.", "Mrs.", "Ms.", "Prof.", "Rep.", "Reps.", "Rev.", "Sen.", "Sens.", "Sgt.", "Sr.", "St.", "A.k.a.", "C.f.", "I.e.", "E.g.", "Vs.", "V.", "Jan.", "Feb.", "Mar.", "Apr.", "Mar.", "Jun.", "Jul.", "Aug.", "Sept.", "Oct.", "Nov.", "Dec."];
RiTa.ABRV = ["Adm.", "Capt.", "Cmdr.", "Col.", "Dr.", "Gen.", "Gov.", "Lt.", "Maj.", "Messrs.", "Mr.", "Mrs.", "Ms.", "Prof.", "Rep.", "Reps.", "Rev.", "Sen.", "Sens.", "Sgt.", "Sr.", "St.", "A.k.a.", "C.f.", "I.e.", "E.g.", "Vs.", "V.", "Jan.", "Feb.", "Mar.", "Apr.", "Mar.", "Jun.", "Jul.", "Aug.", "Sept.", "Oct.", "Nov.", "Dec."];
RiTa.QUESTIONS = ["was", "what", "when", "where", "which", "why", "who", "will", "would", "who", "how", "if", "is", "could", "might", "does", "are", "have"];
RiTa.STOP_WORDS = [
"and", "a", "of", "in", "i", "you", "is", "to",
Expand All @@ -317,9 +309,6 @@ RiTa.STOP_WORDS = [
];
RiTa.INFINITIVE = 1;
RiTa.GERUND = 2;
RiTa.IMPERATIVE = 3;
RiTa.BARE_INFINITIVE = 4;
RiTa.SUBJUNCTIVE = 5;

RiTa.FEATURES = ['TOKENS', 'STRESSES', 'PHONES', 'SYLLABLES', 'POS', 'TEXT'];

Expand Down
2 changes: 1 addition & 1 deletion src/tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Tokenizer {
}

let escapeAbbrevs = (text) => {
let abbrevs = this.RiTa.ABBREVIATIONS;
let abbrevs = this.RiTa.ABRV;
for (let i = 0; i < abbrevs.length; i++) {
let abv = abbrevs[i];
let idx = text.indexOf(abv);
Expand Down
Loading

0 comments on commit 5f0bcdf

Please sign in to comment.