Package org.zanata.model.tm

Examples of org.zanata.model.tm.TransMemoryUnit


     *
     * @throws TMXParseException
     */
    public void processTransUnit(TransMemory tm, Element tuElem)
            throws TMXParseException {
        TransMemoryUnit tu = new TransMemoryUnit();
        tu.setTranslationMemory(tm);

        TMXMetadataHelper.setMetadata(tu, tuElem, tm.getSourceLanguage());
        tu.setVersionNum(0);

        addTUVs(tu, tuElem.getChildElements("tuv"));

        tu.setUniqueId(determineUniqueId(tu));

        tu = mergeWithExistingTUIfAny(tu);
        entityManager.merge(tu);
    }
View Full Code Here


        TMXMetadataHelper.setMetadata(tuv, tuvElem);
        tu.getTransUnitVariants().put(tuv.getLanguage(), tuv);
    }

    private TransMemoryUnit mergeWithExistingTUIfAny(TransMemoryUnit newTU) {
        TransMemoryUnit existingTu =
                transMemoryDAO.findTranslationUnit(newTU.getTranslationMemory()
                        .getSlug(), newTU.getUniqueId());
        if (existingTu != null) {
            existingTu
                    .setMetadata(newTU.getMetadataType(), newTU.getMetadata());
            existingTu.setPosition(newTU.getPosition());
            existingTu.setSourceLanguage(newTU.getSourceLanguage());
            existingTu.setTransUnitId(newTU.getTransUnitId());
            existingTu.getTransUnitVariants().clear();
            existingTu.getTransUnitVariants().putAll(
                    newTU.getTransUnitVariants());
            // No need to set the unique id or parent Trans Memory, it should be
            // the same
            return existingTu;
        }
View Full Code Here

                    fromContentState(textFlowTarget.getState());
            addOrIncrementResultItem(transMemoryQuery, matchesMap, match,
                    matchType, textFlowContents, targetContents, textFlowTarget
                            .getTextFlow().getId(), "");
        } else if (entity instanceof TransMemoryUnit) {
            TransMemoryUnit transUnit = (TransMemoryUnit) entity;
            ArrayList<String> sourceContents =
                    Lists.newArrayList(transUnit.getTransUnitVariants()
                            .get(sourceLocaleId.getId()).getPlainTextSegment());
            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());
        }
    }
View Full Code Here

        assertThat(tm.getSourceLanguage(), equalTo("en-US"));

        Set<String> expectedLocales =
                Sets.newHashSet("en-US", "es", "es-ES", "fr", "fr-FR", "he",
                        "it", "it-IT");
        TransMemoryUnit tu = tm.getTranslationUnits().iterator().next();
        HashSet<String> actualLocales =
                Sets.newHashSet(tu.getTransUnitVariants().keySet());
        assertThat(actualLocales, equalTo(expectedLocales));
    }
View Full Code Here

        assertThat(tmChildren.get(0).getValue(), is("Header Prop value"));
        assertThat(tmChildren.get(1).getLocalName(), is("note"));
        assertThat(tmChildren.get(1).getValue(), is("Header Note value"));

        // Metadata at the TU level
        TransMemoryUnit tu0 =
                findInCollection(tm.getTranslationUnits(), "doc0:resId0");
        Map<String, String> tu0Atts = TMXMetadataHelper.getAttributes(tu0);
        assertThat(tu0Atts.size(), is(4));
        assertThat(tu0Atts, hasEntry("tuid", "doc0:resId0"));
        assertThat(tu0Atts, hasEntry("srclang", "en"));
        assertThat(tu0Atts, hasKey("creationdate"));
        assertThat(tu0Atts, hasKey("changedate"));

        List<Element> tu0Children = TMXMetadataHelper.getChildren(tu0);
        assertThat(tu0Children.size(), is(2));
        assertThat(tu0Children.get(0).getLocalName(), is("prop"));
        assertThat(tu0Children.get(0).getValue(), is("Custom prop0 value"));
        assertThat(tu0Children.get(1).getLocalName(), is("note"));
        assertThat(tu0Children.get(1).getValue(), is("Custom note"));

        TransMemoryUnit tu1 =
                findInCollection(tm.getTranslationUnits(), "doc0:resId1");
        Map<String, String> tu1Atts = TMXMetadataHelper.getAttributes(tu1);
        assertThat(tu1Atts.size(), is(4));
        assertThat(tu1Atts, hasEntry("tuid", "doc0:resId1"));
        assertThat(tu1Atts, hasEntry("srclang", "en"));
View Full Code Here

                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);
View Full Code Here

    public void saveWithTransUnits() throws Exception {
        TransMemory tm = createDefaultTransMemoryInstance();

        // add some units
        for (int i = 0; i < NUM_TRANS_UNITS; i++) {
            TransMemoryUnit unit = new TransMemoryUnit("uid:" + i);
            unit.setTranslationMemory(tm);
            unit.setSourceLanguage("en-US");
            unit.setTransUnitId("unit-id-" + i);
            tm.getTranslationUnits().add(unit);
        }

        super.getEm().persist(tm);
View Full Code Here

    public void saveTransUnitsWithMetadata() throws Exception {
        TransMemory tm = createDefaultTransMemoryInstance();

        // add some units
        for (int i = 0; i < NUM_TRANS_UNITS; i++) {
            TransMemoryUnit unit = new TransMemoryUnit("uid:" + i);
            unit.setTranslationMemory(tm);
            unit.setSourceLanguage("en-US");
            unit.setTransUnitId("unit-id-" + i);
            unit.setMetadata(TMMetadataType.TMX14, "Metadata " + i);
            tm.getTranslationUnits().add(unit);
        }

        super.getEm().persist(tm);
View Full Code Here

        // Fetch the translation memory
        TransMemory stored = loadTM("new-trans-memory");

        // Store a Trans unit variant with formatting
        TransMemoryUnit tu = stored.getTranslationUnits().iterator().next();
        TransMemoryUnitVariant tuvES =
                new TransMemoryUnitVariant("es",
                        "<seg>Mensaje <bpt>&lt;b></bpt>de<ept i=\"1\">&lt;b></ept> Prueba</seg>");

        tu.getTransUnitVariants().put(tuvES.getLanguage(), tuvES);

        super.getEm().merge(tu);

        // Verify they were saved
        TransMemoryUnitVariant tuv =
View Full Code Here

        Long tmSourceId = tmResult.getSourceIdList().get(0);
        ContentState statusToSet;
        String comment;
        if (tmResult.getMatchType() == TransMemoryResultItem.MatchType.Imported) {
            TransMemoryUnit tu = transMemoryUnitDAO.findById(tmSourceId);
            statusToSet =
                    TransMemoryMergeStatusResolver.newInstance().decideStatus(
                            action, tmResult, oldTarget);
            comment = buildTargetComment(tu);
        } else {
View Full Code Here

TOP

Related Classes of org.zanata.model.tm.TransMemoryUnit

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.