A tool to inflect words
npm install inflectrixgit clone https://github.com/V-Volte/inflector
npm install
index.js (or anything else) in the root directory of the project.
latin.json in the examplepatterns directory.
js
const LanguageConstructor = require('./src/core/LanguageConstructor');
const latin = LanguageConstructor.constructLanguageFromJSONFile('./examplepatterns/latin.json');
`
Now, you can inflect any word using the inflectNoun or inflectVerb method of the Language class:
`ts
const augustus = "Augustus";
const amare = "Amāre";
console.log(latin.inflectNoun(augustus, "First Declension", "Plural", "Plural", "Genitive"));
console.log(
latin.inflectVerb(amare, "First Conjugation", "Indicative", "Active", "Present", "Singular", "First")
);
`
Or, you can use the generateMarkdownInflectionTable() method of InflectionClass to generate a Markdown table of all the inflections of a word:
`js
const fs = require('fs');
fs.writeFileSync('inflections.md', latin.getNounInflectionClass("First Declension")?.generateMarkdownInflectionTable(augustus, "Masculine"))
`
Defining a language
Currently, defining a new language and rules in JSON is very tedious and frankly, impossible for a normal human. Even generating this file took me about 15 minutes with Copilot automatically adding the inflection patterns in JavaScript. I'm currently working on a better way to define the rules, probably using a different JSON structure, or maybe something like YAML.
If, however, you have access to Copilot or any other AI that can generate code, you can use the addInflectionPattern function and others of its ilk to create a Language object, and save it by stringifying it into a JSON file. This is how I generated the latin.json file:
`js
const latin = new Language(
"Latin",
["Indicative", "Subjunctive", "Imperative"],
["Present", "Imperfect", "Future", "Perfect", "Pluperfect", "Future Perfect"],
["Singular", "Plural"],
["First", "Second", "Third"],
["Active", "Passive"],
["Masculine", "Feminine", "Neuter"],
["Nominative", "Genitive", "Dative", "Accusative", "Ablative", "Vocative", "Locative"]
);
const firstConjugation = new VerbInflectionClass(
"First Conjugation",
"(.*)(āre)",
latin.moods,
latin.voices,
latin.tenses,
latin.numbers,
latin.persons
);
firstConjugation.addInflectionPattern(
"Indicative",
"Active",
"Present",
"Singular",
"First",
new InflectionPattern(firstConjugation.rootPattern, ["ō"], [1])
);
``