Skip to content

Commit

Permalink
Restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
wapmorgan committed Jan 28, 2017
1 parent 97de456 commit 7ab7e8c
Show file tree
Hide file tree
Showing 32 changed files with 1,098 additions and 1,208 deletions.
6 changes: 0 additions & 6 deletions BasicPlurality.php

This file was deleted.

55 changes: 55 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Contribution

`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 abstract classes:

#### `morphos\NamesDeclensions`
Class for names declension.

* ```php
abstract public function hasForms($name, $gender);
```
Checks, whether there are rules for this name.

* ```php
abstract public function getForms($name, $gender);
```
Generates all forms of a name.

* ```php
abstract public function getForm($name, $form, $gender);
```
Generates one form of a name.

#### `morphos\GeneralDeclension`

* ```php
public function hasForms($word, $animate = false);
```
Checks, whether there are rules for this word.

* ```php
public function getForms($word, $animate = false);
```
Generates all forms of a word.

* ```php
public function getForm($word, $form, $animate = false);
```
Generates one form of a word.

### Useful functions

For simple access to string processing Morphos creates few functions in global 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)
7. `chars_count()` - Count of few chars.
8. `last_position_for_one_of_chars()` - Finds last position for one of chars.
180 changes: 74 additions & 106 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,51 @@ A morphological solution written completely in PHP.
Tests & Quality: [![Build Status](https://travis-ci.org/wapmorgan/Morphos.svg)](https://travis-ci.org/wapmorgan/Morphos)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/wapmorgan/Morphos/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/wapmorgan/Morphos/?branch=master)

Supported languages:

* English - pluralization.
* Russian - pluralization and declension.
1. Installation
2. Russian
3. English
4. Contributing / Addition of new languages

# Installation

* Download library through composer:
`composer require "wapmorgan/morphos"`

# Declension
# Russian

Russian morphology:

```php
morphos\
Russian\
Cases
FirstNamesDeclension
LastNamesDeclension
GeneralDeclension
Plurality
```

## Russian
## Declension

### First names
### First names (`FirstNamesDeclension`)
Declension of first names in russian language:

1. Create declension class object:
```php
use morphos\RussianCases;
use morphos\RussianNamesDeclension;
use morphos\Russian\Cases;
use morphos\Russian\FirstNamesDeclension;

$dec = new RussianNamesDeclension();
$dec = new FirstNamesDeclension();
```

2. Check whether there are forms for this name:
```php
var_dump($dec->hasForms('Иван', RussianNamesDeclension::MAN)); // true
var_dump($dec->hasForms('Иван', FirstNamesDeclension::MAN)); // true
```

3. Get all forms of a name:
```php
var_dump($dec->getForms('Иван', RussianNamesDeclension::MAN));
var_dump($dec->getForms('Иван', FirstNamesDeclension::MAN));
/* Will produce something like
array(6) {
["nominativus"]=>
Expand All @@ -63,28 +75,28 @@ Declension of first names in russian language:

4. Get one form of a name:
```php
var_dump($dec->getForm('Иван', RussianCases::RODIT, RussianNamesDeclension::MAN)); // Ивана
var_dump($dec->getForm('Иван', Cases::RODIT, FirstNamesDeclension::MAN)); // Ивана
```

### Last names
### Last names (`LastNamesDeclension`)
Declension of last names in russian language:

1. Create declension class object:
```php
use morphos\RussianCases;
use morphos\RussianLastNamesDeclension;
use morphos\Russian\Cases;
use morphos\Russian\LastNamesDeclension;

$dec = new RussianLastNamesDeclension();
$dec = new LastNamesDeclension();
```

2. Check whether there are forms for this name:
```php
var_dump($dec->hasForms('Иванов', RussianNamesDeclension::MAN)); // true
var_dump($dec->hasForms('Иванов', LastNamesDeclension::MAN)); // true
```

3. Get all forms of a name:
```php
var_dump($dec->getForms('Иван', RussianNamesDeclension::MAN));
var_dump($dec->getForms('Иванов', LastNamesDeclension::MAN));
/* Will produce something like
array(6) {
["nominativus"]=>
Expand All @@ -105,18 +117,18 @@ Declension of last names in russian language:

4. Get one form of a name:
```php
var_dump($dec->getForm('Иванов', RussianCases::RODIT, RussianNamesDeclension::MAN)); // Иванова
var_dump($dec->getForm('Иванов', Cases::RODIT, LastNamesDeclension::MAN)); // Иванова
```

### General words
### General words (`GeneralDeclension`)
Declension of general words in russian language:

1. Create declension class object:
```php
use morphos\RussianCases;
use morphos\RussianGeneralDeclension;
use morphos\Russian\Cases;
use morphos\Russian\GeneralDeclension;

$dec = new RussianGeneralDeclension();
$dec = new GeneralDeclension();
```

2. Check whether there are forms for this word (second arg is an animateness):
Expand Down Expand Up @@ -147,7 +159,7 @@ Declension of general words in russian language:

4. Get one form of a word:
```php
var_dump($dec->getForm('поле', false, RussianCases::RODIT)); // поля
var_dump($dec->getForm('поле', false, Cases::RODIT)); // поля
```

5. Get all forms of a plural word:
Expand All @@ -171,97 +183,53 @@ Declension of general words in russian language:
*/
```

**Declension of general words is very complicated and may fail.**

### Cases

1. Cases in russian language:

* morphos\RussianCases::IMENIT
* morphos\RussianCases::RODIT
* morphos\RussianCases::DAT
* morphos\RussianCases::VINIT
* morphos\RussianCases::TVORIT
* morphos\RussianCases::PRODLOJ


# Pluralization

1. Pluralization a word in Russian:
```php
use morphos\RussianPlurality;

$plu = new RussianPlurality();
$word = 'дом';
$count = 10;

echo $count.' '.$plu->pluralize($word, $count, false));
// result: 10 домов
```

2. Pluralization a word in English:

```php
use morphos\EnglishPlurality;

$plu = new EnglishPlurality();
$word = 'foot';
$count = 10;
echo $count.' '.$plu->pluralize($word, $count));
// result: 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.
### Cases (`Cases`)

Here is a list of basic classes:
Cases in russian language:

#### BasicNamesDeclension
* morphos\Russian\Cases::IMENIT
* morphos\Russian\Cases::RODIT
* morphos\Russian\Cases::DAT
* morphos\Russian\Cases::VINIT
* morphos\Russian\Cases::TVORIT
* morphos\Russian\Cases::PRODLOJ

Class for names declension.
### Pluralization (`Plurality`)
Pluralization a word in Russian:

* Checks, whether there are rules for this name.
```php
abstract public function hasForms($name, $gender);
```
```php
use morphos\Russian\Plurality;

* Generates all forms of a name.
```php
abstract public function getForms($name, $gender);
```
$plu = new Plurality();
$word = 'дом';
$count = 10;

* Generates one form of a name.
```php
abstract public function getForm($name, $form, $gender);
```
echo $count.' '.$plu->pluralize($word, $count, false));
// result: 10 домов
```

#### BasicDeclension
# English

* Checks, whether there are rules for this word.
```php
public function hasForms($word, $animate = false);
```
English morphology:
```php
morphos\
English\
Plurality
```

* Generates all forms of a word.
```php
public function getForms($word, $animate = false);
```
## Pluralization
Pluralization a word in English:

* Generates one form of a word.
```php
public function getForm($word, $form, $animate = false);
```
```php
use morphos\English\Plurality;

### Useful functions in morphos namespace
$plu = new Plurality();
$word = 'foot';
$count = 10;
echo $count.' '.$plu->pluralize($word, $count));
// result: 10 feet
```

For simple access to functions of string processing there are some functions in `morphos` namespace:
## Contributing / Addition of new languages

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)
See [CONTRIBUTING.md](CONTRIBUTING.md) for this.
19 changes: 0 additions & 19 deletions RussianPlurality.php

This file was deleted.

10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"name": "wapmorgan/morphos",
"description": "Morphological solution",
"license": "MIT",
"keywords": ["language", "morphology", "russian"],
"suggest": {
"ext-mbstring": "Support cyrillic transformations."
"keywords": ["language", "morphology", "russian", "english", "pluralization", "declension"],
"require": {
"ext-mbstring": "*"
},
"autoload": {
"files": ["functions.php"],
"files": ["src/functions.php"],
"psr-4": {
"morphos\\": ""
"morphos\\": "src/"
}
},
"require-dev": {
Expand Down
22 changes: 11 additions & 11 deletions Cases.php → src/Cases.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
namespace morphos;

interface Cases {
const NOMINATIVE = 'nominativus';
const GENETIVE = 'genetivus';
const DATIVE = 'dativus';
const ACCUSATIVE = 'accusative';
const ABLATIVE = 'ablativus';
const PREPOSITIONAL = 'praepositionalis';
}
<?php
namespace morphos;

interface Cases {
const NOMINATIVE = 'nominativus';
const GENETIVE = 'genetivus';
const DATIVE = 'dativus';
const ACCUSATIVE = 'accusative';
const ABLATIVE = 'ablativus';
const PREPOSITIONAL = 'praepositionalis';
}
Loading

0 comments on commit 7ab7e8c

Please sign in to comment.