Skip to content

Commit

Permalink
Fix bug 1469010: Calculate source length in the quality expression (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jotes authored and mathjazz committed Nov 20, 2018
1 parent ce9db86 commit 173b38f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pontoon/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2910,6 +2910,9 @@ def postgres_levenshtein_ratio(
:return: TranslationMemory Entries enriched with the quality metric.
"""
text_length = Value(len(text))

source_target_length = Length(F('source')) + text_length

levenshtein_param = levenshtein_param or F('source')
levenshtein_distance_expression = LevenshteinDistance(
levenshtein_param,
Expand All @@ -2927,9 +2930,9 @@ def postgres_levenshtein_ratio(
quality=ExpressionWrapper(
(
Cast(
(F('source_length') + text_length - levenshtein_distance_expression),
(source_target_length - levenshtein_distance_expression),
models.FloatField()
) / (F('source_length') + text_length)
) / source_target_length
) * 100,
output_field=models.DecimalField()
)
Expand Down

0 comments on commit 173b38f

Please sign in to comment.