Package org.zanata.webtrans.shared.model

Examples of org.zanata.webtrans.shared.model.TransMemoryResultItem


    @Override
    public void renderTable(List<TransMemoryResultItem> memories,
            List<String> queries) {
        currentQueries = queries;
        for (int i = 0; i < memories.size(); i++) {
            final TransMemoryResultItem item = memories.get(i);

            resultTable.setWidget(i + 1, SOURCE_COL,
                    createSourcePanel(item, queries));
            resultTable.setWidget(i + 1, TARGET_COL, createTargetPanel(item));

            Label countLabel = new Label(String.valueOf(item.getMatchCount()));
            countLabel
                    .setTitle(messages.matchCountTooltip(item.getMatchCount()));

            resultTable.setWidget(i + 1, NUM_TRANS_COL, countLabel);
            resultTable.getFlexCellFormatter().setStyleName(i + 1,
                    NUM_TRANS_COL, "txt--align-center");

            if (odd(i)) {
                resultTable.getRowFormatter().setStyleName(i + 1, "oddRow");
            }

            Button copyButton = new Button(messages.copy());
            copyButton.setTitle(messages.copyTooltip());

            copyButton.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    listener.fireCopyEvent(item);
                }
            });

            resultTable.setWidget(i + 1, ACTION_COL, copyButton);
            resultTable.getFlexCellFormatter().setStyleName(i + 1, ACTION_COL,
                    "txt--align-center");

            Label similarityLabel =
                    new Label((int) item.getSimilarityPercent() + "%");
            resultTable.setWidget(i + 1, SIMILARITY_COL, similarityLabel);
            resultTable.getFlexCellFormatter().setStyleName(i + 1,
                    SIMILARITY_COL, "txt--align-center");

            Anchor infoCell = new Anchor();
            if (item.getMatchType() == MatchType.Imported) {
                String originStr = Joiner.on(", ").join(item.getOrigins());
                infoCell.setText(shorten(originStr, 10));
                infoCell.setTitle(originStr);
            } else {
                infoCell.setStyleName("i i--info txt--lead");
                infoCell.addClickHandler(new ClickHandler() {
View Full Code Here


    }

    @Override
    public void redrawTable(List<TransMemoryResultItem> memories) {
        for (int i = 0; i < memories.size(); i++) {
            TransMemoryResultItem item = memories.get(i);
            resultTable.setWidget(i + 1, SOURCE_COL,
                    createSourcePanel(item, currentQueries));
        }
    }
View Full Code Here

    }

    @Override
    public void onTransMemoryCopy(TransMemoryShortcutCopyEvent event) {
        if (userWorkspaceContext.hasEditTranslationAccess()) {
            TransMemoryResultItem item = getTMResultOrNull(event);
            if (item != null) {
                Log.debug("Copy from translation memory:"
                        + (event.getIndex() + 1));
                eventBus.fireEvent(new CopyDataToEditorEvent(item
                        .getTargetContents()));
            }
        }
    }
View Full Code Here

            Map<TMKey, TransMemoryResultItem> matchesMap, Object[] match,
            TransMemoryResultItem.MatchType matchType,
            ArrayList<String> sourceContents, ArrayList<String> targetContents,
            Long sourceId, String origin) {
        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);
            matchesMap.put(key, item);
        }
        item.incMatchCount();
        item.addOrigin(origin);
        item.addSourceId(sourceId);
    }
View Full Code Here

        target2.add("<tr> &lt;target2</tr>");
        ArrayList<String> target3 = new ArrayList<String>();
        target3.add("<tr> &lt;target3</tr>");
        ArrayList<String> target4 = new ArrayList<String>();
        target4.add("<tr> &lt;target4</tr>");
        matches.add(new TransMemoryResultItem(source, target1,
                ApprovedInternal, 3, 85));
        matches.add(new TransMemoryResultItem(source, target2,
                ApprovedInternal, 3, 85));
        matches.add(new TransMemoryResultItem(source, target3,
                TranslatedInternal, 3, 85));
        matches.add(new TransMemoryResultItem(source, target4,
                TranslatedInternal, 3, 85));
        callback.onSuccess(new GetTranslationMemoryResult(action, matches));
        Log.info("EXIT DummyGetTranslationMemoryCommand.execute()");
    }
View Full Code Here

        return prepareAction(threshold, requests, opts);
    }

    private static TransMemoryResultItem tmResult(Long sourceId, int percent) {
        TransMemoryResultItem resultItem =
                new TransMemoryResultItem(tmSource, tmTarget,
                        MatchType.ApprovedInternal, 1D, percent);
        resultItem.addSourceId(sourceId);
        return resultItem;
    }
View Full Code Here

        return resultItem;
    }

    private static TransMemoryResultItem importedTmResult(Long sourceId,
            int percent) {
        TransMemoryResultItem resultItem =
                new TransMemoryResultItem(tmSource, tmTarget,
                        MatchType.Imported, 1D, percent);
        resultItem.addSourceId(sourceId);
        return resultItem;
    }
View Full Code Here

                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()),
                updateRequestCaptor.capture());

        List<TransUnitUpdateRequest> updateRequest =
                updateRequestCaptor.getValue();
        assertThat(updateRequest, Matchers.hasSize(1));
        TransUnitUpdateRequest transUnitUpdateRequest = updateRequest.get(0);
        assertThat(transUnitUpdateRequest.getNewContents(),
                Matchers.equalTo(mostSimilarTM.getTargetContents()));
        assertThat(
                transUnitUpdateRequest.getTargetComment(),
                Matchers.equalTo("auto translated by TM merge from project: project a, version: master, DocId: pot/msg.pot"));
    }
View Full Code Here

        // 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));
        TransUnitUpdateRequest transUnitUpdateRequest = updateRequest.get(0);
        assertThat(transUnitUpdateRequest.getNewContents(),
                Matchers.equalTo(mostSimilarTM.getTargetContents()));
        assertThat(
                transUnitUpdateRequest.getTargetComment(),
                Matchers.equalTo("auto translated by TM merge from translation memory: test-tm, unique id: uid10"));
    }
View Full Code Here

        verify(display).setListener(presenter);
    }

    @Test
    public void testShow() throws Exception {
        TransMemoryResultItem transMemoryResultItem =
                Mockito.mock(TransMemoryResultItem.class);
        ArrayList<Long> sourceIds = Lists.newArrayList(1L, 2L);
        when(transMemoryResultItem.getSourceIdList()).thenReturn(sourceIds);
        when(transMemoryResultItem.getSourceContents()).thenReturn(
                Lists.newArrayList("a", "b"));
        when(transMemoryResultItem.getTargetContents()).thenReturn(
                Lists.newArrayList("c", "d"));

        presenter.show(transMemoryResultItem);

        verify(dispatcher).execute(actionCaptor.capture(),
                resultCaptor.capture());
        assertThat(actionCaptor.getValue().getTransUnitIdList(),
                Matchers.equalTo(sourceIds));
        AbstractAsyncCallback<TransMemoryDetailsList> callback =
                resultCaptor.getValue();

        Date lastModifiedDate = new Date();
        // testing on callback success
        TransMemoryDetails details =
                new TransMemoryDetails("source comment", "target comment",
                        "project", "iteration", "docId", "resId", "msgContext",
                        ContentState.Approved, "admin", lastModifiedDate);
        callback.onSuccess(new TransMemoryDetailsList(Lists
                .newArrayList(details)));

        InOrder inOrder = Mockito.inOrder(display);
        inOrder.verify(display).clearSourceAndTarget();
        inOrder.verify(display).setSource(
                transMemoryResultItem.getSourceContents());
        inOrder.verify(display).setTarget(
                transMemoryResultItem.getTargetContents());
        inOrder.verify(display).clearDocs();
        inOrder.verify(display).addDoc("project/iteration/docId");

        verify(display).setSourceComment("source comment");
        verify(display).setTargetComment("target comment");
View Full Code Here

TOP

Related Classes of org.zanata.webtrans.shared.model.TransMemoryResultItem

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.