|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Djunehor\Grammar; |
|
4
|
|
|
|
|
5
|
|
|
class Word |
|
6
|
|
|
{ |
|
7
|
|
|
private $string; |
|
8
|
|
|
|
|
9
|
|
|
private $partsOfSpeech = [ |
|
10
|
|
|
'prep.' => 'Preposition', |
|
11
|
|
|
'n.' => 'Noun', |
|
12
|
|
|
'v.' => 'Verb', |
|
13
|
|
|
'a.' => 'Adjective', |
|
14
|
|
|
'adv.' => 'Adverb', |
|
15
|
|
|
'pron.' => 'Pronoun', |
|
16
|
|
|
'interj.' => 'Interjection', |
|
17
|
|
|
'conj.' => 'Conjunction', |
|
18
|
|
|
]; |
|
19
|
|
|
|
|
20
|
|
|
private $table; |
|
21
|
|
|
|
|
22
|
14 |
|
public function __construct($string = null) |
|
23
|
|
|
{ |
|
24
|
14 |
|
if ($string) { |
|
25
|
|
|
$this->string = $string; |
|
26
|
|
|
} |
|
27
|
14 |
|
$this->table = config('laravel-grammar.table', 'entries'); |
|
28
|
14 |
|
} |
|
29
|
|
|
|
|
30
|
1 |
|
public function getPartsOfSpeech() |
|
31
|
|
|
{ |
|
32
|
1 |
|
return array_values($this->partsOfSpeech); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
11 |
|
public function getWordPartOfSpeech($string) |
|
36
|
|
|
{ |
|
37
|
11 |
|
$this->string = $string; |
|
38
|
11 |
|
$row = \DB::table($this->table)->where('word', ucfirst($this->string))->first(); |
|
39
|
|
|
|
|
40
|
11 |
|
return $row ? json_decode($row->word_type, true) : []; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
11 |
|
public function checkIs($part) |
|
44
|
|
|
{ |
|
45
|
11 |
|
return in_array($part, $this->getWordPartOfSpeech($this->string)); |
|
46
|
|
|
} |
|
47
|
11 |
|
|
|
48
|
|
|
public function isNoun() |
|
49
|
11 |
|
{ |
|
50
|
11 |
|
return $this->checkIs('Noun'); |
|
51
|
11 |
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function isPronoun() |
|
54
|
|
|
{ |
|
55
|
11 |
|
return $this->checkIs('Pronoun'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
9 |
|
public function isAdjective() |
|
59
|
|
|
{ |
|
60
|
9 |
|
return $this->checkIs('Adjective'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
1 |
|
public function isAdverb() |
|
64
|
|
|
{ |
|
65
|
1 |
|
return $this->checkIs('Adverb'); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
1 |
|
public function isPreposition() |
|
69
|
|
|
{ |
|
70
|
1 |
|
return $this->checkIs('Preposition'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
1 |
|
public function isConjunction() |
|
74
|
|
|
{ |
|
75
|
1 |
|
return $this->checkIs('Conjunction'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
1 |
|
public function isInterjection() |
|
79
|
|
|
{ |
|
80
|
1 |
|
return $this->checkIs('Interjection'); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
1 |
|
public function isVerb() |
|
84
|
|
|
{ |
|
85
|
1 |
|
return $this->checkIs('Verb'); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|