Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| GrammarHy | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
132 | |
0.00% |
0 / 1 |
| process | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
132 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace Wikimedia\Leximorph\Handler\Overrides\Grammar; |
| 8 | |
| 9 | use Wikimedia\Leximorph\Handler\Overrides\IGrammarTransformer; |
| 10 | |
| 11 | /** |
| 12 | * GrammarHy |
| 13 | * |
| 14 | * Implements grammar transformations for Armenian (hy). |
| 15 | * |
| 16 | * These rules don't cover the whole grammar of the language. |
| 17 | * This logic was originally taken from MediaWiki Core. |
| 18 | * Thanks to all contributors. |
| 19 | * |
| 20 | * @since 1.45 |
| 21 | * @author Ruben Vardanyan (Me@RubenVardanyan.com) |
| 22 | * @author Doğu Abaris (abaris@null.net) |
| 23 | * @license https://www.gnu.org/copyleft/gpl.html GPL-2.0-or-later |
| 24 | */ |
| 25 | class GrammarHy implements IGrammarTransformer { |
| 26 | /** |
| 27 | * Applies Armenian-specific grammatical transformations. |
| 28 | * |
| 29 | * @param string $word The word to process. |
| 30 | * @param string $case The grammatical case. |
| 31 | * |
| 32 | * @since 1.45 |
| 33 | * @return string The processed word. |
| 34 | */ |
| 35 | public function process( string $word, string $case ): string { |
| 36 | # These rules are not perfect, but they are currently only used for site names so it doesn't |
| 37 | # matter if they are wrong sometimes. Just add a special case for your site name if necessary. |
| 38 | |
| 39 | # join and array_slice instead mb_substr |
| 40 | $ar = []; |
| 41 | preg_match_all( '/./us', $word, $ar ); |
| 42 | if ( !preg_match( "/[a-zA-Z_]/u", $word ) ) { |
| 43 | switch ( $case ) { |
| 44 | # սեռական հոլով |
| 45 | case 'genitive': |
| 46 | if ( implode( '', array_slice( $ar[0], -1 ) ) == 'ա' ) { |
| 47 | $word = implode( '', array_slice( $ar[0], 0, -1 ) ) . 'այի'; |
| 48 | } elseif ( implode( '', array_slice( $ar[0], -1 ) ) == 'ո' ) { |
| 49 | $word = implode( '', array_slice( $ar[0], 0, -1 ) ) . 'ոյի'; |
| 50 | } elseif ( implode( '', array_slice( $ar[0], -4 ) ) == 'գիրք' ) { |
| 51 | $word = implode( '', array_slice( $ar[0], 0, -4 ) ) . 'գրքի'; |
| 52 | } else { |
| 53 | $word .= 'ի'; |
| 54 | } |
| 55 | break; |
| 56 | # Տրական հոլով |
| 57 | case 'dative': |
| 58 | # stub |
| 59 | break; |
| 60 | # Հայցական հոլով |
| 61 | case 'accusative': |
| 62 | # stub |
| 63 | break; |
| 64 | case 'instrumental': |
| 65 | # stub |
| 66 | break; |
| 67 | case 'prepositional': |
| 68 | # stub |
| 69 | break; |
| 70 | default: |
| 71 | break; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | return $word; |
| 76 | } |
| 77 | } |