Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
fix(translation memory): remove 0% matching TM entry
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Feb 15, 2016
1 parent 2a29468 commit 9b2aef6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* [ZNTA-742](https://zanata.atlassian.net/browse/ZNTA-742) - Get a list of contributors for a Project version via the API
* [ZNTA-744](https://zanata.atlassian.net/browse/ZNTA-744) - Add review data to the contribution statistics API
* [ZNTA-879](https://zanata.atlassian.net/browse/ZNTA-879) - Allow admin to configure the visibility of user email
* [ZNTA-905](https://zanata.atlassian.net/browse/ZNTA-905) - Remove 0% matching translation memory entry

-----------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public class TranslationMemoryServiceImpl implements TranslationMemoryService {
// private static final float BOOST_PROJITERSLUG = SysProperties.getFloat(
// SysProperties.TM_BOOST_PROJITERSLUG, 1.5f);

private static final double MINIMUM_SIMILARITY = 1.0;

@Inject @FullText
private FullTextEntityManager entityManager;

Expand Down Expand Up @@ -359,8 +361,18 @@ private void processIndexMatch(TransMemoryQuery transMemoryQuery,
Lists.newArrayList(textFlowTarget.getContents());
TransMemoryResultItem.MatchType matchType =
fromContentState(textFlowTarget.getState());
TransMemoryResultItem item = createOrGetResultItem(transMemoryQuery, matchesMap, match, matchType,
textFlowContents, targetContents);

double percent =
calculateSimilarityPercentage(transMemoryQuery,
textFlowContents);
if (percent < MINIMUM_SIMILARITY) {
log.info("Ignoring TM - {} with less than {}% matching.",
textFlowContents, MINIMUM_SIMILARITY);
return;
}
TransMemoryResultItem item = createOrGetResultItem(
matchesMap, match, matchType,
textFlowContents, targetContents, percent);
addTextFlowTargetToResultMatches(textFlowTarget, item);
} else if (entity instanceof TransMemoryUnit) {
TransMemoryUnit transUnit = (TransMemoryUnit) entity;
Expand All @@ -370,8 +382,17 @@ private void processIndexMatch(TransMemoryQuery transMemoryQuery,
ArrayList<String> targetContents =
Lists.newArrayList(transUnit.getTransUnitVariants()
.get(targetLocaleId.getId()).getPlainTextSegment());
TransMemoryResultItem item = createOrGetResultItem(transMemoryQuery, matchesMap, match,
TransMemoryResultItem.MatchType.Imported, sourceContents, targetContents);
double percent =
calculateSimilarityPercentage(transMemoryQuery, sourceContents);
if (percent < MINIMUM_SIMILARITY) {
log.info("Ignoring TM - {} with less than {}% matching.",
sourceContents, MINIMUM_SIMILARITY);
return;
}
TransMemoryResultItem item =
createOrGetResultItem(matchesMap, match,
TransMemoryResultItem.MatchType.Imported,
sourceContents, targetContents, percent);
addTransMemoryUnitToResultMatches(item, transUnit);
}
}
Expand Down Expand Up @@ -430,16 +451,15 @@ private static TransMemoryResultItem.MatchType fromContentState(
*
* @return the item for the given source and target contents, which may be newly created.
*/
private TransMemoryResultItem createOrGetResultItem(TransMemoryQuery transMemoryQuery, Map<TMKey,
TransMemoryResultItem> matchesMap, Object[] match, TransMemoryResultItem.MatchType matchType,
ArrayList<String> sourceContents, ArrayList<String> targetContents) {
private TransMemoryResultItem createOrGetResultItem(
Map<TMKey, TransMemoryResultItem> matchesMap, Object[] match,
TransMemoryResultItem.MatchType matchType,
ArrayList<String> sourceContents, ArrayList<String> targetContents,
double percent) {
TMKey key = new TMKey(sourceContents, targetContents);
TransMemoryResultItem item = matchesMap.get(key);
if (item == null) {
float score = (Float) match[0];
double percent =
calculateSimilarityPercentage(transMemoryQuery,
sourceContents);
item =
new TransMemoryResultItem(sourceContents, targetContents,
matchType, score, percent);
Expand Down

0 comments on commit 9b2aef6

Please sign in to comment.