Created
July 21, 2016 10:21
-
-
Save aramis-it/3cd03dda54c28c67063e7392ad7989b0 to your computer and use it in GitHub Desktop.
From http://localhost/spot/members/sources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$this->viewBuilder()->layout('trans'); | |
$source = $this->Sources->newEntity(); | |
if ($this->request->is('post')) { | |
$source->path = md5(Time::now()) . '.srt'; | |
$file = new File($this->request->data['file']['tmp_name']); | |
$file->copy(WWW_ROOT . 'files' . DS . $source->path); | |
$source->title = $this->request->data['title']; | |
$source->user_id = $this->Auth->user('id'); | |
$this->Sources->save($source); | |
$f = "files" . DS . $source->path; | |
$ret = SrtToArrayTool::getArrayByFile($f); // Srt to Array | |
$text = ''; | |
foreach ($ret as $ret) { | |
$text = $text . ' ' . $ret['text']; | |
} | |
$tok = new ClassifierBasedTokenizer( | |
new EndOfSentence(), new WhitespaceTokenizer() | |
); | |
$sentences = $tok->tokenize($text); | |
foreach ($sentences as $sentence) { | |
$DBsentence = $this->Sources->Sentences->newEntity(); | |
$DBsentence->source_id = $source->id; | |
$DBsentence->name = $sentence; | |
$this->Sources->Sentences->save($DBsentence); | |
} | |
$this->set('source', $source); | |
return $this->redirect(['action' => 'index']); | |
} | |
$this->set('source', $source); | |
$this->set('_serialize', ['source']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment