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

Commit

Permalink
Workaround TM result coalescing bug.
Browse files Browse the repository at this point in the history
Refactors the match processing code to make it clearer what type of
match is being added to a result item, and makes a few small changes
to minimize the incorrect behaviour:

 - No longer adds imported TM item id to the list that is used to look
   up text flows.

       A more complete fix is to wrap the Long id in a type so that
       all the ids are present and can be used sensibly. This just
       makes the list appropriate for the code that uses it right
       now, to delay spending the development time for the full fix.

 - Upgrades match type when a match has a higher match type, where
   ApprovedInternal > TranslatedInternal > Imported.

       Imported is treated as lowest just because the editor suppresses
       details display for Imported. Treating the others as higher will
       allow users to see text flow details for the other types.

       The full fix for this would be to inculde a summary of all the
       match types in the DTO, so the editor can display whatever
       makes sense.
  • Loading branch information
davidmason committed Jun 4, 2015
1 parent 8e915d2 commit a53c3cc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
Expand Up @@ -305,9 +305,9 @@ private void processIndexMatch(TransMemoryQuery transMemoryQuery,
Lists.newArrayList(textFlowTarget.getContents());
TransMemoryResultItem.MatchType matchType =
fromContentState(textFlowTarget.getState());
addOrIncrementResultItem(transMemoryQuery, matchesMap, match,
matchType, textFlowContents, targetContents, textFlowTarget
.getTextFlow().getId(), "");
TransMemoryResultItem item = createOrGetResultItem(transMemoryQuery, matchesMap, match, matchType,
textFlowContents, targetContents);
addTextFlowTargetToResultMatches(textFlowTarget, item);
} else if (entity instanceof TransMemoryUnit) {
TransMemoryUnit transUnit = (TransMemoryUnit) entity;
ArrayList<String> sourceContents =
Expand All @@ -316,10 +316,9 @@ private void processIndexMatch(TransMemoryQuery transMemoryQuery,
ArrayList<String> targetContents =
Lists.newArrayList(transUnit.getTransUnitVariants()
.get(targetLocaleId.getId()).getPlainTextSegment());
addOrIncrementResultItem(transMemoryQuery, matchesMap, match,
TransMemoryResultItem.MatchType.Imported, sourceContents,
targetContents, transUnit.getId(), transUnit
.getTranslationMemory().getSlug());
TransMemoryResultItem item = createOrGetResultItem(transMemoryQuery, matchesMap, match,
TransMemoryResultItem.MatchType.Imported, sourceContents, targetContents);
addTransMemoryUnitToResultMatches(item, transUnit);
}
}

Expand Down Expand Up @@ -370,11 +369,16 @@ private static TransMemoryResultItem.MatchType fromContentState(
}
}

private void addOrIncrementResultItem(TransMemoryQuery transMemoryQuery,
Map<TMKey, TransMemoryResultItem> matchesMap, Object[] match,
TransMemoryResultItem.MatchType matchType,
ArrayList<String> sourceContents, ArrayList<String> targetContents,
Long sourceId, String origin) {
/**
* Look up the result item for the given source and target contents.
*
* If no item is found, a new one is added to the map and returned.
*
* @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) {
TMKey key = new TMKey(sourceContents, targetContents);
TransMemoryResultItem item = matchesMap.get(key);
if (item == null) {
Expand All @@ -387,9 +391,29 @@ private void addOrIncrementResultItem(TransMemoryQuery transMemoryQuery,
matchType, score, percent);
matchesMap.put(key, item);
}
return item;
}

private void addTransMemoryUnitToResultMatches(TransMemoryResultItem item, TransMemoryUnit transMemoryUnit) {
item.incMatchCount();
item.addOrigin(transMemoryUnit.getTranslationMemory().getSlug());
}

private void addTextFlowTargetToResultMatches(HTextFlowTarget textFlowTarget, TransMemoryResultItem item) {
item.incMatchCount();
item.addOrigin(origin);
item.addSourceId(sourceId);

// TODO change sourceId to include type, then include the id of imported matches
item.addSourceId(textFlowTarget.getTextFlow().getId());

// Workaround: since Imported does not have a details view in the current editor,
// I am treating it as the lowest priority, so will be overwritten by
// other match types.
// A better fix is to have the DTO hold all the match types so the editor
// can show them in whatever way is most sensible.
ContentState state = textFlowTarget.getState();
if (state == ContentState.Approved || item.getMatchType() == TransMemoryResultItem.MatchType.Imported) {
item.setMatchType(fromContentState(state));
}
}

/**
Expand Down
Expand Up @@ -110,6 +110,10 @@ public List<String> getTargetContents() {
return targetContents;
}

public void setMatchType(MatchType matchType) {
this.matchType = matchType;
}

public MatchType getMatchType() {
return matchType;
}
Expand Down

0 comments on commit a53c3cc

Please sign in to comment.