6 releases (breaking)

0.5.1 Aug 9, 2019
0.5.0 Jun 29, 2019
0.4.0 Mar 16, 2019
0.3.0 Dec 29, 2018
0.1.0 Dec 11, 2018

#784 in Text processing


Used in sententiae

MIT license

175KB
2.5K SLoC

Verba

Verba is a library for working with Latin words. This library aims to handle a majority of the grammatical work, such as declining nouns and adjectives and conjugating verbs, for individual Latin words.

Nouns

Latin nouns decline for grammatical number and case. The noun module contains submodules for creating regular, irregular, and indeclinable nouns. Each type implements the Noun trait, which has a decline function that takes a grammatical number and case.

For example, to create the regular first declension noun porta, portae you would call verba::Regular::new("porta".to_string(), "portae".to_string());.

To decline the genitive plural you would call noun.decline(Number::Plural, Case::Genitive);.

Irregular nouns are created using a HashMap<(Number, Case), Option<Vec<String>>> that contains overrides for cases where the noun declines irregularly. For example, to create the irregular noun vīs, vīs you first create the HashMap of overrides:

overrides.insert((Number::Singular, Case::Nominative), Some(vec!["vīs".to_string()]));
overrides.insert((Number::Singular, Case::Genitive), Some(vec!["vīs".to_string()]));
overrides.insert((Number::Singular, Case::Dative), Some(vec!["".to_string()]));
overrides.insert((Number::Singular, Case::Accusative), Some(vec!["vim".to_string()]));
overrides.insert((Number::Singular, Case::Ablative), Some(vec!["".to_string()]));
overrides.insert((Number::Singular, Case::Vocative), Some(vec!["vīs".to_string()]));
overrides.insert((Number::Plural, Case::Genitive), Some(vec!["vīrium".to_string()]));
overrides.insert((Number::Plural, Case::Accusative), Some(vec!["vīrēs".to_string(), "vīrīs".to_string()]));

This HashMap overrides all six singular cases and the plural genitive and accusative cases. The remaining cases; the plural nominative, dative, accusative and vocative; will decline as regular nouns. To accomplish this, the verba::noun::Irregular::new function also requires passing in a stem and a declension group. To create the irregular noun call verba::Irregular::new(declension, Gender::Feminine, "vīr".to_string(), Group::Third).

Calling the decline function will provide the irregular forms when called with a number and cases that appears in the passed in HashMap, otherwise it will use the passed in stem and declension group to decline it as a regular noun. For example, noun.decline(Number::Singular, Case::Genitive) will return Some(vec!["vīs.to_string()]) and calling noun.decline(Number::Plural, Case::Dative), which is not in the overrides HashMap, will return Some(vec!["vīribus".to_string()])).

Indeclinable nouns don't change form when declined. To create the indeclinable noun nīl you would call verba::Indeclinable::new("nīl".to_string(), Gender::Neuter).

Calling its decline will returne nīl regardless of the number and case passed to it.

Adjectives

Latin adjectives decline for grammatical number, case, and gender. The adjective module currently contains only a submodule for creating regular adjectives.

The dictionary form of Latin adjectives can take several forms. For adjectives of the first and second declension group the masculine, feminine, and neuter forms are provided. To create and adjective you first need to create a dictionary form, then you pass that dictionary form into the new function:

let dictionary = A::DictionaryForm::Three("altus".to_string(), "alta".to_string(), "altum".to_string());

let adjective;
match A::Regular::new(dictionary) {
    Ok(a) => adjective = a,
    Err(_) => panic!("Failed to create a regular adjective.");
}

To get the singular genitive feminine form you would call adjective.decline(Number::Singular, Case::Genitive, Gender::Feminine), which would return Some(vec!["altae".to_string()]).

Verbs

Latin verbs conjugate for mood, voice, tense, number, and person. The verb module currently contains only a submodule for creating regular verbs.

To create the regular verb laudō, laudāre, laudāvī, laudātum would would call verba::Regular::new("laudō".to_string(), "laudāre".to_string(), "laudāre".to_string(), "laudāvī".to_string()).

To get the first person plural present active indicative form of the verb you would call verb.conjugate(V::Person::First, V::Number::Plural, V::Tense::Present, V::Voice::Active, V::Mood::Indicative), which would return Conjugation::Complete(vec!["laudāmus".to_string()]).

The conjugate function returns a Conjugate enum, which can either be Complete, which indicates the the stored forms are the completed forms, or a PassivePerfect. The passive perfect forms of Latin verbs take the form of an adjective form along with a declined form of sum. A PassivePerfect contains a reference to a verb's adjective form and the appropriate form of sum.

To complete the declension the adjective form must be declined for number, case, and gender. For example, calling conjugation.decline(Number::Singular, Case::Nominative, Gender::Masculine) would return the fully conjugated form for the singular, nominative, masculine form of the adjective form along with the accompanying form of sum.

Dependencies

~7.5MB
~155K SLoC