Package org.zanata.webtrans.shared.rpc

Examples of org.zanata.webtrans.shared.rpc.TransMemoryMerge


            display.hide();
            return;
        }

        display.showProcessing();
        TransMemoryMerge action =
                prepareTMMergeAction(items, percentage, mergeOptions);
        dispatcher.execute(action, new AsyncCallback<UpdateTransUnitResult>() {
            @Override
            public void onFailure(Throwable caught) {
                Log.warn("TM merge failed", caught);
View Full Code Here


                            public TransUnitUpdateRequest apply(TransUnit from) {
                                return new TransUnitUpdateRequest(from.getId(),
                                        null, null, from.getVerNum());
                            }
                        }));
        return new TransMemoryMerge(threshold, updateRequests, mergeOptions);
    }
View Full Code Here

    }

    private TransMemoryMerge prepareAction(int threshold,
            List<TransUnitUpdateRequest> requests, MergeOptions opts) {
        TransMemoryMerge action =
                new TransMemoryMerge(threshold, requests, opts);
        action.setWorkspaceId(new WorkspaceId(new ProjectIterationId(
                projectSlug, versionSlug, ProjectType.File), targetLocale
                .getLocaleId()));
        return action;
    }
View Full Code Here

    @Test
    public void willTranslateIfMatches() throws ActionException {
        // Given:
        // an action with threshold 80% and trans unit id is 1
        final long transUnitId = 1L;
        TransMemoryMerge action = prepareAction(80, transUnitId);

        HTextFlow hTextFlow =
                TestFixture.makeHTextFlow(transUnitId, sourceLocale,
                        targetLocale, ContentState.New, docId, versionSlug,
                        projectSlug);
        when(textFlowDAO.findByIdList(newArrayList(transUnitId))).thenReturn(
                newArrayList(hTextFlow));
        // Given: there are three TM results returned for text flow id 1, and
        // the most matched one is text flow id 11
        HTextFlow tmResultSource =
                TestFixture.makeApprovedHTextFlow(11L, targetLocale);
        TransMemoryResultItem mostSimilarTM =
                tmResult(tmResultSource.getId(), 100);

        when(textFlowDAO.findById(tmResultSource.getId(), false)).thenReturn(
                tmResultSource);

        when(localeService.getByLocaleId(action.getWorkspaceId().getLocaleId()))
                .thenReturn(targetLocale);

        when(
                translationMemoryService.getTransMemoryDetail(targetLocale,
                        tmResultSource)).thenReturn(tmDetail());

        Optional<TransMemoryResultItem> matches = Optional.of(mostSimilarTM);

        when(
                translationMemoryService.searchBestMatchTransMemory(hTextFlow,
                        targetLocale.getLocaleId(), sourceLocale.getLocaleId(),
                        false, false, false, action.getThresholdPercent()))
                .thenReturn(matches);

        // When: execute the action
        transMemoryMergeService.executeMerge(action);

        // Then:
        verify(securityService).checkWorkspaceAction(action.getWorkspaceId(),
                MODIFY);

        // we should have text flow auto translated by using the most
        // similar TM
        verify(translationService).translate(same(targetLocale.getLocaleId()),
View Full Code Here

    }

    @Test
    public void willNotTranslateIfNoMatches() throws ActionException {
        final long transUnitId = 1L;
        TransMemoryMerge action = prepareAction(80, transUnitId);

        HTextFlow hTextFlow =
                TestFixture.makeHTextFlow(transUnitId, sourceLocale,
                        targetLocale, ContentState.New, docId, versionSlug,
                        projectSlug);

        when(textFlowDAO.findByIdList(newArrayList(transUnitId))).thenReturn(
                newArrayList(hTextFlow));

        Optional<TransMemoryResultItem> matches =
                Optional.<TransMemoryResultItem> absent();

        when(
                translationMemoryService.searchBestMatchTransMemory(hTextFlow,
                        targetLocale.getLocaleId(), sourceLocale.getLocaleId(),
                        false, false, false, action.getThresholdPercent()))
                .thenReturn(matches);

        when(localeService.getByLocaleId(action.getWorkspaceId().getLocaleId()))
                .thenReturn(targetLocale);

        // When: execute the action
        transMemoryMergeService.executeMerge(action);

        verify(securityService).checkWorkspaceAction(action.getWorkspaceId(),
                MODIFY);

        // Then: we should have EMPTY trans unit update request
        verifyZeroInteractions(translationService);
    }
View Full Code Here

        // Given: an action with threshold 90% and trans unit id is 1, 2, 3, 4
        final long idWith100MatchTM = 1L;
        final long idWithoutTM = 2L;
        final long idWith80MatchTM = 3L;
        final long idWith90MatchTM = 4L;
        TransMemoryMerge action =
                prepareAction(90, idWith100MatchTM, idWithoutTM,
                        idWith80MatchTM, idWith90MatchTM);

        HTextFlow textFlow100TM =
                TestFixture.makeHTextFlow(idWith100MatchTM, sourceLocale,
                        targetLocale, ContentState.New, docId, versionSlug,
                        projectSlug);

        HTextFlow textFlowNoTM =
                TestFixture.makeHTextFlow(idWithoutTM, sourceLocale,
                        targetLocale, ContentState.New, docId, versionSlug,
                        projectSlug);
        HTextFlow textFlow80TM =
                TestFixture.makeHTextFlow(idWith80MatchTM, sourceLocale,
                        targetLocale, ContentState.New, docId, versionSlug,
                        projectSlug);
        HTextFlow textFLow90TM =
                TestFixture.makeHTextFlow(idWith90MatchTM, sourceLocale,
                        targetLocale, ContentState.New, docId, versionSlug,
                        projectSlug);

        when(localeService.getByLocaleId(action.getWorkspaceId().getLocaleId()))
                .thenReturn(targetLocale);

        when(
                textFlowDAO.findByIdList(newArrayList(idWith100MatchTM,
                        idWithoutTM, idWith80MatchTM, idWith90MatchTM)))
                .thenReturn(
                        newArrayList(textFlow100TM, textFlowNoTM, textFlow80TM,
                                textFLow90TM));
        // Given: TM results
        HTextFlow tmResultSource =
                TestFixture.makeApprovedHTextFlow(11L, targetLocale);

        Optional<TransMemoryResultItem> tm100 =
                Optional.of(tmResult(tmResultSource.getId(), 100));
        Optional<TransMemoryResultItem> tm90 =
                Optional.of(tmResult(tmResultSource.getId(), 90));
        Optional<TransMemoryResultItem> tm80 =
                Optional.of(tmResult(tmResultSource.getId(), 80));
        Optional<TransMemoryResultItem> noMatch = Optional.absent();

        when(
                translationMemoryService.searchBestMatchTransMemory(
                        textFlow100TM, targetLocale.getLocaleId(),
                        sourceLocale.getLocaleId(), false, false, false, 90))
                .thenReturn(tm100);
        when(
                translationMemoryService.searchBestMatchTransMemory(
                        textFLow90TM, targetLocale.getLocaleId(),
                        sourceLocale.getLocaleId(), false, false, false, 90))
                .thenReturn(tm90);
        when(
                translationMemoryService.searchBestMatchTransMemory(
                        textFlow80TM, targetLocale.getLocaleId(),
                        sourceLocale.getLocaleId(), false, false, false, 90))
                .thenReturn(tm80);
        when(
                translationMemoryService.searchBestMatchTransMemory(
                        textFlowNoTM, targetLocale.getLocaleId(),
                        sourceLocale.getLocaleId(), false, false, false, 90))
                .thenReturn(noMatch);

        when(textFlowDAO.findById(tmResultSource.getId(), false)).thenReturn(
                tmResultSource);
        // Given: tm detail of text flow id 11
        when(
                translationMemoryService.getTransMemoryDetail(targetLocale,
                        tmResultSource)).thenReturn(tmDetail());

        // When: execute the action
        transMemoryMergeService.executeMerge(action);

        verify(securityService).checkWorkspaceAction(action.getWorkspaceId(),
                MODIFY);

        // Then: we should have text flow auto translated by using the most
        // similar TM
        verify(translationService).translate(
                same(action.getWorkspaceId().getLocaleId()),
                updateRequestCaptor.capture());

        List<TransUnitUpdateRequest> updateRequest =
                updateRequestCaptor.getValue();
        assertThat(updateRequest, Matchers.hasSize(3));
View Full Code Here

    @Test
    public void canAutoTranslateImportedTMResults() throws Exception {
        // Given:
        // an action with threshold 80% and trans unit id
        final long transUnitId = 1L;
        TransMemoryMerge action = prepareAction(80, transUnitId);

        // A Text Flow to be translated
        HTextFlow hTextFlow =
                TestFixture.makeHTextFlow(transUnitId, sourceLocale,
                        targetLocale, ContentState.New, docId, versionSlug,
                        projectSlug);

        // A matching imported Translation Unit
        TransMemoryUnit tuResultSource =
                TestFixture.makeTransMemoryUnit(10L, targetLocale);

        // and an associated result item
        TransMemoryResultItem mostSimilarTM =
                importedTmResult(tuResultSource.getId(), 100);

        Optional<TransMemoryResultItem> match = Optional.of(mostSimilarTM);

        // A Translation memory query
        TransMemoryQuery tmQuery =
                prepareTMQuery(hTextFlow.getContents(), FUZZY_PLURAL, null,
                        hTextFlow.getResId());

        // Expectations:
        when(localeService.getByLocaleId(action.getWorkspaceId().getLocaleId()))
                .thenReturn(targetLocale);

        when(textFlowDAO.findByIdList(newArrayList(transUnitId))).thenReturn(
                newArrayList(hTextFlow));

        when(
                translationMemoryService.searchBestMatchTransMemory(hTextFlow,
                        targetLocale.getLocaleId(), sourceLocale.getLocaleId(),
                        false, false, false, action.getThresholdPercent()))
                .thenReturn(match);
        when(transMemoryUnitDAO.findById(tuResultSource.getId())).thenReturn(
                tuResultSource);

        // When: execute the action
        transMemoryMergeService.executeMerge(action);

        // Then: we should have text flow auto translated by using the most
        // similar TM
        verify(translationService).translate(
                same(action.getWorkspaceId().getLocaleId()),
                updateRequestCaptor.capture());

        List<TransUnitUpdateRequest> updateRequest =
                updateRequestCaptor.getValue();
        assertThat(updateRequest, Matchers.hasSize(1));
View Full Code Here

        InOrder inOrder = inOrder(display, dispatcher);
        inOrder.verify(display).showProcessing();
        inOrder.verify(dispatcher).execute(transMemoryMergeCaptor.capture(),
                callbackCaptor.capture());

        TransMemoryMerge action = transMemoryMergeCaptor.getValue();
        List<TransUnitUpdateRequest> updateRequests =
                action.getUpdateRequests();
        assertThat(updateRequests, Matchers.hasSize(5));
        assertThat(getIds(updateRequests),
                Matchers.contains(1L, 3L, 4L, 5L, 6L));
        assertThat(action.getDifferentProjectRule(),
                Matchers.equalTo(MergeRule.IGNORE_CHECK));
        assertThat(action.getDifferentDocumentRule(),
                Matchers.equalTo(MergeRule.REJECT));
        assertThat(action.getDifferentContextRule(),
                Matchers.equalTo(MergeRule.FUZZY));
        assertThat(action.getImportedMatchRule(),
                Matchers.equalTo(MergeRule.FUZZY));
    }
View Full Code Here

    }

    private static TransMemoryMerge mergeTMAction(MergeOptions mergeOptions) {
        TransUnitUpdateRequest updateRequest =
                new TransUnitUpdateRequest(new TransUnitId(1), null, null, 0);
        return new TransMemoryMerge(80, Lists.newArrayList(updateRequest),
                mergeOptions);
    }
View Full Code Here

                tmResultWithSimilarity(100), oldTarget), is(nullValue()));
    }

    @Test
    public void fromImportedTmAndOptionIsFuzzy() {
        TransMemoryMerge transMemoryMerge =
                mergeTMAction(importedMatch(MergeRule.FUZZY));
        assertThat(resolver.decideStatus(transMemoryMerge,
                tmResultWithSimilarityAndExternallyImported(100), null),
                equalTo(ContentState.NeedReview));
    }
View Full Code Here

TOP

Related Classes of org.zanata.webtrans.shared.rpc.TransMemoryMerge

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.