Search in sources :

Example 11 with TmxTU

use of net.heartsome.cat.common.bean.TmxTU in project translationstudio8 by heartsome.

the class TmxReader method read.

public TmxReaderEvent read() {
    TmxTU tu = null;
    try {
        if (tuAp.evalXPath() != -1) {
            tu = new TmxTU();
            readTuElementAttribute(tu);
            readTuNoteElement(tu);
            readTuPropElement(tu);
            readTuTuvElement(tu);
        } else {
            return new TmxReaderEvent(null, TmxReaderEvent.END_FILE);
        }
    } catch (VTDException e) {
        return new TmxReaderEvent(null, TmxReaderEvent.READ_EXCEPTION);
    }
    return new TmxReaderEvent(tu, TmxReaderEvent.NORMAL_READ);
}
Also used : TmxTU(net.heartsome.cat.common.bean.TmxTU) VTDException(com.ximpleware.VTDException)

Example 12 with TmxTU

use of net.heartsome.cat.common.bean.TmxTU 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

TmxTU (net.heartsome.cat.common.bean.TmxTU)12 TmxSegement (net.heartsome.cat.common.bean.TmxSegement)7 TmxProp (net.heartsome.cat.common.bean.TmxProp)6 ArrayList (java.util.ArrayList)5 FuzzySearchResult (net.heartsome.cat.common.bean.FuzzySearchResult)5 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 Statement (java.sql.Statement)3 Timestamp (java.sql.Timestamp)3 HashMap (java.util.HashMap)2 Hashtable (java.util.Hashtable)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 Vector (java.util.Vector)2 AltTransBean (net.heartsome.cat.ts.core.bean.AltTransBean)2 PropBean (net.heartsome.cat.ts.core.bean.PropBean)2 PropGroupBean (net.heartsome.cat.ts.core.bean.PropGroupBean)2 VTDException (com.ximpleware.VTDException)1 File (java.io.File)1 IOException (java.io.IOException)1