Search in sources :

Example 1 with PropBean

use of net.heartsome.cat.ts.core.bean.PropBean in project translationstudio8 by heartsome.

the class TmUtils method fuzzyResult2Alttransbean.

public static Vector<AltTransBean> fuzzyResult2Alttransbean(List<FuzzySearchResult> fuzzyResults) {
    Vector<AltTransBean> altTrans = new Vector<AltTransBean>();
    for (FuzzySearchResult result : fuzzyResults) {
        AltTransBean atb = new AltTransBean();
        //			Map<String, String> match = tu.getTuInfo();
        TmxTU tu = result.getTu();
        // 获取源节点内容、属性及纯文本
        atb.setSrcText(tu.getSource().getPureText());
        atb.setTgtText(tu.getTarget().getPureText());
        Hashtable<String, String> matchProps = new Hashtable<String, String>();
        matchProps.put("match-quality", result.getSimilarity() + "");
        matchProps.put("origin", result.getDbName());
        matchProps.put("tool-id", "Translation Memory");
        matchProps.put("hs:matchType", "TM");
        matchProps.put("xml:space", "default");
        atb.setMatchProps(matchProps);
        Hashtable<String, String> srcProps = new Hashtable<String, String>();
        srcProps.put("xml:lang", tu.getSource().getLangCode());
        atb.setSrcProps(srcProps);
        atb.setSrcContent(tu.getSource().getFullText());
        Hashtable<String, String> tgtProps = new Hashtable<String, String>();
        tgtProps.put("xml:lang", tu.getTarget().getLangCode());
        atb.setTgtProps(tgtProps);
        atb.setTgtContent(tu.getTarget().getFullText());
        Vector<PropGroupBean> pgs = new Vector<PropGroupBean>();
        Vector<PropBean> props = new Vector<PropBean>();
        PropBean pb = new PropBean("creationId", tu.getCreationUser());
        props.add(pb);
        pb = new PropBean("creationDate", tu.getCreationDate());
        props.add(pb);
        pb = new PropBean("changeId", tu.getChangeUser());
        props.add(pb);
        pb = new PropBean("changeDate", tu.getChangeDate());
        props.add(pb);
        List<TmxProp> attrValList = tu.getProps();
        for (TmxProp attr : attrValList) {
            String name = attr.getName();
            if (name == null || name.equals("")) {
                continue;
            }
            String value = attr.getValue();
            if (value == null || value.equals("")) {
                continue;
            }
            PropBean prop = new PropBean(name, value);
            props.add(prop);
        }
        PropGroupBean pg = new PropGroupBean(props);
        // 获取属性组名称。
        pg.setName("hs:prop-group");
        pgs.add(pg);
        atb.setPropGroups(pgs);
        atb.setFuzzyResult(result);
        altTrans.add(atb);
    }
    return altTrans;
}
Also used : Hashtable(java.util.Hashtable) PropBean(net.heartsome.cat.ts.core.bean.PropBean) TmxProp(net.heartsome.cat.common.bean.TmxProp) PropGroupBean(net.heartsome.cat.ts.core.bean.PropGroupBean) AltTransBean(net.heartsome.cat.ts.core.bean.AltTransBean) FuzzySearchResult(net.heartsome.cat.common.bean.FuzzySearchResult) TmxTU(net.heartsome.cat.common.bean.TmxTU) Vector(java.util.Vector)

Example 2 with PropBean

use of net.heartsome.cat.ts.core.bean.PropBean in project translationstudio8 by heartsome.

the class MatchViewPart method loadData.

private synchronized void loadData(List<AltTransBean> matches) {
    if (matches == null) {
        return;
    }
    IEditorReference[] editorReferences = getSite().getPage().getEditorReferences();
    if (editorReferences.length == 0) {
        return;
    }
    for (AltTransBean altTransBean : matches) {
        String type = altTransBean.getMatchProps().get("hs:matchType");
        if (type == null || type.equals("")) {
            type = "others";
        }
        String orgin = altTransBean.getMatchOrigin();
        if (orgin == null) {
            // Fixed bug 2258 by Jason 翻译匹配面板不支持非 HS 工具匹配信息的显示
            orgin = "";
        }
        String srcContent = altTransBean.getSrcContent();
        if (srcContent == null || srcContent.equals("")) {
            continue;
        }
        String tgtContent = altTransBean.getTgtContent();
        if (tgtContent == null || tgtContent.equals("")) {
            continue;
        }
        String quality = altTransBean.getMatchProps().get("match-quality").trim();
        if (quality == null) {
            quality = "";
        } else {
            if (!quality.endsWith("%")) {
                quality += "%";
            }
        }
        String changeDate = null;
        String changeid = null;
        String creationDate = null;
        String creationid = null;
        Vector<PropGroupBean> propGroups = altTransBean.getPropGroups();
        StringBuffer toolTipBfTemp = new StringBuffer();
        if (propGroups != null) {
            for (PropGroupBean propGroupBean : propGroups) {
                List<PropBean> propBeans = propGroupBean.getProps();
                for (PropBean bean : propBeans) {
                    String ptype = bean.getProptype();
                    String pVal = bean.getValue();
                    if (ptype.equals("changeDate")) {
                        if (pVal != null && !pVal.equals("")) {
                            changeDate = DateUtils.formatDateFromUTC(pVal);
                        }
                    } else if (ptype.equals("changeId")) {
                        changeid = pVal;
                    } else if (ptype.equals("creationId")) {
                        creationid = pVal;
                    } else if (ptype.equals("creationDate")) {
                        if (pVal != null && !pVal.equals("")) {
                            creationDate = DateUtils.formatDateFromUTC(pVal);
                        }
                    } else {
                        toolTipBfTemp.append(ptype).append(" : ").append(pVal).append("\n");
                    }
                }
            }
        }
        StringBuffer toolTipBf = new StringBuffer();
        if (creationid != null && !creationid.equals("")) {
            toolTipBf.append(Messages.getString("view.MatchViewPart.info.tooltip.creationId")).append(creationid).append("\n");
        }
        if (creationDate != null && !creationDate.equals("")) {
            toolTipBf.append(Messages.getString("view.MatchViewPart.info.tooltip.creationDate")).append(creationDate).append("\n");
        }
        toolTipBf.append(toolTipBfTemp);
        StringBuffer msgBf = new StringBuffer();
        if (changeDate != null && !changeDate.equals("")) {
            msgBf.append(changeDate);
        }
        if (changeid != null && !changeid.equals("")) {
            if (msgBf.length() != 0) {
                msgBf.append("  |  ");
            }
            msgBf.append(changeid);
        }
        if (orgin != null && !orgin.equals("")) {
            if (msgBf.length() != 0) {
                msgBf.append("  |  ");
            }
            msgBf.append(orgin);
        }
        if (gridTable.isDisposed()) {
            return;
        }
        String toolId = altTransBean.getMatchProps().get("tool-id");
        GridItem gridItem = new GridItem(gridTable, SWT.NONE);
        gridItem.setText(0, srcContent);
        gridItem.setText(1, quality);
        gridItem.setText(2, tgtContent);
        gridItem.setToolTipText(0, toolId);
        gridItem.setToolTipText(1, toolId);
        gridItem.setToolTipText(2, toolId);
        // 保存信息
        gridItem.setData("info", resetSpecialString(msgBf.toString()));
        gridItem.setData("infoTooltip", resetSpecialString(toolTipBf.toString()));
        // 保存目标纯文本
        gridItem.setData("tgtText", altTransBean.getTgtText());
        // 保存目标纯文本
        gridItem.setData("tgtContent", tgtContent);
        gridItem.setData("matchType", type);
        gridItem.setData("quality", quality.substring(0, quality.lastIndexOf('%')));
        gridItem.setData("typeImage", getImageByType(type));
        gridItem.setData("tmFuzzyInfo", altTransBean.getFuzzyResult());
    }
}
Also used : PropGroupBean(net.heartsome.cat.ts.core.bean.PropGroupBean) AltTransBean(net.heartsome.cat.ts.core.bean.AltTransBean) IEditorReference(org.eclipse.ui.IEditorReference) GridItem(org.eclipse.nebula.widgets.grid.GridItem) PropBean(net.heartsome.cat.ts.core.bean.PropBean)

Example 3 with PropBean

use of net.heartsome.cat.ts.core.bean.PropBean in project translationstudio8 by heartsome.

the class XLFHandler method getPrpoGroups.

// 获取当前节点下的属性组集合。
private Vector<PropGroupBean> getPrpoGroups(VTDUtils vu) throws XPathParseException, XPathEvalException, NavException {
    VTDNav vn = vu.getVTDNav();
    Vector<PropGroupBean> pgs = new Vector<PropGroupBean>();
    AutoPilot ap = new AutoPilot(vn);
    ap.selectXPath("./prop-group");
    while (ap.evalXPath() != -1) {
        vn.push();
        Vector<PropBean> props = getProps(vu);
        vn.pop();
        PropGroupBean pg = new PropGroupBean(props);
        // 获取属性组名称。
        pg.setName(vu.getCurrentElementAttribut("name", null));
        pgs.add(pg);
    }
    ap.resetXPath();
    ap.declareXPathNameSpace("xml", VTDUtils.XML_NAMESPACE_URL);
    ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
    ap.selectXPath("./hs:prop-group");
    while (ap.evalXPath() != -1) {
        vn.push();
        Vector<PropBean> props = getProps(vu);
        vn.pop();
        PropGroupBean pg = new PropGroupBean(props);
        // 获取属性组名称。
        pg.setName(vu.getCurrentElementAttribut("name", null));
        pgs.add(pg);
    }
    if (pgs.isEmpty()) {
        pgs = null;
    }
    return pgs;
}
Also used : PropGroupBean(net.heartsome.cat.ts.core.bean.PropGroupBean) AutoPilot(com.ximpleware.AutoPilot) PropBean(net.heartsome.cat.ts.core.bean.PropBean) VTDNav(com.ximpleware.VTDNav) Vector(java.util.Vector)

Example 4 with PropBean

use of net.heartsome.cat.ts.core.bean.PropBean in project translationstudio8 by heartsome.

the class XLFHandler method getProps.

// 获取当前节点下的属性元素子节点。
private Vector<PropBean> getProps(VTDUtils vu) throws XPathParseException, XPathEvalException, NavException {
    VTDNav vn = vu.getVTDNav();
    Vector<PropBean> props = new Vector<PropBean>();
    AutoPilot ap = new AutoPilot(vn);
    ap.selectXPath("./prop");
    while (ap.evalXPath() != -1) {
        String proptype = vu.getCurrentElementAttribut("prop-type", null);
        String value = vu.getElementContent();
        String lang = vu.getCurrentElementAttribut("xml:lang", null);
        PropBean prop = new PropBean(proptype, value, lang);
        props.add(prop);
    }
    ap.resetXPath();
    ap.declareXPathNameSpace("xml", VTDUtils.XML_NAMESPACE_URL);
    ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
    ap.selectXPath("./hs:prop");
    while (ap.evalXPath() != -1) {
        String proptype = vu.getCurrentElementAttribut("prop-type", null);
        String value = vu.getElementContent();
        String lang = vu.getCurrentElementAttribut("xml:lang", null);
        PropBean prop = new PropBean(proptype, value, lang);
        props.add(prop);
    }
    if (props.isEmpty()) {
        props = null;
    }
    return props;
}
Also used : AutoPilot(com.ximpleware.AutoPilot) PropBean(net.heartsome.cat.ts.core.bean.PropBean) VTDNav(com.ximpleware.VTDNav) Vector(java.util.Vector)

Example 5 with PropBean

use of net.heartsome.cat.ts.core.bean.PropBean in project translationstudio8 by heartsome.

the class TmUtils method altTransInfoConverter.

/**
	 * 将从库中获取的匹配转成以 AltTransBean 封装的匹配数据,在转换的过程与当前 AltTrans重复的记录将被忽略
	 * @param dbMatches
	 *            从数据库中获取的匹配
	 * @param currentAltTrans
	 *            当前已经存原altTrans
	 * @return 和当前匹配不重复的AltTrans集;
	 */
public static Vector<AltTransBean> altTransInfoConverter(List<FuzzySearchResult> dbMatches, Vector<AltTransBean> currentAltTrans) {
    Vector<AltTransBean> altTrans = new Vector<AltTransBean>();
    Vector<AltTransBean> existAltTrans = new Vector<AltTransBean>();
    for (FuzzySearchResult result : dbMatches) {
        AltTransBean atb = new AltTransBean();
        //			Map<String, String> match = tu.getTuInfo();
        TmxTU tu = result.getTu();
        // 获取源节点内容、属性及纯文本
        atb.setSrcText(tu.getSource().getPureText());
        atb.setTgtText(tu.getTarget().getPureText());
        if (isMatchExist(currentAltTrans, atb, result.getDbName(), existAltTrans)) {
            continue;
        }
        Hashtable<String, String> matchProps = new Hashtable<String, String>();
        matchProps.put("match-quality", result.getSimilarity() + "");
        matchProps.put("origin", result.getDbName());
        matchProps.put("tool-id", "Translation Memory");
        matchProps.put("hs:matchType", "TM");
        matchProps.put("xml:space", "default");
        atb.setMatchProps(matchProps);
        Hashtable<String, String> srcProps = new Hashtable<String, String>();
        srcProps.put("xml:lang", tu.getSource().getLangCode());
        atb.setSrcProps(srcProps);
        atb.setSrcContent(tu.getSource().getFullText());
        Hashtable<String, String> tgtProps = new Hashtable<String, String>();
        tgtProps.put("xml:lang", tu.getTarget().getLangCode());
        atb.setTgtProps(tgtProps);
        atb.setTgtContent(tu.getTarget().getFullText());
        Vector<PropGroupBean> pgs = new Vector<PropGroupBean>();
        Vector<PropBean> props = new Vector<PropBean>();
        PropBean pb = new PropBean("creationId", tu.getCreationUser());
        props.add(pb);
        pb = new PropBean("creationDate", tu.getCreationDate());
        props.add(pb);
        pb = new PropBean("changeId", tu.getChangeUser());
        props.add(pb);
        pb = new PropBean("changeDate", tu.getChangeDate());
        props.add(pb);
        List<TmxProp> attrValList = tu.getProps();
        for (TmxProp attr : attrValList) {
            String name = attr.getName();
            if (name == null || name.equals("")) {
                continue;
            }
            String value = attr.getValue();
            if (value == null || value.equals("")) {
                continue;
            }
            PropBean prop = new PropBean(name, value);
            props.add(prop);
        }
        PropGroupBean pg = new PropGroupBean(props);
        // 获取属性组名称。
        pg.setName("hs:prop-group");
        pgs.add(pg);
        atb.setPropGroups(pgs);
        altTrans.add(atb);
    }
    if (altTrans.size() > 0) {
        altTrans.addAll(existAltTrans);
    } else {
        currentAltTrans.addAll(existAltTrans);
    }
    return altTrans;
}
Also used : Hashtable(java.util.Hashtable) PropBean(net.heartsome.cat.ts.core.bean.PropBean) TmxProp(net.heartsome.cat.common.bean.TmxProp) PropGroupBean(net.heartsome.cat.ts.core.bean.PropGroupBean) AltTransBean(net.heartsome.cat.ts.core.bean.AltTransBean) FuzzySearchResult(net.heartsome.cat.common.bean.FuzzySearchResult) TmxTU(net.heartsome.cat.common.bean.TmxTU) Vector(java.util.Vector)

Aggregations

PropBean (net.heartsome.cat.ts.core.bean.PropBean)7 Vector (java.util.Vector)6 PropGroupBean (net.heartsome.cat.ts.core.bean.PropGroupBean)5 AutoPilot (com.ximpleware.AutoPilot)4 VTDNav (com.ximpleware.VTDNav)4 AltTransBean (net.heartsome.cat.ts.core.bean.AltTransBean)3 Hashtable (java.util.Hashtable)2 FuzzySearchResult (net.heartsome.cat.common.bean.FuzzySearchResult)2 TmxProp (net.heartsome.cat.common.bean.TmxProp)2 TmxTU (net.heartsome.cat.common.bean.TmxTU)2 GridItem (org.eclipse.nebula.widgets.grid.GridItem)1 IEditorReference (org.eclipse.ui.IEditorReference)1