-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParts.php
57 lines (55 loc) · 1.32 KB
/
Parts.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* @package go\ewp
*/
namespace go\ewp;
/**
* Definition of parts of speech
*
* @author Oleg Grigoriev <go.vasac@gmail.com>
*/
class Parts
{
/**
* Define part of speech
*
* @param string $word
* @return object
* [remain, part, accus, plural]
*/
public static function define($word, $ap = false)
{
$result = (object)[
'remain' => $word,
'part' => null,
];
$pattern = '^(.+?)(o|a|e|i|is|as|os|us|u)';
if ($ap) {
$result->accus = false;
$result->plural = false;
$pattern .= '(n|j|nj|jn)?';
}
$pattern = '/'.$pattern.'$/is';
if (!\preg_match($pattern, $word, $matches)) {
return $result;
}
$result->remain = $matches[1];
$result->part = $matches[2];
if (isset($matches[3])) {
switch ($matches[3]) {
case 'n':
$result->accus = true;
break;
case 'j':
$result->plural = true;
break;
case 'nj':
case 'jn':
$result->accus = true;
$result->plural = true;
break;
}
}
return $result;
}
}