Navigation Menu

Skip to content

Commit

Permalink
Migrate transcriptions shell (script) to CakePHP3
Browse files Browse the repository at this point in the history
`cake transcriptions script sentences`

Refs #1784.
  • Loading branch information
jiru committed Mar 6, 2019
1 parent d58949a commit ac3bd97
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/Shell/TranscriptionsShell.php
Expand Up @@ -34,15 +34,14 @@ public function initialize()
private function detectTranscriptionsFor($data) {
$result = array();
foreach ($data as $row) {
$model = key($row);
$lang = isset($row[$model]['lang']) ?
$row[$model]['lang'] :
$row[$model]['sentence_lang'];
$text = $row[$model]['text'];
$script = $this->Transcription->detectScript($lang, $text);
$lang = isset($row->lang) ?
$row->lang :
$row->sentence_lang;
$text = $row->text;
$script = $this->Transcriptions->detectScript($lang, $text);

$result[] = array(
'id' => $row[$model]['id'],
'id' => $row->id,
'script' => $script,
'modified' => false,
);
Expand Down Expand Up @@ -122,7 +121,7 @@ protected function _setScript($rows, $model) {
);
$entities = $this->{$model}->newEntities($data);
if ($this->{$model}->saveMany($entities, $options))
$proceeded += count($data);
$proceeded += count($entities);
}
$this->out('.', 0);
return $proceeded;
Expand Down
20 changes: 20 additions & 0 deletions tests/TestCase/Shell/TranscriptionsShellTest.php
Expand Up @@ -23,6 +23,7 @@ private function getAutotranscriptionMock() {
->setMethods([
'jpn_Jpan_to_Hrkt_generate',
'jpn_Jpan_to_Hrkt_validate',
'cmn_detectScript',
])
->getMock();
$AT->expects($this->any())
Expand All @@ -31,6 +32,10 @@ private function getAutotranscriptionMock() {
$AT->expects($this->any())
->method('jpn_Jpan_to_Hrkt_validate')
->will($this->returnValue(true));
$AT->expects($this->any())
->method('cmn_detectScript')
->will($this->returnValue('TEST'));

return $AT;
}

Expand Down Expand Up @@ -82,4 +87,19 @@ public function testAutogen_batched()
$this->TS->batchOperationSize = 2;
$this->testAutogen_forAllSentences();
}

public function testSetSentencesScript()
{
$expectedScripts = ['TEST'];

$this->TS->setSentencesScript('cmn');

$scripts = TableRegistry::get('Sentences')
->find('list', ['valueField' => 'script'])
->where(['lang' => 'cmn'])
->toArray();

$scripts = array_keys(array_flip($scripts));
$this->assertEquals($expectedScripts, $scripts);
}
}

0 comments on commit ac3bd97

Please sign in to comment.