<commit_before><?php
/**
 * Created by IntelliJ IDEA.
 * User: nikolayyotsov
 * Date: 5/21/17
 * Time: 3:40 PM
 */

namespace App\Http\Controllers;

use App\Http\Client\TransltrClient;
use App\Word;
use Illuminate\Http\Request;

class TranslateController extends Controller
{
    /**
     * @var array
     */
    private $validationRules
        = [
            'words' => 'required',
        ];

    /**
     * @param Request $request
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function translate(Request $request)
    {
        $this->validate($request, $this->validationRules);

        $words  = explode(' ', $request->only('words')['words']);

        $meaning = [];
        foreach ($words as $word) {
            $meaning[$word] = TransltrClient::transalte($word, 'en', 'bg')['translationText'];
        }

        return view('welcome', ['translated' => $meaning]);
    }
}<commit_msg>dynamic from/to<commit_after><?php
/**
 * Created by IntelliJ IDEA.
 * User: nikolayyotsov
 * Date: 5/21/17
 * Time: 3:40 PM
 */

namespace App\Http\Controllers;

use App\Http\Client\TransltrClient;
use App\Word;
use Illuminate\Http\Request;

class TranslateController extends Controller
{
    /**
     * @var array
     */
    private $validationRules
        = [
            'words' => 'required',
        ];

    /**
     * @param Request $request
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function translate(Request $request)
    {
        $this->validate($request, $this->validationRules);

        $words  = explode(' ', $request->only('words')['words']);
        $query  = $request->query('from', 'to');

        $from   = $query['from'] ?? 'en';
        $to     = $query['to']  ?? 'bg';

        $meaning = [];
        foreach ($words as $word) {
            $meaning[$word] = TransltrClient::transalte($word, $from, $to)['translationText'];
        }

        return view('welcome', ['translated' => $meaning]);
    }
}
{'fraction_non_alphanumeric': 0.16822429906542055, 'fraction_numerical': 0.007870142646335464, 'mean_word_length': 2.4650766609880748, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2391612', 'n_tokens_mistral': 650, 'n_tokens_neox': 633, 'n_words': 124}