Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jordikroon/Php-Google-Vision-Api
Browse files Browse the repository at this point in the history
  • Loading branch information
jordikroon committed Aug 20, 2018
2 parents 52e20af + 7adfec6 commit 06e456e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
38 changes: 29 additions & 9 deletions src/Hydrator/Strategy/ParagraphsStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,23 @@ public function __construct()
public function extract($value)
{
return array_map(function(Paragraph $paragraphEntity) {
$textProperty = $paragraphEntity->getProperty()
? $this->textPropertyStrategy->extract($paragraphEntity->getProperty())
: null;

$boundingBox = $paragraphEntity->getBoundingBox()
? $this->boundingPolyStrategy->extract($paragraphEntity->getBoundingBox())
: null;

$words = $paragraphEntity->getWords()
? $this->wordsStrategy->extract($paragraphEntity->getWords())
: null;


return array_filter([
'property' => $this->textPropertyStrategy->extract($paragraphEntity->getProperty()),
'boundingBox' => $this->boundingPolyStrategy->extract($paragraphEntity->getBoundingBox()),
'words' => $this->wordsStrategy->extract($paragraphEntity->getWords()),
'property' => $textProperty,
'boundingBox' => $boundingBox,
'words' => $words,
]);
}, $value);
}
Expand All @@ -51,13 +64,20 @@ public function extract($value)
public function hydrate($value)
{
$paragraphEntities = [];

foreach ($value as $paragraphEntityInfo) {
$paragraphEntities[] = new Paragraph(
$this->textPropertyStrategy->hydrate($paragraphEntityInfo['property']),
$this->boundingPolyStrategy->hydrate($paragraphEntityInfo['boundingBox']),
$this->wordsStrategy->hydrate($paragraphEntityInfo['words'])
);
$textProperty = isset($paragraphEntityInfo['property'])
? $this->textPropertyStrategy->hydrate($paragraphEntityInfo['property'])
: null;

$boundingBox = isset($paragraphEntityInfo['boundingBox'])
? $this->boundingPolyStrategy->hydrate($paragraphEntityInfo['boundingBox'])
: null;

$words = isset($paragraphEntityInfo['words'])
? $this->wordsStrategy->hydrate($paragraphEntityInfo['words'])
: null;

$paragraphEntities[] = new Paragraph($textProperty, $boundingBox, $words);
}

return $paragraphEntities;
Expand Down
28 changes: 21 additions & 7 deletions src/Hydrator/Strategy/SymbolsStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace Vision\Hydrator\Strategy;

use Vision\Annotation\Paragraph;
use Vision\Annotation\Symbol;
use Vision\Annotation\Word;
use Zend\Hydrator\Strategy\StrategyInterface;

class SymbolsStrategy implements StrategyInterface
Expand Down Expand Up @@ -32,9 +30,17 @@ public function __construct()
public function extract($value)
{
return array_map(function(Symbol $symbolEntity) {
$textProperty = $symbolEntity->getProperty()
? $this->textPropertyStrategy->extract($symbolEntity->getProperty())
: null;

$boundingBox = $symbolEntity->getBoundingBox()
? $this->boundingPolyStrategy->extract($symbolEntity->getBoundingBox())
: null;

return array_filter([
'property' => $this->textPropertyStrategy->extract($symbolEntity->getProperty()),
'boundingBox' => $this->boundingPolyStrategy->extract($symbolEntity->getBoundingBox()),
'property' => $textProperty,
'boundingBox' => $boundingBox,
'text' => $symbolEntity->getText(),
]);
}, $value);
Expand All @@ -49,10 +55,18 @@ public function hydrate($value)
$symbolEntities = [];

foreach ($value as $symbolEntityInfo) {
$textProperty = isset($symbolEntityInfo['property'])
? $this->textPropertyStrategy->hydrate($symbolEntityInfo['property'])
: null;

$boundingBox = isset($symbolEntityInfo['boundingBox'])
? $this->boundingPolyStrategy->hydrate($symbolEntityInfo['boundingBox'])
: null;

$symbolEntities[] = new Symbol(
$this->textPropertyStrategy->hydrate($symbolEntityInfo['property']),
$this->boundingPolyStrategy->hydrate($symbolEntityInfo['boundingBox']),
$symbolEntityInfo['text']
$textProperty,
$boundingBox,
isset($symbolEntityInfo['text']) ? $symbolEntityInfo['text'] : null
);
}

Expand Down

1 comment on commit 06e456e

@vodickavaclav
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to be done also in WordsStrategy.php

Please sign in to comment.