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

Commit

Permalink
Update based on review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
seanf committed Jul 29, 2013
1 parent 1d197fc commit 7460c33
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 34 deletions.
Expand Up @@ -176,14 +176,14 @@ private TransUnitUpdateRequest createRequest(TransMemoryMerge action, HLocale hL
if( tmResult.getMatchType() == MatchType.Imported )
{
TransMemoryUnit tu = transMemoryUnitDAO.findById(tmSourceId);
statusToSet = TransMemoryMergeStatusResolver.newInstance().workOutStatus(action, tmResult, oldTarget);
statusToSet = TransMemoryMergeStatusResolver.newInstance().decideStatus(action, tmResult, oldTarget);
comment = buildTargetComment(tu);
}
else
{
HTextFlow tmSource = textFlowDAO.findById(tmSourceId, false);
TransMemoryDetails tmDetail = getTransMemoryDetailsHandler.getTransMemoryDetail(hLocale, tmSource);
statusToSet = TransMemoryMergeStatusResolver.newInstance().workOutStatus(action, hTextFlowToBeFilled,
statusToSet = TransMemoryMergeStatusResolver.newInstance().decideStatus(action, hTextFlowToBeFilled,
tmDetail, tmResult, oldTarget);
comment = buildTargetComment(tmDetail);
}
Expand All @@ -202,19 +202,17 @@ private TransUnitUpdateRequest createRequest(TransMemoryMerge action, HLocale hL

private static String buildTargetComment(TransMemoryDetails tmDetail)
{
StringBuilder builder = new StringBuilder("auto translated by TM merge from ");
builder.append("project: ").append(tmDetail.getProjectName())
.append(", version: ").append(tmDetail.getIterationName())
.append(", DocId: ").append(tmDetail.getDocId());
return builder.toString();
return new StringBuilder("auto translated by TM merge from ")
.append("project: ").append(tmDetail.getProjectName())
.append(", version: ").append(tmDetail.getIterationName())
.append(", DocId: ").append(tmDetail.getDocId()).toString();
}

private static String buildTargetComment(TransMemoryUnit tu)
{
StringBuilder builder = new StringBuilder("auto translated by TM merge from ");
builder.append("translation memory: ").append(tu.getTranslationMemory().getSlug())
.append(", unique id: ").append(tu.getUniqueId());
return builder.toString();
return new StringBuilder("auto translated by TM merge from ")
.append("translation memory: ").append(tu.getTranslationMemory().getSlug())
.append(", unique id: ").append(tu.getUniqueId()).toString();
}

@Override
Expand Down
Expand Up @@ -62,7 +62,7 @@ public static TransMemoryMergeStatusResolver newInstance()
* @return content state to be set on auto translated target. If null means
* we want to reject the auto translation via TM merge
*/
public ContentState workOutStatus(TransMemoryMerge action, HTextFlow tfToBeFilled, TransMemoryDetails tmDetail, TransMemoryResultItem tmResult, HTextFlowTarget oldTarget)
public ContentState decideStatus(TransMemoryMerge action, HTextFlow tfToBeFilled, TransMemoryDetails tmDetail, TransMemoryResultItem tmResult, HTextFlowTarget oldTarget)
{

if ((int) tmResult.getSimilarityPercent() != 100)
Expand Down Expand Up @@ -100,7 +100,7 @@ else if (needReview)
* @return content state to be set on auto translated target. If null means
* we want to reject the auto translation via TM merge
*/
public ContentState workOutStatus(TransMemoryMerge action, TransMemoryResultItem tmResult,
public ContentState decideStatus(TransMemoryMerge action, TransMemoryResultItem tmResult,
HTextFlowTarget oldTarget)
{

Expand Down
Expand Up @@ -22,6 +22,7 @@
public class TextFlowStreamingDAOTest extends ZanataDbunitJpaTest
{

private static final int TEXTFLOWS_IN_SAMPLE_PROJECT_10 = 5;
private ProjectDAO projectDao;
private ProjectIterationDAO projectIterDao;
private TextFlowStreamingDAO dao;
Expand Down Expand Up @@ -50,7 +51,7 @@ public void findAllTextFlows() throws Exception
{
@Cleanup
CloseableIterator<HTextFlow> iter = dao.findTextFlows();
assertThat(Iterators.size(iter), equalTo(5));
assertThat(Iterators.size(iter), equalTo(TEXTFLOWS_IN_SAMPLE_PROJECT_10));
}

@Test
Expand All @@ -59,7 +60,7 @@ public void findTextFlowsForProject() throws Exception
HProject proj = projectDao.getBySlug("sample-project");
@Cleanup
CloseableIterator<HTextFlow> iter = dao.findTextFlowsByProject(proj);
assertThat(Iterators.size(iter), equalTo(5));
assertThat(Iterators.size(iter), equalTo(TEXTFLOWS_IN_SAMPLE_PROJECT_10));
}

@Test
Expand All @@ -77,7 +78,7 @@ public void findTextFlowsForProjectIter() throws Exception
HProjectIteration projIter = projectIterDao.getBySlug("sample-project", "1.0");
@Cleanup
CloseableIterator<HTextFlow> iter = dao.findTextFlowsByProjectIteration(projIter);
assertThat(Iterators.size(iter), equalTo(5));
assertThat(Iterators.size(iter), equalTo(TEXTFLOWS_IN_SAMPLE_PROJECT_10));
}

@Test
Expand Down
Expand Up @@ -42,6 +42,11 @@
*/
public class TransMemoryJPATest extends ZanataDbunitJpaTest
{
/**
*
*/
private static final int NUM_TRANS_UNITS = 5;

@Override
protected void prepareDBUnitOperations()
{
Expand Down Expand Up @@ -93,7 +98,7 @@ public void saveWithTransUnits() throws Exception
TransMemory tm = createDefaultTransMemoryInstance();

// add some units
for( int i = 0; i<5; i++ )
for( int i = 0; i<NUM_TRANS_UNITS; i++ )
{
TransMemoryUnit unit = new TransMemoryUnit("uid:" + i);
unit.setTranslationMemory(tm);
Expand All @@ -107,7 +112,7 @@ public void saveWithTransUnits() throws Exception
// Fetch it, should have the same elements
TransMemory stored = getTransMemory("new-trans-memory");

assertThat(stored.getTranslationUnits().size(), is(5));
assertThat(stored.getTranslationUnits().size(), is(NUM_TRANS_UNITS));
}

@Test
Expand All @@ -116,7 +121,7 @@ public void saveTransUnitsWithMetadata() throws Exception
TransMemory tm = createDefaultTransMemoryInstance();

// add some units
for( int i = 0; i<5; i++ )
for( int i = 0; i<NUM_TRANS_UNITS; i++ )
{
TransMemoryUnit unit = new TransMemoryUnit("uid:" + i);
unit.setTranslationMemory(tm);
Expand All @@ -131,7 +136,7 @@ public void saveTransUnitsWithMetadata() throws Exception
// Fetch it, should have the same elements
TransMemory stored = getTransMemory("new-trans-memory");

assertThat(stored.getTranslationUnits().size(), is(5));
assertThat(stored.getTranslationUnits().size(), is(NUM_TRANS_UNITS));
for( TransMemoryUnit tu : tm.getTranslationUnits() )
{
assertThat(tu.getMetadata().size(), is(1));
Expand Down
Expand Up @@ -111,7 +111,7 @@ private TransMemoryMerge mergeTMActionWhenProjectNameIsDifferent(MergeOption pro
@Test
public void notOneHundredMatchWillBeSetAsFuzzy() {
action = mergeTMAction(MergeOption.IGNORE_CHECK, MergeOption.IGNORE_CHECK, MergeOption.IGNORE_CHECK, MergeOption.IGNORE_CHECK);
ContentState result = resolver.workOutStatus(action, textFlow, tmDetail, tmResultWithSimilarity(90), null);
ContentState result = resolver.decideStatus(action, textFlow, tmDetail, tmResultWithSimilarity(90), null);

assertThat(result, equalTo(ContentState.NeedReview));
}
Expand All @@ -120,86 +120,86 @@ public void notOneHundredMatchWillBeSetAsFuzzy() {
public void differentResIdAndOptionIsFuzzy() {
TransMemoryDetails tmDetail = tmDetail(projectName, docId, "different res id", msgContext);
action = mergeTMActionWhenResIdIsDifferent(MergeOption.FUZZY);
assertThat(resolver.workOutStatus(action, textFlow, tmDetail, tmResultWithSimilarity(100), null), equalTo(ContentState.NeedReview));
assertThat(resolver.decideStatus(action, textFlow, tmDetail, tmResultWithSimilarity(100), null), equalTo(ContentState.NeedReview));
}

@Test
public void differentResIdAndOptionIsIgnore() {
TransMemoryDetails tmDetail = tmDetail(projectName, docId, "different res id", msgContext);

action = mergeTMActionWhenResIdIsDifferent(MergeOption.IGNORE_CHECK);
assertThat(resolver.workOutStatus(action, textFlow, tmDetail, tmResultWithSimilarity(100), null), equalTo(ContentState.Translated));
assertThat(resolver.decideStatus(action, textFlow, tmDetail, tmResultWithSimilarity(100), null), equalTo(ContentState.Translated));
}

@Test
public void differentResIdAndOptionIsReject() {
TransMemoryDetails tmDetail = tmDetail(projectName, docId, "different res id", msgContext);
action = mergeTMActionWhenResIdIsDifferent(MergeOption.REJECT);
assertThat(resolver.workOutStatus(action, textFlow, tmDetail, tmResultWithSimilarity(80), null), is(nullValue()));
assertThat(resolver.decideStatus(action, textFlow, tmDetail, tmResultWithSimilarity(80), null), is(nullValue()));
}

@Test
public void differentMsgContextAndOptionIsFuzzy() {
TransMemoryDetails tmDetail = tmDetail(projectName, docId, resId, "different msg context");
action = mergeTMActionWhenResIdIsDifferent(MergeOption.FUZZY);
assertThat(resolver.workOutStatus(action, textFlow, tmDetail, tmResultWithSimilarity(100), null), equalTo(ContentState.NeedReview));
assertThat(resolver.decideStatus(action, textFlow, tmDetail, tmResultWithSimilarity(100), null), equalTo(ContentState.NeedReview));
}

@Test
public void differentMsgContextAndOptionIsIgnore() {
TransMemoryDetails tmDetail = tmDetail(projectName, docId, resId, "different msg context");

action = mergeTMActionWhenResIdIsDifferent(MergeOption.IGNORE_CHECK);
assertThat(resolver.workOutStatus(action, textFlow, tmDetail, tmResultWithSimilarity(100), null), equalTo(ContentState.Translated));
assertThat(resolver.decideStatus(action, textFlow, tmDetail, tmResultWithSimilarity(100), null), equalTo(ContentState.Translated));
}

@Test
public void differentMsgContextAndOptionIsReject() {
TransMemoryDetails tmDetail = tmDetail(projectName, docId, resId, "different msg context");
action = mergeTMActionWhenResIdIsDifferent(MergeOption.REJECT);
assertThat(resolver.workOutStatus(action, textFlow, tmDetail, tmResultWithSimilarity(80), null), is(nullValue()));
assertThat(resolver.decideStatus(action, textFlow, tmDetail, tmResultWithSimilarity(80), null), is(nullValue()));
}

@Test
public void differentDocIdAndOptionIsFuzzy() {
TransMemoryDetails tmDetail = tmDetail(projectName, "different doc id", resId, msgContext);
action = mergeTMActionWhenDocIdIsDifferent(MergeOption.FUZZY);
assertThat(resolver.workOutStatus(action, textFlow, tmDetail, tmResultWithSimilarity(100), null), equalTo(ContentState.NeedReview));
assertThat(resolver.decideStatus(action, textFlow, tmDetail, tmResultWithSimilarity(100), null), equalTo(ContentState.NeedReview));
}

@Test
public void differentDocIdAndOptionIsIgnore() {
TransMemoryDetails tmDetail = tmDetail(projectName, "different doc id", resId, msgContext);
action = mergeTMActionWhenDocIdIsDifferent(MergeOption.IGNORE_CHECK);
assertThat(resolver.workOutStatus(action, textFlow, tmDetail, tmResultWithSimilarity(100), null), equalTo(ContentState.Translated));
assertThat(resolver.decideStatus(action, textFlow, tmDetail, tmResultWithSimilarity(100), null), equalTo(ContentState.Translated));
}

@Test
public void differentDocIdAndOptionIsReject() {
TransMemoryDetails tmDetail = tmDetail(projectName, "different doc id", resId, msgContext);
action = mergeTMActionWhenDocIdIsDifferent(MergeOption.REJECT);
assertThat(resolver.workOutStatus(action, textFlow, tmDetail, tmResultWithSimilarity(100), null), is(nullValue()));
assertThat(resolver.decideStatus(action, textFlow, tmDetail, tmResultWithSimilarity(100), null), is(nullValue()));
}

@Test
public void differentProjectNameAndOptionIsFuzzy() {
TransMemoryDetails tmDetail = tmDetail("different project name", docId, resId, msgContext);
action = mergeTMActionWhenProjectNameIsDifferent(MergeOption.FUZZY);
assertThat(resolver.workOutStatus(action, textFlow, tmDetail, tmResultWithSimilarity(100), null), equalTo(ContentState.NeedReview));
assertThat(resolver.decideStatus(action, textFlow, tmDetail, tmResultWithSimilarity(100), null), equalTo(ContentState.NeedReview));
}

@Test
public void differentProjectNameAndOptionIsIgnore() {
TransMemoryDetails tmDetail = tmDetail("different project name", docId, resId, msgContext);
action = mergeTMActionWhenProjectNameIsDifferent(MergeOption.IGNORE_CHECK);
assertThat(resolver.workOutStatus(action, textFlow, tmDetail, tmResultWithSimilarity(100), null), equalTo(ContentState.Translated));
assertThat(resolver.decideStatus(action, textFlow, tmDetail, tmResultWithSimilarity(100), null), equalTo(ContentState.Translated));
}

@Test
public void differentProjectNameAndOptionIsReject() {
TransMemoryDetails tmDetail = tmDetail("different project name", docId, resId, msgContext);
action = mergeTMActionWhenProjectNameIsDifferent(MergeOption.REJECT);
assertThat(resolver.workOutStatus(action, textFlow, tmDetail, tmResultWithSimilarity(100), null), is(nullValue()));
assertThat(resolver.decideStatus(action, textFlow, tmDetail, tmResultWithSimilarity(100), null), is(nullValue()));
}

@Test
Expand All @@ -211,7 +211,7 @@ public void willRejectIfThereIsOldTranslationButCanNotFindTranslationToSetAsAppr
HTextFlowTarget oldTarget = new HTextFlowTarget(textFlow, new HLocale());
oldTarget.setState(ContentState.NeedReview);

assertThat(resolver.workOutStatus(action, textFlow, tmDetail, tmResultWithSimilarity(100), oldTarget), is(nullValue()));
assertThat(resolver.decideStatus(action, textFlow, tmDetail, tmResultWithSimilarity(100), oldTarget), is(nullValue()));
}

}

0 comments on commit 7460c33

Please sign in to comment.