Skip to content

Commit 42bf379

Browse files
committed
feat(TaskProcessing): Add OCR TaskType
Signed-off-by: Marcel Klehr <[email protected]>
1 parent c0a4098 commit 42bf379

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,7 @@
893893
'OCP\\TaskProcessing\\TaskTypes\\ContextAgentInteraction' => $baseDir . '/lib/public/TaskProcessing/TaskTypes/ContextAgentInteraction.php',
894894
'OCP\\TaskProcessing\\TaskTypes\\ContextWrite' => $baseDir . '/lib/public/TaskProcessing/TaskTypes/ContextWrite.php',
895895
'OCP\\TaskProcessing\\TaskTypes\\GenerateEmoji' => $baseDir . '/lib/public/TaskProcessing/TaskTypes/GenerateEmoji.php',
896+
'OCP\\TaskProcessing\\TaskTypes\\ImageToTextOpticalCharacterRecognition' => $baseDir . '/lib/public/TaskProcessing/TaskTypes/ImageToTextOpticalCharacterRecognition.php',
896897
'OCP\\TaskProcessing\\TaskTypes\\TextToImage' => $baseDir . '/lib/public/TaskProcessing/TaskTypes/TextToImage.php',
897898
'OCP\\TaskProcessing\\TaskTypes\\TextToSpeech' => $baseDir . '/lib/public/TaskProcessing/TaskTypes/TextToSpeech.php',
898899
'OCP\\TaskProcessing\\TaskTypes\\TextToText' => $baseDir . '/lib/public/TaskProcessing/TaskTypes/TextToText.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
934934
'OCP\\TaskProcessing\\TaskTypes\\ContextAgentInteraction' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/TaskTypes/ContextAgentInteraction.php',
935935
'OCP\\TaskProcessing\\TaskTypes\\ContextWrite' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/TaskTypes/ContextWrite.php',
936936
'OCP\\TaskProcessing\\TaskTypes\\GenerateEmoji' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/TaskTypes/GenerateEmoji.php',
937+
'OCP\\TaskProcessing\\TaskTypes\\ImageToTextOpticalCharacterRecognition' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/TaskTypes/ImageToTextOpticalCharacterRecognition.php',
937938
'OCP\\TaskProcessing\\TaskTypes\\TextToImage' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/TaskTypes/TextToImage.php',
938939
'OCP\\TaskProcessing\\TaskTypes\\TextToSpeech' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/TaskTypes/TextToSpeech.php',
939940
'OCP\\TaskProcessing\\TaskTypes\\TextToText' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/TaskTypes/TextToText.php',
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCP\TaskProcessing\TaskTypes;
11+
12+
use OCP\IL10N;
13+
use OCP\L10N\IFactory;
14+
use OCP\TaskProcessing\EShapeType;
15+
use OCP\TaskProcessing\ITaskType;
16+
use OCP\TaskProcessing\ShapeDescriptor;
17+
18+
/**
19+
* This is the task processing task type for OCR
20+
* @since 33.0.0
21+
*/
22+
class ImageToTextOpticalCharacterRecognition implements ITaskType {
23+
/**
24+
* @since 33.0.0
25+
*/
26+
public const ID = 'core:image2text:ocr';
27+
28+
private IL10N $l;
29+
30+
/**
31+
* @param IFactory $l10nFactory
32+
* @since 33.0.0
33+
*/
34+
public function __construct(
35+
IFactory $l10nFactory,
36+
) {
37+
$this->l = $l10nFactory->get('lib');
38+
}
39+
40+
41+
/**
42+
* @inheritDoc
43+
* @since 33.0.0
44+
*/
45+
public function getName(): string {
46+
return $this->l->t('Optical character recognition');
47+
}
48+
49+
/**
50+
* @inheritDoc
51+
* @since 33.0.0
52+
*/
53+
public function getDescription(): string {
54+
return $this->l->t('Extract text from an image');
55+
}
56+
57+
/**
58+
* @return string
59+
* @since 33.0.0
60+
*/
61+
public function getId(): string {
62+
return self::ID;
63+
}
64+
65+
/**
66+
* @return ShapeDescriptor[]
67+
* @since 33.0.0
68+
*/
69+
public function getInputShape(): array {
70+
return [
71+
'input' => new ShapeDescriptor(
72+
$this->l->t('Input Image'),
73+
$this->l->t('The image to extract text from'),
74+
EShapeType::Image
75+
),
76+
];
77+
}
78+
79+
/**
80+
* @return ShapeDescriptor[]
81+
* @since 33.0.0
82+
*/
83+
public function getOutputShape(): array {
84+
return [
85+
'output' => new ShapeDescriptor(
86+
$this->l->t('Output text'),
87+
$this->l->t('The text that was extracted from the image'),
88+
EShapeType::Text
89+
),
90+
];
91+
}
92+
}

0 commit comments

Comments
 (0)