Skip to content

Commit

Permalink
Remove EngineBase::getLangCodes() as not required
Browse files Browse the repository at this point in the history
Remove the above method as it was not checking for the existence
correctly and anyway was only ever being passed valid model codes.

Also fix a bug in the TranskribusEngine with the HTR ID not being
retrieved correctly.
  • Loading branch information
samwilson authored Dec 6, 2024
1 parent 61af6dc commit 513a873
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 26 deletions.
12 changes: 0 additions & 12 deletions src/Engine/EngineBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,6 @@ public function getModelTitle( ?string $model = null ): string {
return $this->intuition->getLangName( $model ) ?: '';
}

/**
* Transform the given ISO 639-1 codes into the language codes needed by this type of Engine.
* @param string[] $langs
* @return mixed[]
*/
public function getLangCodes( array $langs ): array {
return array_map( function ( $lang ) {
$language = $this->getModelList()[ $lang ];
return isset( $language ) ? $lang : '';
}, $langs );
}

/**
* Set the allowed image hosts.
* @param string $imageHosts
Expand Down
2 changes: 1 addition & 1 deletion src/Engine/GoogleCloudVisionEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getResult(

$imageContext = new ImageContext();
if ( $validLangs ) {
$imageContext->setLanguageHints( $this->getLangCodes( $validLangs ) );
$imageContext->setLanguageHints( $validLangs );
}

if ( !$this->imageAnnotator ) {
Expand Down
2 changes: 1 addition & 1 deletion src/Engine/TesseractEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getResult(
$this->ocr->imageData( $image->getData(), $image->getSize() );

if ( $validLangs ) {
$this->ocr->lang( ...$this->getLangCodes( $validLangs ) );
$this->ocr->lang( ...$validLangs );
}

// Env vars are passed through by the thiagoalessio/tesseract_ocr package to the tesseract command,
Expand Down
9 changes: 5 additions & 4 deletions src/Engine/TranskribusEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,13 @@ public function getResult(
if ( !$validLangs ) {
throw new OcrException( 'transkribus-no-lang-error' );
}
$langCodes = $this->getLangCodes( $validLangs );
if ( count( $langCodes ) > 1 ) {

if ( count( $validLangs ) > 1 ) {
throw new OcrException( 'transkribus-multiple-lang-error' );
}
$htrModelId = (int)$langCodes[0]['htr'];

$modelCode = $validLangs[0];
$modelInfo = $this->getModelList()[$modelCode];
$htrModelId = (int)$modelInfo['htr'];
$processId = $this->transkribusClient->initProcess( $imageUrl, $htrModelId, $this->lineId, $points );

$resText = '';
Expand Down
8 changes: 0 additions & 8 deletions tests/Engine/EngineBaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,6 @@ public function provideLangs(): array {
];
}

/**
* @covers EngineBase::getLangCodes
*/
public function testLangCodes(): void {
static::assertSame( [ 'eng', 'fra' ], $this->tesseractEngine->getLangCodes( [ 'eng', 'fra' ] ) );
static::assertSame( [ 'en', 'iw' ], $this->googleEngine->getLangCodes( [ 'en', 'iw' ] ) );
}

/**
* @covers EngineBase::getModelName
* @covers EngineBase::getValidModels
Expand Down

0 comments on commit 513a873

Please sign in to comment.