-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExperimentsController.php
55 lines (45 loc) · 1.67 KB
/
ExperimentsController.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
<?php
namespace App\Http\Controllers;
use App\SemanticSEO\Experiments\OnlineMeeting;
use App\SemanticSEO\Experiments\Synonymizer;
use Illuminate\Support\Str;
use NoelDeMartin\SemanticSEO\Support\Facades\SemanticSEO;
class ExperimentsController extends Controller
{
public function onlineMeeting()
{
SemanticSEO::meta(trans('seo.online_meeting'));
SemanticSEO::is(OnlineMeeting::class);
return view('experiments.online_meeting');
}
public function synonymizer()
{
SemanticSEO::meta(trans('seo.synonymizer'));
SemanticSEO::is(Synonymizer::class);
return view('experiments.synonymizer');
}
public function synonymizeText()
{
$text = explode(' ', request('text'));
foreach ($text as $key => $word) {
if (strlen($word) > 2) {
$originalWord = trim($word);
$singularWord = Str::singular($originalWord);
$wordData = app('db')->table('thesaurus')->where('word', $singularWord)->first();
if (! is_null($wordData)) {
$meanings = json_decode($wordData->data);
$randomMeaning = $meanings[array_rand($meanings)];
$substitution = $randomMeaning->synonyms[array_rand($randomMeaning->synonyms)];
if (strcmp($originalWord, $singularWord) !== 0) {
$text[$key] = Str::plural($substitution);
} else {
$text[$key] = $substitution;
}
} else {
$text[$key] = $word;
}
}
}
return implode(' ', $text);
}
}