Morphos - a morphological decision written completely in PHP.
At the moment the main functionality is declension of personal names in Russian language.
-
Download library through composer:
composer require "wapmorgan/morphos"
-
Create an instance of declension class:
$dec = new morphos\RussianDeclension();
-
Check whether there are forms for this name (need to know a gender)
var_dump($dec->hasForms('Иоанн', morphos\RussianDeclension::MAN))); //true
-
Get one of forms:
var_dump($dec->getForm('Иоанн', morphos\RussianDeclension::DAT_3, morphos\RussianDeclension::MAN)); // Иоанна
-
Get all forms:
var_dump($dec->getForms('Иоанн', morphos\RussianDeclension::MAN));
array(6) { ["nominativus"]=> string(10) "И�оанн" ["genetivus"]=> string(12) "И�оанна" ["dativus"]=> string(12) "И�оанну" ["accusative"]=> string(12) "И�оанна" ["ablativus"]=> string(14) "И�оанном" ["praepositionalis"]=> string(17) "об И�оанне" }
To add a new language simply: create the class inheriting BasicDeclension and realize three abstract methods from BasicDeclension:
-
Checks, whether there are rules for this name.
public function hasForms($name, $gender);
-
Generates all forms of a name.
public function getForms($name, $gender);
-
Generates one form of a name.
public function getForm($name, $form, $gender);
For simple access to functions of string processing there are some functions in morphos
namespace:
set_encoding()
- Sets encoding for using in morphos/* functions.length()
- Calculates count of characters in string.slice()
- Slices string like python.lower()
- Lower case.upper()
- Upper case.name()
- Name case. (ex: Thomas Lewis)
- NOMINATIVE
- GENETIVE
- DATIVE
- ACCUSATIVE
- ABLATIVE
- PREPOSITIONAL
- IMENIT_1
- RODIT_2
- DAT_3
- VINIT_4
- TVORIT_5
- PREDLOJ_6