PHP Classes
elePHPant
Icontem

Morphos: Get the different forms of language words

Recommend this page to a friend!
  Info   View files Documentation   View files View files (24)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-01-10 (7 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 193 This week: 10All time: 7,925 This week: 93Up
Version License PHP version Categories
morphos 1.4Free for non-comm...5.4Algorithms, PHP 5, Text processing
Description Author

This class can get the different forms of language words.

It provides several classes that can take words in a given language and determine declension of the word, i.e. the inflection of the word to indicate plurality (singular and plural), gender (male or female), and case (nominative, genitive, dative, accusative, ablative, and prepositional).

Currently it provides specialized classes for Russian declension and English plurality.

Innovation Award
PHP Programming Innovation award nominee
December 2014
Number 2


Prize: One downloadable copy of Komodo IDE
Many words can have multiple forms by changing inflection aspects like the gender, number or the case of those words.

This class implements a solution that can obtain variations of words changing its inflection aspects. It can also detect if a word is a variation of another word.

These capabilities are implemented in a way that can support multiple languages by providing specialization classes for each language.

Manuel Lemos
  Performance   Level  
Name: wapmorgan is available for providing paid consulting. Contact wapmorgan .
Classes: 22 packages by
Country: Russian Federation Russian Federation
Age: ???
All time rank: 102733 in Russian Federation Russian Federation
Week rank: 18 Up1 in Russian Federation Russian Federation Up
Innovation award
Innovation award
Nominee: 8x

Winner: 1x

Details

Morphos

A morphological solution written completely in PHP.

Composer package Latest Stable Version License Total Downloads Latest Unstable Version

Tests & Quality: Build Status Scrutinizer Code Quality Code Coverage

Supported languages:

  • English - pluralization.
  • Russian - pluralization and declension.

Installation

  • Download library through composer: composer require "wapmorgan/morphos"

Declension

Personal names

Declension of personal names in russian language:

  1. Create declension class object: `php $dec = new morphos\RussianNamesDeclension(); `
  2. Check whether there are forms for this name: `php var_dump($dec->hasForms('Иван', morphos\RussianNamesDeclension::MAN)); // true `
  3. Get all forms of a name: `php var_dump($dec->getForms('Иван', morphos\RussianNamesDeclension::MAN)); // array[] {...} `
  4. Get one form of a name: `php var_dump($dec->getForm('Иван', morphos\RussianCases::RODIT_2, morphos\RussianNamesDeclension::MAN)); // Ивана `
  5. All forms for this name: ` array(6) { ["nominativus"]=> string(8) "Иван" ["genetivus"]=> string(10) "Ивана" ["dativus"]=> string(10) "Ивану" ["accusative"]=> string(10) "Ивана" ["ablativus"]=> string(12) "Иваном" ["praepositionalis"]=> string(15) "об Иване" } `

General words

Declension of general words in russian language:

  1. Create declension class object: `php $dec = new morphos\RussianGeneralDeclension(); `
  2. Check whether there are forms for this word (second arg is an animateness): `php var_dump($dec->hasForms('поле', false)); `
  3. Get all forms of a word: `php var_dump($dec->getForms('поле', false)); // array[] {...} `
  4. Get one form of a word: `php var_dump($dec->getForm('поле', false, morphos\RussianCases::RODIT_2)); // поля `
  5. All forms for this word: ` array(6) { ["nominativus"]=> string(8) "поле" ["genetivus"]=> string(8) "поля" ["dativus"]=> string(8) "полю" ["accusative"]=> string(8) "поле" ["ablativus"]=> string(10) "полем" ["praepositionalis"]=> string(8) "поле" } `
  6. Get all forms of a plural word: `php var_dump($dec->pluralizeAllDeclensions('поле', false)); // array[] {...} `
  7. All forms for this plural word: ` array(6) { ["nominativus"]=> string(8) "поля" ["genetivus"]=> string(10) "полей" ["dativus"]=> string(10) "полям" ["accusative"]=> string(8) "поля" ["ablativus"]=> string(12) "полями" ["praepositionalis"]=> string(10) "полях" } `

Declension of general words is very complicated and may fail.

Cases

  1. Cases in russian language:

    * morphos\RussianCases::IMENIT_1 * morphos\RussianCases::RODIT_2 * morphos\RussianCases::DAT_3 * morphos\RussianCases::VINIT_4 * morphos\RussianCases::TVORIT_5 * morphos\RussianCases::PRODLOJ_6

Pluralization

  1. Pluralization a word in Russian: `php $plu = new morphos\RussianPlurality(); $word = 'дом'; $count = 10; echo sprintf("%d %s", $count, $plu->pluralize($word, $count, false)); // last argument - animateness ` prints 10 домов
  2. Pluralization a word in English: `php $plu = new morphos\EnglishPlurality(); $word = 'foot'; $count = 10; echo sprintf("%d %s", $count, $plu->pluralize($word, $count)); ` prints 10 feet

Contributing / Addition of new languages.

Morphos are open for additions and improvements.

Addition a new language is simple: create the class inheriting one of basic classes and realize abstract methods from it.

Here is a list of basic classes:

BasicNamesDeclension

Class for names declension.

  • Checks, whether there are rules for this name. `php abstract public function hasForms($name, $gender); `
  • Generates all forms of a name. `php abstract public function getForms($name, $gender); `
  • Generates one form of a name. `php abstract public function getForm($name, $form, $gender); `

BasicDeclension

  • Checks, whether there are rules for this word. `php public function hasForms($word, $animate = false); `
  • Generates all forms of a word. `php public function getForms($word, $animate = false); `
  • Generates one form of a word. `php public function getForm($word, $form, $animate = false); `

Useful functions in morphos namespace

For simple access to functions of string processing there are some functions in morphos namespace:

  1. set_encoding() - Sets encoding for using in morphos/* functions.
  2. length() - Calculates count of characters in string.
  3. slice() - Slices string like python.
  4. lower() - Lower case.
  5. upper() - Upper case.
  6. name() - Name case. (ex: Thomas Lewis)
  Files folder image Files  
File Role Description
Files folder imagetests (7 files)
Files folder imageweb (1 file)
Plain text file .scrutinizer.yml Data Auxiliary data
Plain text file BasicDeclension.php Class Class source
Plain text file BasicNamesDeclension.php Class Class source
Plain text file BasicPlurality.php Class Class source
Plain text file Cases.php Class Class source
Plain text file composer.json Data Auxiliary data
Plain text file EnglishPlurality.php Class Class source
Plain text file functions.php Aux. Auxiliary script
Plain text file LICENSE.md Lic. License text
Plain text file README.md Doc. Documentation
Plain text file Russian.php Class Class source
Plain text file RussianCases.php Class Class source
Plain text file RussianGeneralDeclension.php Class Class source
Plain text file RussianNamesDeclension.php Class Class source
Plain text file RussianPlurality.php Class Class source
Plain text file test.php Test Unit test script

  Files folder image Files  /  tests  
File Role Description
  Plain text file english_plurality_basic.phpt Data Auxiliary data
  Plain text file russian_general_declension_basic.phpt Data Auxiliary data
  Plain text file russian_names_getforms_basic.phpt Data Auxiliary data
  Plain text file russian_names_getform_advanced.phpt Data Auxiliary data
  Plain text file russian_names_hasforms_basic.phpt Data Auxiliary data
  Plain text file russian_names_hasforms_error.phpt Data Auxiliary data
  Plain text file russian_plularize_basic.phpt Data Auxiliary data

  Files folder image Files  /  web  
File Role Description
  Plain text file index.php Example Application script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:193
This week:10
All time:7,925
This week:93Up