Skip to content

Commit a1779d5

Browse files
committed
Merge branch 'develop'
2 parents 8dcb3cf + af9a730 commit a1779d5

File tree

153 files changed

+3824
-1514
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+3824
-1514
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"symfony/console": "^5",
3333
"ext-curl": "*",
3434
"ext-pcntl": "*",
35-
"ext-json": "*",
3635
"ext-libxml": "*",
3736
"ext-dom": "*",
3837
"ext-pdo": "*",

docker

internal_scripts

lib/Controller/API/App/Authentication/LaraAuthController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ function () use ($chunkValidator) {
6767
}
6868
)->onSuccess(
6969
function () use ($chunkValidator) {
70-
(new IsOwnerInternalUserValidator($this, $chunkValidator->getChunk()))->validate();
70+
$reasoning = (bool)filter_var($this->getParams()['reasoning'], FILTER_VALIDATE_BOOLEAN);
71+
if($reasoning){
72+
(new IsOwnerInternalUserValidator($this, $chunkValidator->getChunk()))->validate();
73+
}
7174
}
7275
)
7376
);

lib/Controller/API/App/CreateProjectController.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Utils\Constants\Constants;
2929
use Utils\Constants\ProjectStatus;
3030
use Utils\Engines\EnginesFactory;
31+
use Utils\Engines\Lara;
3132
use Utils\Engines\Validators\Contracts\EngineValidatorObject;
3233
use Utils\Engines\Validators\DeepLEngineOptionsValidator;
3334
use Utils\Engines\Validators\DeeplFormalityValidator;
@@ -262,6 +263,7 @@ private function validateTheRequest(): array
262263
$intento_provider = filter_var($this->request->param('intento_provider'), FILTER_SANITIZE_SPECIAL_CHARS, ['flags' => FILTER_FLAG_STRIP_LOW]);
263264
$intento_routing = filter_var($this->request->param('intento_routing'), FILTER_SANITIZE_SPECIAL_CHARS, ['flags' => FILTER_FLAG_STRIP_LOW]);
264265
$lara_glossaries = filter_var($this->request->param('lara_glossaries'), FILTER_SANITIZE_SPECIAL_CHARS, ['flags' => FILTER_FLAG_STRIP_LOW]);
266+
$lara_style = filter_var($this->request->param('lara_style'), FILTER_SANITIZE_SPECIAL_CHARS, ['flags' => FILTER_FLAG_STRIP_LOW]);
265267
$deepl_id_glossary = filter_var($this->request->param('deepl_id_glossary'), FILTER_SANITIZE_SPECIAL_CHARS, ['flags' => FILTER_FLAG_STRIP_LOW]);
266268
$deepl_formality = filter_var($this->request->param('deepl_formality'), FILTER_SANITIZE_SPECIAL_CHARS, ['flags' => FILTER_FLAG_STRIP_LOW]);
267269
$deepl_engine_type = filter_var($this->request->param('deepl_engine_type'), FILTER_SANITIZE_SPECIAL_CHARS, ['flags' => FILTER_FLAG_STRIP_LOW]);
@@ -295,7 +297,6 @@ private function validateTheRequest(): array
295297
$only_private = (!is_null($get_public_matches) && !$get_public_matches);
296298
$due_date = (empty($due_date) ? null : Utils::mysqlTimestamp($due_date));
297299

298-
299300
$engineStruct = null;
300301
// any other engine than Match
301302
if ($mt_engine !== null and $mt_engine > 1) {
@@ -327,6 +328,10 @@ private function validateTheRequest(): array
327328
)
328329
);
329330

331+
// validate Lara style
332+
if($engineStruct instanceof Lara){
333+
$lara_style = (!empty($lara_style)) ? Lara::validateLaraStyle($lara_style) : Lara::DEFAULT_STYLE;
334+
}
330335

331336
/**
332337
* Represents a generic data variable that can hold a variety of information.
@@ -338,7 +343,6 @@ private function validateTheRequest(): array
338343
* @var mixed $data The data container allowing for versatile usage scenarios.
339344
*/
340345
$data = [
341-
342346
'file_name' => $file_name,
343347
'project_name' => $project_name,
344348
'source_lang' => $source_lang,
@@ -355,6 +359,7 @@ private function validateTheRequest(): array
355359
'intento_provider' => (!empty($intento_provider)) ? $intento_provider : null,
356360
'intento_routing' => (!empty($intento_routing)) ? $intento_routing : null,
357361
'lara_glossaries' => (!empty($lara_glossaries)) ? $lara_glossaries : null,
362+
'lara_style' => (!empty($lara_style)) ? $lara_style : null,
358363
'deepl_id_glossary' => (!empty($deepl_id_glossary)) ? $deepl_id_glossary : null,
359364
'deepl_formality' => (!empty($deepl_formality)) ? $deepl_formality : null,
360365
'deepl_engine_type' => (!empty($deepl_engine_type)) ? $deepl_engine_type : null,
@@ -431,7 +436,7 @@ private function validateTheRequest(): array
431436
$data['payable_rate_template'],
432437
$data['payable_rate_template_id']
433438
);
434-
$data['dialect_strict'] = $this->validateDialectStrictParam($data['target_lang'], $data['dialect_strict']);
439+
$data['dialect_strict'] = $this->validateDialectStrictParam(Languages::getInstance(), $data['dialect_strict']);
435440
$data['filters_extraction_parameters'] = $this->validateFiltersExtractionParameters(
436441
$data['filters_extraction_parameters']
437442
);
@@ -756,27 +761,34 @@ private function validatePayableRateTemplate(
756761
}
757762

758763
/**
759-
* Validate `dialect_strict` param vs target languages
764+
* Validate `dialect_strict` param
760765
*
761766
* Example: {"it-IT": true, "en-US": false, "fr-FR": false}
762767
*
763-
* @param $target_lang
768+
* @param Languages $lang_handler
764769
* @param null $dialect_strict
765770
*
766771
* @return string|null
767772
*/
768-
private function validateDialectStrictParam($target_lang, $dialect_strict = null): ?string
773+
private function validateDialectStrictParam(Languages $lang_handler, $dialect_strict = null): ?string
769774
{
770775
if (!empty($dialect_strict)) {
771776
$dialect_strict = trim(html_entity_decode($dialect_strict));
772-
$target_languages = preg_replace('/\s+/', '', $target_lang);
773-
$targets = explode(',', trim($target_languages));
777+
778+
// first check if `dialect_strict` is a valid JSON
779+
if (!Utils::isJson($dialect_strict)) {
780+
throw new InvalidArgumentException("dialect_strict is not a valid JSON");
781+
}
782+
774783
$dialectStrictObj = json_decode($dialect_strict, true);
775784

776785
foreach ($dialectStrictObj as $lang => $value) {
777-
if (!in_array($lang, $targets)) {
786+
787+
try {
788+
$lang_handler->validateLanguage($lang);
789+
} catch (Exception $e) {
778790
throw new InvalidArgumentException(
779-
'Wrong `dialect_strict` object, language, ' . $lang . ' is not one of the project target languages'
791+
'Wrong `dialect_strict` object, language, ' . $lang . ' is not supported'
780792
);
781793
}
782794

lib/Controller/API/App/EngineController.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ public function add(): void
221221
$this->destroyUserEnginesCache();
222222
}
223223

224-
$engine_type = explode("\\", $newEngineStruct->class_load);
225-
$engine_type = array_pop($engine_type);
224+
$engine_type = $newEngineStruct->getEngineType();
226225

227226
if (!$newCreatedDbRowStruct instanceof EngineStruct) {
228227
throw new AuthorizationError("Creation failed. Only one $engine_type engine is allowed.", 403);
@@ -251,15 +250,11 @@ public function add(): void
251250
$UserMetadataDao->set($this->user->uid, $newCreatedDbRowStruct->class_load, $newCreatedDbRowStruct->id);
252251
}
253252

253+
$data = $newCreatedDbRowStruct->arrayRepresentation();
254+
$data['extra'] = $newEngineStruct->extra_parameters;
255+
254256
$this->response->json([
255-
'data' => [
256-
'id' => $newCreatedDbRowStruct->id,
257-
'name' => $newCreatedDbRowStruct->name,
258-
'description' => $newCreatedDbRowStruct->description,
259-
'type' => $newCreatedDbRowStruct->type,
260-
'extra' => $newEngineStruct->extra_parameters,
261-
'engine_type' => $engine_type,
262-
],
257+
'data' => $data,
263258
'errors' => [],
264259
]);
265260
}
@@ -291,9 +286,8 @@ public function disable(): void
291286
$engine = EnginesFactory::createTempInstance($result);
292287

293288
if ($engine->isAdaptiveMT()) {
294-
$engName = explode("\\", $result->class_load);
295289
//retrieve OWNER EnginesFactory License
296-
(new MetadataDao())->delete($this->user->uid, array_pop($engName)); // engine_id
290+
(new MetadataDao())->delete($this->user->uid, $result->getEngineType()); // engine_id
297291
}
298292

299293
$this->response->json([

lib/Controller/API/App/GetContributionController.php

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use ReflectionException;
2323
use Utils\Contribution\Get;
2424
use Utils\Contribution\GetContributionRequest;
25+
use Utils\Engines\Lara;
2526
use Utils\Registry\AppConfig;
2627
use Utils\TaskRunner\Exceptions\EndQueueException;
2728
use Utils\TaskRunner\Exceptions\ReQueueException;
@@ -46,26 +47,30 @@ public function get(): void
4647
{
4748
$request = $this->validateTheRequest();
4849

49-
$id_client = $request['id_client'];
5050
$id_job = $request['id_job'];
5151
$id_segment = $request['id_segment'];
52-
$num_results = $request['num_results'];
5352
$password = $request['password'];
53+
54+
$jobStruct = ChunkDao::getByIdAndPassword($id_job, $password);
55+
$dataRefMap = SegmentOriginalDataDao::getSegmentDataRefMap($id_segment);
56+
57+
$projectStruct = $jobStruct->getProject();
58+
$this->featureSet->loadForProject($projectStruct);
59+
60+
$id_client = $request['id_client'];
61+
$num_results = $request['num_results'];
5462
$received_password = $request['received_password'];
5563
$concordance_search = $request['concordance_search'];
5664
$switch_languages = $request['switch_languages'];
5765
$cross_language = $request['cross_language'];
66+
$reasoning = $request['reasoning'];
67+
68+
$lara_style = $request['lara_style'] ?: $projectStruct->getMetadataValue('lara_style');
5869

5970
if (empty($num_results)) {
6071
$num_results = AppConfig::$DEFAULT_NUM_RESULTS_FROM_TM;
6172
}
6273

63-
$jobStruct = ChunkDao::getByIdAndPassword($id_job, $password);
64-
$dataRefMap = SegmentOriginalDataDao::getSegmentDataRefMap($id_segment);
65-
66-
$projectStruct = $jobStruct->getProject();
67-
$this->featureSet->loadForProject($projectStruct);
68-
6974
$contributionRequest = new GetContributionRequest();
7075
$featureSet = ($this->featureSet !== null) ? $this->featureSet : new FeatureSet();
7176
$subfiltering_handlers = (new MetadataDao())->getSubfilteringCustomHandlers($jobStruct->id, $jobStruct->password);
@@ -113,6 +118,7 @@ public function get(): void
113118
$contributionRequest->setUser($owner);
114119
$contributionRequest->setJobStruct($jobStruct);
115120
$contributionRequest->setProjectStruct($projectStruct);
121+
$contributionRequest->lara_style = $lara_style;
116122
$contributionRequest->segmentId = $id_segment;
117123
$contributionRequest->id_client = $id_client;
118124
$contributionRequest->concordanceSearch = $concordance_search;
@@ -142,6 +148,9 @@ public function get(): void
142148
if ($dialect_strict !== null) {
143149
$contributionRequest->dialect_strict = $dialect_strict->value == 1;
144150
}
151+
if ($reasoning !== null) {
152+
$contributionRequest->reasoning = $reasoning;
153+
}
145154

146155
if ($mt_evaluation !== null) {
147156
$contributionRequest->mt_evaluation = $mt_evaluation->value == 1;
@@ -179,6 +188,8 @@ public function get(): void
179188
'dialect_strict' => $contributionRequest->dialect_strict,
180189
'segmentId' => $contributionRequest->segmentId ? (string)$contributionRequest->segmentId : null,
181190
'resultNum' => (int)$contributionRequest->resultNum,
191+
'lara_style' => $contributionRequest->lara_style,
192+
'reasoning' => $contributionRequest->reasoning,
182193
'concordanceSearch' => $contributionRequest->concordanceSearch,
183194
]
184195
]
@@ -210,6 +221,7 @@ private function validateTheRequest(): array
210221
$password = filter_var($this->request->param('password'), FILTER_SANITIZE_SPECIAL_CHARS, ['flags' => FILTER_FLAG_STRIP_LOW]);
211222
$received_password = filter_var($this->request->param('current_password'), FILTER_SANITIZE_SPECIAL_CHARS, ['flags' => FILTER_FLAG_STRIP_LOW]);
212223
$concordance_search = filter_var($this->request->param('is_concordance'), FILTER_VALIDATE_BOOLEAN);
224+
$reasoning = filter_var($this->request->param('reasoning'), FILTER_VALIDATE_BOOLEAN);
213225
$switch_languages = filter_var($this->request->param('from_target'), FILTER_VALIDATE_BOOLEAN);
214226
$context_before = filter_var($this->request->param('context_before'), FILTER_UNSAFE_RAW);
215227
$context_after = filter_var($this->request->param('context_after'), FILTER_UNSAFE_RAW);
@@ -220,6 +232,7 @@ private function validateTheRequest(): array
220232
$cross_language = filter_var($this->request->param('cross_language'), FILTER_SANITIZE_SPECIAL_CHARS, ['flags' => FILTER_FORCE_ARRAY]);
221233
$text = trim($text);
222234
$translation = trim($translation);
235+
$lara_style = filter_var($this->request->param('lara_style'), FILTER_SANITIZE_SPECIAL_CHARS, ['flags' => FILTER_FLAG_STRIP_LOW]);
223236

224237
if (!$concordance_search) {
225238
//execute these lines only in segment contribution search,
@@ -247,6 +260,11 @@ private function validateTheRequest(): array
247260
throw new InvalidArgumentException("missing id_client", -5);
248261
}
249262

263+
// validate Lara style
264+
if(!empty($lara_style)){
265+
$lara_style = Lara::validateLaraStyle($lara_style);
266+
}
267+
250268
$this->id_job = $id_job;
251269
$this->request_password = $received_password;
252270

@@ -266,6 +284,8 @@ private function validateTheRequest(): array
266284
'id_before' => $id_before,
267285
'id_after' => $id_after,
268286
'cross_language' => $cross_language,
287+
'lara_style' => $lara_style,
288+
'reasoning' => $reasoning,
269289
'context_list_after' => json_decode($context_list_after, true),
270290
'context_list_before' => json_decode($context_list_before, true),
271291
];
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Controller\API\App;
4+
5+
use Controller\Abstracts\KleinController;
6+
use Controller\API\Commons\Exceptions\NotFoundException;
7+
use Controller\API\Commons\Validators\ChunkPasswordValidator;
8+
use Controller\API\Commons\Validators\LoginValidator;
9+
use Exception;
10+
use Model\Jobs\MetadataDao;
11+
use ReflectionException;
12+
use Utils\Validator\JSONSchema\JSONValidator;
13+
use Utils\Validator\JSONSchema\JSONValidatorObject;
14+
15+
class LaraController extends KleinController
16+
{
17+
protected function afterConstruct(): void
18+
{
19+
$this->appendValidator(new LoginValidator($this));
20+
}
21+
22+
public function translate(): void {
23+
// id segment
24+
// source_lang
25+
// target_lang
26+
// source
27+
// mt_engine_id
28+
// style
29+
// id_project
30+
// password
31+
}
32+
}

lib/Controller/API/App/TmKeyManagementController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,7 @@ private function _checkForAdaptiveEngines(MemoryKeyStruct $memoryKey): array
180180
if (!empty($ownerMmtEngineMetaData)) {
181181
$engine = EnginesFactory::getInstance($ownerMmtEngineMetaData->value);
182182
if ($engine->getMemoryIfMine($memoryKey)) {
183-
$engine_type = explode("\\", $engine->getEngineRecord()->class_load);
184-
$response[] = array_pop($engine_type);
183+
$response[] = $engine->getEngineRecord()->getEngineType();
185184
}
186185
}
187186
}

0 commit comments

Comments
 (0)