Skip to content

h4kbas/trjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Turkish Grammar Library (trjs)

A comprehensive TypeScript library for Turkish grammar and sentence composition. This library provides tools for verb conjugation, noun declension, and Turkish vowel harmony rules.

Features

  • Verb Conjugation: Complete conjugation system for Turkish verbs across all tenses, persons, and moods
  • Noun Declension: Case marking, genitive forms, and pluralization
  • Vowel Harmony: Automatic application of Turkish vowel harmony rules
  • TypeScript Support: Full type definitions and IntelliSense support
  • Comprehensive Testing: Extensive test suite with 92+ test cases

Installation

npm install trjs

Quick Start

import { Verb, Noun, Pronoun, Tense, Type, Polarity, Case } from 'trjs';

// Verb conjugation
const verb = new Verb('gitmek'); // 'to go'
verb.setTense(Tense.Present, Pronoun.Ben, Type.Indicative, Polarity.Affirmative);
console.log(verb.toString()); // "giderim" (I go)

// Noun declension
const noun = new Noun('araba'); // 'car'
noun.case(Case.Dative);
console.log(noun.toString()); // "arabaya" (to the car)

Verb Conjugation

Supported Tenses

  • Present (Tense.Present): Current actions
  • Past (Tense.Past): Completed actions
  • Continuous (Tense.Continuous): Ongoing actions
  • Remote Past (Tense.RPast): Distant past actions
  • Future (Tense.Future): Future actions

Supported Persons

  • Ben (Pronoun.Ben): I
  • Sen (Pronoun.Sen): You (singular)
  • O (Pronoun.O): He/She/It
  • Biz (Pronoun.Biz): We
  • Siz (Pronoun.Siz): You (plural/formal)
  • Onlar (Pronoun.Onlar): They

Supported Moods

  • Indicative (Type.Indicative): Statements
  • Imperative (Type.Imperative): Commands
  • Interrogative (Type.Interrogative): Questions
  • Conditional (Type.Conditional): Conditions

Supported Polarities

  • Affirmative (Polarity.Affirmative): Positive statements
  • Negative (Polarity.Negative): Negative statements

Example: Complete Verb Conjugation

import { Verb, Pronoun, Tense, Type, Polarity } from 'trjs';

const verb = new Verb('gelmek'); // 'to come'

// Present tense
verb.setTense(Tense.Present, Pronoun.Ben, Type.Indicative, Polarity.Affirmative);
console.log(verb.toString()); // "gelirim" (I come)

// Past tense
verb.setTense(Tense.Past, Pronoun.Sen, Type.Indicative, Polarity.Negative);
console.log(verb.toString()); // "gelmedin" (you didn't come)

// Future tense
verb.setTense(Tense.Future, Pronoun.O, Type.Indicative, Polarity.Affirmative);
console.log(verb.toString()); // "gelecek" (he/she/it will come)

// Continuous tense
verb.setTense(Tense.Continuous, Pronoun.Biz, Type.Indicative, Polarity.Negative);
console.log(verb.toString()); // "gelmiyoruz" (we are not coming)

Noun Declension

Supported Cases

  • Accusative (Case.Accusative): Direct object (no suffix)
  • Dative (Case.Dative): Indirect object (to/for)
  • Ablative (Case.Ablative): Source (from)
  • Locative (Case.Locative): Location (in/at/on)

Genitive Forms

Genitive forms indicate possession and are marked with pronouns:

import { Noun, Pronoun } from 'trjs';

const noun = new Noun('araba'); // 'car'

noun.genitive(Pronoun.Ben);
console.log(noun.toString()); // "arabam" (my car)

noun.genitive(Pronoun.Sen);
console.log(noun.toString()); // "araban" (your car)

noun.genitive(Pronoun.O);
console.log(noun.toString()); // "arabası" (his/her/its car)

Pluralization

const noun = new Noun('ev'); // 'house'

noun.plural();
console.log(noun.toString()); // "evler" (houses)

noun.singular();
console.log(noun.toString()); // "ev" (house)

Example: Complex Noun Declension

import { Noun, Pronoun, Case } from 'trjs';

const noun = new Noun('araba'); // 'car'

// Multiple operations
noun.plural();                    // Make plural
noun.genitive(Pronoun.Biz);       // Add genitive (our)
noun.case(Case.Dative);          // Add dative case (to)

console.log(noun.toString()); // "arabalarımıza" (to our cars)

Vowel Harmony

The library automatically applies Turkish vowel harmony rules:

Backness Harmony

  • Front vowels (i, ü, e, ö) → e
  • Back vowels (ı, u, a, o) → a

Flatness Harmony

  • i, e → i
  • ü, ö → ü
  • ı, a → ı
  • u, o → u
import { Word } from 'trjs';

const word = new Word('git'); // 'go'

console.log(word.backnessHarmony());  // "e" (front vowel)
console.log(word.flatnessHarmony());  // "i" (front vowel)

Advanced Features

Word Analysis

import { Word } from 'trjs';

const word = new Word('gelir'); // 'comes/income'

// Vowel and consonant analysis
console.log(word.allVowels());     // ["e", "i"]
console.log(word.allConsonants()); // ["g", "l", "r"]
console.log(word.vowelLength());   // 2
console.log(word.consonantLength()); // 3

// Character classification
console.log(word.isVowel('e'));    // true
console.log(word.isConsonant('g')); // true
console.log(word.isFortis('p'));   // true
console.log(word.isLenis('b'));    // true

Irregular Verbs

The library handles irregular Turkish verbs correctly:

// These verbs have special present tense forms
const gelmek = new Verb('gelmek'); // 'to come'
gelmek.setTense(Tense.Present, Pronoun.Ben, Type.Indicative, Polarity.Affirmative);
console.log(gelmek.toString()); // "gelirim" (not "gelerim")

const korkmak = new Verb('korkmak'); // 'to fear'
korkmak.setTense(Tense.Present, Pronoun.Ben, Type.Indicative, Polarity.Affirmative);
console.log(korkmak.toString()); // "korkarım" (not "korkarım")

API Reference

Verb Class

Constructor

new Verb(infinitive: string)

Methods

  • setTense(tense: Tense, pronoun: Pronoun, mood: Type, polarity: Polarity): void
  • setConjugation(tense: Tense, pronoun: Pronoun, mood: Type, polarity: Polarity): void
  • toString(): string
  • toRoot(): string

Noun Class

Constructor

new Noun(root: string)

Methods

  • case(caseType: Case): void
  • genitive(pronoun: Pronoun): void
  • plural(): void
  • singular(): void
  • toString(): string
  • toRoot(): string

Word Class

Constructor

new Word(root: string)

Methods

  • toString(): string
  • toRoot(): string
  • suffix(suffix: string): void
  • desuffix(suffix: string): void
  • isVowel(char: string): boolean
  • isConsonant(char: string): boolean
  • isFortis(char: string): boolean
  • isLenis(char: string): boolean
  • lastVowel(word?: string): string
  • lastConsonant(word?: string): string
  • firstVowel(word?: string): string
  • firstConsonant(word?: string): string
  • allVowels(word?: string): string[]
  • allConsonants(word?: string): string[]
  • vowelLength(word?: string): number
  • consonantLength(word?: string): number
  • backnessHarmony(word?: string): string
  • flatnessHarmony(word?: string): string

Testing

Run the test suite:

npm test

The library includes comprehensive tests covering:

  • All verb conjugations across tenses, persons, and polarities
  • All noun declensions and cases
  • Vowel harmony rules
  • Edge cases and error handling
  • Irregular verb handling

Examples

See the examples/ directory for more detailed usage examples.

Contributing

Contributions are welcome! Please ensure all tests pass before submitting a pull request.

License

MIT License - see LICENSE file for details.

Changelog

Version 2.0.0

  • Complete rewrite with TypeScript support
  • Fixed all verb conjugation issues
  • Added comprehensive test suite
  • Improved vowel harmony implementation
  • Added irregular verb support
  • Enhanced documentation and examples

About

A library that uses Turkish grammar and composes Turkish sentences

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published