Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bucketing #3173

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 41 additions & 10 deletions lib/Utils/Analysis/Workers/TMAnalysisWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,22 +149,23 @@ protected function _endQueueCallback( QueueElement $queueElement ) {
*/
protected function _updateRecord( QueueElement $queueElement ) {

$firstAvailableNotMTMatch = $this->getFirstAvailableNotMTMatch();
$featureSet = ( $this->featureSet !== null ) ? $this->featureSet : new \FeatureSet();
$filter = MateCatFilter::getInstance( $featureSet, $queueElement->params->source, $queueElement->params->target, [] );
$suggestion = $this->_matches[ 0 ][ 'raw_translation' ]; //No layering needed
$suggestion = $firstAvailableNotMTMatch[ 'raw_translation' ]; //No layering needed

$suggestion_match = $this->_matches[ 0 ][ 'match' ];
$suggestion_source = $this->_matches[ 0 ][ 'created_by' ];
$suggestion_match = $firstAvailableNotMTMatch[ 'match' ];
$suggestion_source = $firstAvailableNotMTMatch[ 'created_by' ];

$equivalentWordMapping = json_decode( $queueElement->params->payable_rates, true );

$new_match_type = $this->_getNewMatchType(
( stripos( $this->_matches[ 0 ][ 'created_by' ], "MT" ) !== false ? "MT" : $suggestion_match ),
( stripos( $firstAvailableNotMTMatch[ 'created_by' ], "MT" ) !== false ? "MT" : $suggestion_match ),
$queueElement->params->match_type,
$equivalentWordMapping,
/* is Public TM */
empty( $this->_matches[ 0 ][ 'memory_key' ] ),
isset( $this->_matches[ 0 ][ 'ICE' ] ) && $this->_matches[ 0 ][ 'ICE' ]
empty( $firstAvailableNotMTMatch[ 'memory_key' ] ),
isset( $firstAvailableNotMTMatch[ 'ICE' ] ) && $firstAvailableNotMTMatch[ 'ICE' ]
);

$eqWordMapping = (isset($equivalentWordMapping[ $new_match_type ])) ? $equivalentWordMapping[ $new_match_type ] : null;
Expand All @@ -182,7 +183,12 @@ protected function _updateRecord( QueueElement $queueElement ) {
$standard_words = $equivalentWordMapping[ "NO_MATCH" ] * $queueElement->params->raw_word_count / 100;

// realign MT Spaces
$check = $this->initPostProcess( $this->_matches[ 0 ][ 'raw_segment' ], $suggestion, $queueElement->params->source, $queueElement->params->target );
$check = $this->initPostProcess(
$firstAvailableNotMTMatch[ 'raw_segment' ],
$suggestion,
$queueElement->params->source,
$queueElement->params->target
);
$check->realignMTSpaces();

//this should every time be ok because MT preserve tags, but we use the check on the errors
Expand All @@ -201,14 +207,19 @@ protected function _updateRecord( QueueElement $queueElement ) {

}

( !empty( $this->_matches[ 0 ][ 'sentence_confidence' ] ) ?
$mt_qe = floatval( $this->_matches[ 0 ][ 'sentence_confidence' ] ) :
( !empty( $firstAvailableNotMTMatch[ 'sentence_confidence' ] ) ?
$mt_qe = floatval( $firstAvailableNotMTMatch[ 'sentence_confidence' ] ) :
$mt_qe = null
);

// perform a consistency check as setTranslation does
// in order to add spaces to translation if needed
$check = $this->initPostProcess( $queueElement->params->segment, $suggestion, $queueElement->params->source, $queueElement->params->target );
$check = $this->initPostProcess(
$queueElement->params->segment,
$suggestion,
$queueElement->params->source,
$queueElement->params->target
);
$check->performConsistencyCheck();
$suggestion = $check->getTargetSeg();
$err_json2 = ( $check->thereAreErrors() ) ? $check->getErrorsJSON() : '';
Expand Down Expand Up @@ -276,6 +287,26 @@ protected function _updateRecord( QueueElement $queueElement ) {

}

/**
* Get the first available not MT match
* @return mixed
*/
private function getFirstAvailableNotMTMatch()
{
foreach($this->_matches as $match){
// return $match if not MT and quality >= 75
if(
stripos( $match[ 'created_by' ], "MT" ) === false and
(int)$match[ 'match' ] >= 75
){
return $match;
}
}

// return the first match available
return $this->_matches[0];
}

/**
* Init a \PostProcess instance.
* This method forces to set source/target languages
Expand Down