Commit c6b1c595 authored by Martin Gregor's avatar Martin Gregor
Browse files

priprava presentera na generovanie a prekladanie viet

parent 5740171d
<?php
/**
* Homepage presenter.
*/
class AdminPresenter extends BasePresenter
{
public function renderLogin()
{
}
}
<?php
use NlpTools\Stemmers\PorterStemmer;
//use Curl;
/**
* Homepage presenter.
*/
class HomepagePresenter extends BasePresenter
{
public function renderDefault()
{
private $limit = 10;
private $exchange_count = 2;
public function renderDefault()
{
$count = $this->db->table('sentences')->count("*");
$next_sentence_id = (time() % $count) + 1;
$current_sentence_id = $next_sentence_id;
$en_words = [];
$sentences = [];
$sentenceIdSession = $this->getSession('sentenceIdSession');
// inicializacia session
if (!is_array($sentenceIdSession->ids) || count($sentenceIdSession->ids) == $count)
{
$sentenceIdSession->ids = [];
}
while ($current_sentence_id == $next_sentence_id)
// vyhladanie nezobrazenej vety
while (in_array($current_sentence_id,$sentenceIdSession->ids))
{
$current_sentence_id = mt_rand(1, $count);
}
$this->template->sentence = $this->db->table('sentences')->get($current_sentence_id);
$this->template->next_sentence = $this->db->table('sentences')->get($next_sentence_id);
}
// ulozenie id vybranej vety a ziskanie vety z db
$sentenceIdSession->ids[] = $current_sentence_id;
$sentence = $this->db->table('sentences')->get($current_sentence_id);
// rozdelenie vety na slova a inicializacia pola duplicit
$words = explode(' ', $sentence->sentence);
$duplicity = array_fill(0,count($words),0);
// lematizacia skolskou sluzbou
// $curl = new Curl();
//
// $curl->headers = [
// 'Content-Type' => 'text/plain'
// ];
// $result = $curl->post('http://text.fiit.stuba.sk:8080/lematizer/services/lemmatizer/lemmatize/fast','test');
//
// $words = explode(' ',$result->body);
// preklad kazdeho slova z vety
foreach ($words as $word)
{
$en_words[] = $this->translate($word);
}
// nahodny vyber slov z vety na preklad a vytvorenie vety
foreach ($words as $word)
{
$tmp_words = $words;
$counter = 0;
do
{
$position = mt_rand(0,count($words)-1);
$counter++;
} while(($en_words[$position] == null || $duplicity[$position]) && $counter < 30);
if ($counter == 30)
break;
$duplicity[$position] = 1;
$tmp_words[$position] = $en_words[$position]->word;
$sentences[] = implode(' ',$tmp_words);
for ($i = 1; $i < $this->exchange_count; $i++)
{
$next_position = mt_rand(0,count($tmp_words) - $position - 1);
if ($en_words[$position+$next_position] != null)
{
$tmp_words[$position+$next_position] = $en_words[$position+$next_position]->word;
$tmp_sentece = implode(' ',$tmp_words);
if (!in_array($tmp_sentece,$sentences))
{
$sentences[] = $tmp_sentece;
}
}
}
if (count($sentences) == $this->limit)
break;
}
$this->template->sentence = $sentence->sentence;
$this->template->sentences = $sentences;
}
private function translate($word)
{
$word_en = $this->db->query('SELECT dict_en.word as word, dict_en.rank3 as rank, dict_sk_en.type as type'.
' FROM dict_sk_en LEFT JOIN dict_sk ON dict_sk_en.sk_id = dict_sk.id JOIN dict_en ON dict_en.id = dict_sk_en.en_id'.
' WHERE dict_sk.word = ? ORDER BY original_pos',$word)->fetch();
if ($word_en)
return $word_en;
else
return null;
}
}
......@@ -3,6 +3,9 @@
{block content}
<h1 n:block="title">Annotacie správnosti zámeny prekladov slov.</h1>
<hgroup>
<h2>Veta:</h2><h3>{$sentence->sentence}</h3>
<h2>Veta:</h2><h3>{$sentence}</h3>
</hgroup>
<section class="en-sentences" n:foreach="$sentences as $item">
<p>{$item}</p>
</section>
{/block}
\ No newline at end of file
......@@ -3,7 +3,7 @@
"This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
],
"hash": "01381395dab247b727e2aa090a01bc6d",
"hash": "7df9325001eabd15a8789c0b9eb8f0bc",
"packages": [
{
"name": "camspiers/porter-stemmer",
......@@ -190,6 +190,82 @@
"security"
],
"time": "2012-09-08 19:46:36"
},
{
"name": "shuber/curl",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/hamstar/curl.git",
"reference": "6624992df201f9fd7262080117385dd09b0ecd2b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/hamstar/curl/zipball/6624992df201f9fd7262080117385dd09b0ecd2b",
"reference": "6624992df201f9fd7262080117385dd09b0ecd2b",
"shasum": ""
},
"type": "library",
"autoload": {
"files": [
"curl.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "PHP Wrapper for Curl",
"keywords": [
"bot",
"curl",
"scraper",
"spider"
],
"time": "2013-11-23 01:44:31"
},
{
"name": "sunra/php-simple-html-dom-parser",
"version": "v1.5.0",
"source": {
"type": "git",
"url": "https://github.com/sunra/php-simple-html-dom-parser.git",
"reference": "a0b80ace086c7e09085669205e1b3c2c9c7a453c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sunra/php-simple-html-dom-parser/zipball/a0b80ace086c7e09085669205e1b3c2c9c7a453c",
"reference": "a0b80ace086c7e09085669205e1b3c2c9c7a453c",
"shasum": ""
},
"require": {
"php": ">=5.3.2"
},
"type": "library",
"autoload": {
"psr-0": {
"Sunra\\PhpSimple\\HtmlDomParser": "Src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Sunra",
"email": "sunra@yandex.ru",
"homepage": "https://github.com/sunra"
}
],
"description": "Composer adaptation of: A HTML DOM parser written in PHP5+ let you manipulate HTML in a very easy way! Require PHP 5+. Supports invalid HTML. Find tags on an HTML page with selectors just like jQuery. Extract contents from HTML in a single line.",
"homepage": "https://github.com/sunra/php-simple-html-dom-parser",
"keywords": [
"dom",
"html",
"parser"
],
"time": "2013-05-04 14:32:03"
}
],
"packages-dev": [
......@@ -202,7 +278,8 @@
"stability-flags": {
"rych/phpass": 20,
"nlp-tools/nlp-tools": 20,
"camspiers/porter-stemmer": 20
"camspiers/porter-stemmer": 20,
"shuber/curl": 20
},
"platform": {
"php": ">= 5.3.0"
......
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Deny Rule 1" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{URL}" pattern="*" />
</conditions>
<action type="CustomResponse" statusCode="403" statusReason="Forbidden: Access is denied." statusDescription="You do not have permission to view this directory or page using the credentials that you supplied." />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment