-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSangria.php
59 lines (49 loc) · 1.85 KB
/
Sangria.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
58
59
<?php
class Sangria
{
public $pronouns = ["yo", "tu", "él", "nosotros", "vosotros", "ellos"];
public $endings = [["o", "as", "a", "amos", "áis", "an"],
["o", "es", "e", "emos", "éis", "en"],
["o", "es", "e", "imos", "ís", "en"]];
public $irregularVerbs = ["ser" => ["soy", "eres", "es", "somos", "sois", "son"],
"tener" => ["tengo", "tienes", "tiene", "tenemos", "tenéis", "tienen"],
"estar" => ["estoy", "estas", "está", "estamos", "estáis", "estan"]];
public $compositePronouns = ["me", "te", "se", "nos", "os", "se"];
public function isComposite($verb)
{
return substr($verb, -2) === "se";
}
public function decompose($verb)
{
return substr($verb, 0, -2);
}
public function findGroup($verb)
{
$ending = substr($verb, -2);
$endingsByGroup = ["ar", "er", "ir"];
if($ending === "se") {
findGroup(decompose($verb));
} else {
return array_search($ending, $endingsByGroup);
}
}
public function findRoot($verb)
{
return substr($verb, 0, -2);
}
public function conjugate($verb, $pronounIndex)
{
if(array_key_exists($verb, $this->irregularVerbs)) {
return $this->irregularVerbs[$verb][$pronounIndex];
}
if($this->isComposite($verb)) {
$verb = $this->decompose($verb);
$root = $this->findRoot($verb);
$group = $this->findGroup($verb);
return sprintf("%s %s%s", $this->compositePronouns[$pronounIndex], $root, $this->endings[$group][$pronounIndex]);
} else {
$group = $this->findGroup($verb);
return sprintf("%s%s", $this->findRoot($verb), $this->endings[$group][$pronounIndex]);
}
}
}