diff --git a/app/Http/Controllers/Assoziator.php b/app/Http/Controllers/Assoziator.php index 94db012057cb04913ce56a6eaf794b51db9baa0e..ced17b41809fb845e16223b28ff19854437fc4f6 100644 --- a/app/Http/Controllers/Assoziator.php +++ b/app/Http/Controllers/Assoziator.php @@ -13,7 +13,6 @@ class Assoziator extends Controller return redirect(LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), '/asso')); } - /* $url = "https://metager.de/meta/meta.ger3?eingabe=" . urlencode($eingabe) . "&out=atom10"; $ch = curl_init(); @@ -41,12 +40,9 @@ class Assoziator extends Controller if($responseCode !== 200) abort(500, "Server currently not available"); - */ - $response = file_get_contents(storage_path("app/public/results.xml")); $response = preg_replace("/^<\?.*\?>/s", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", $response); - #die(var_dump($response)); $content = simplexml_load_string($response); $words = []; @@ -85,6 +81,8 @@ class Assoziator extends Controller unset($words[ucfirst($eingabe)]); unset($words["de"]); unset($words["com"]); + unset($words["wiki"]); + unset($words["Wiki"]); // Remove Stopwords $stopWords = file(storage_path('app/public/stopwords.txt')); @@ -96,6 +94,23 @@ class Assoziator extends Controller unset($words[ucfirst($stopWord)]); } + $wordCount = 0; + + $i = 1; + $max = 60; + foreach($words as $key => $value){ + if($i > $max) + unset($words[$key]); + $wordCount += $value; + $i++; + } + + return view('assoziator.asso') + ->with('title', trans('titles.asso')) + ->with('navbarFocus', 'dienste') + ->with('words', $words) + ->with('keywords', $eingabe) + ->with('wordCount', $wordCount); die(var_dump($words)); } diff --git a/resources/views/assoziator/asso.blade.php b/resources/views/assoziator/asso.blade.php index 829b842e3f2c4cc31078ed551274a00b41ee3d2a..c6eefe87743653ced1849cbcead1210e4400b112 100644 --- a/resources/views/assoziator/asso.blade.php +++ b/resources/views/assoziator/asso.blade.php @@ -12,11 +12,38 @@ <div class="card-heavy"> <p>{{ trans('asso.1.1') }} <a href="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), '/') }}" target="_blank">{{ trans('asso.1.2') }}</a>.</p> - <form> + <form method="post"> <div class="input-group"> - <input type="text" class="form-control" placeholder="Zu assoziierender Begriff" name="q" required autofocus/> + <input type="text" class="form-control" placeholder="Zu assoziierender Begriff" @if(isset($keywords)) value="{{$keywords}}" @endif name="q" required autofocus/> <div class="input-group-addon"><button type="submit"><i class="fa fa-search" aria-hidden="true"></i></button></div> </div> </form> </div> + @if(isset($words)) + <div class="card-heavy"> + <div class="table-responsive"> + <table class="table"> + <caption>Assoziationen für "{{ $keywords }}"</caption> + <thead> + <tr> + <th>#</th> + <th>Assoziation</th> + <th>Relevanz</th> + </tr> + </thead> + <tbody> + @php $i = 1; @endphp + @foreach($words as $key => $value) + <tr> + <td>{{ $i }}</td> + <td>{{ $key }}</td> + <td>{{ round(($value / $wordCount) * 100, 2) }}%</td> + @php $i++; @endphp + </tr> + @endforeach + </tbody> + </table> + </div> + </div> + @endif @endsection diff --git a/routes/web.php b/routes/web.php index 4e0b68539f68d1b6d0da6ecc6fc3d33e903aea85..c46f8d084ed169c783497021c67c15fd4275dedd 100644 --- a/routes/web.php +++ b/routes/web.php @@ -20,11 +20,12 @@ Route::group( Route::get('/', 'StartpageController@loadStartPage'); - Route::get('asso', 'Assoziator@asso'/*function(){ + Route::get('asso', function(){ return view('assoziator.asso') ->with('title', trans('titles.asso')) ->with('navbarFocus', 'dienste'); - }*/); + }); + Route::post('asso', 'Assoziator@asso'); Route::get('img/piwik.png', 'ImageController@generateImage');