Search in sources :

Example 6 with FuzzySearchResult

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

the class PreTranslation method overwriteMatchs.

private void overwriteMatchs(VTDUtils vu, String srcLang, String tgtLang, XMLModifier xm, IProgressMonitor monitor) throws NavException, XPathParseException, XPathEvalException, ModifyException, UnsupportedEncodingException, InterruptedException {
    AutoPilot tuAp = new AutoPilot(vu.getVTDNav());
    tuAp.selectXPath("./body//trans-unit");
    while (tuAp.evalXPath() != -1) {
        // 循环 Trans-unit
        if (monitor != null && monitor.isCanceled()) {
            throw new InterruptedException();
        }
        String locked = vu.getCurrentElementAttribut("translate", "yes");
        if (locked.equals("no")) {
            continue;
        }
        TransUnitInfo2TranslationBean tuInfo = getTransUnitInfo(vu);
        if (tuInfo == null) {
            continue;
        }
        // System.out.println(tuInfo.getSrcFullText());
        tuInfo.setSrcLanguage(srcLang);
        tuInfo.setTgtLangugage(tgtLang);
        getTuContext(vu, contextSize, tuInfo);
        // Vector<Hashtable<String, String>> result = tmMatcher.executeSearch(currentProject, tuInfo);
        List<FuzzySearchResult> result = tmMatcher.executeFuzzySearch(currentProject, tuInfo);
        updateXliffFile(vu, tuInfo, result, xm, true);
        monitor.worked(1);
    }
}
Also used : FuzzySearchResult(net.heartsome.cat.common.bean.FuzzySearchResult) AutoPilot(com.ximpleware.AutoPilot) TransUnitInfo2TranslationBean(net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean)

Example 7 with FuzzySearchResult

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

the class PreTranslation method keepHigherMatchs.

private void keepHigherMatchs(VTDUtils vu, String srcLang, String tgtLang, XMLModifier xm, IProgressMonitor monitor) throws NavException, XPathParseException, XPathEvalException, ModifyException, UnsupportedEncodingException, InterruptedException {
    AutoPilot tuAp = new AutoPilot(vu.getVTDNav());
    tuAp.selectXPath("./body//trans-unit");
    boolean needUpdateTarget = false;
    while (tuAp.evalXPath() != -1) {
        // 循环 Trans-unit
        if (monitor != null && monitor.isCanceled()) {
            throw new InterruptedException();
        }
        String locked = vu.getCurrentElementAttribut("translate", "yes");
        if (locked.equals("no")) {
            continue;
        }
        //  ===从库中查询匹配===
        TransUnitInfo2TranslationBean tuInfo = getTransUnitInfo(vu);
        if (tuInfo == null) {
            continue;
        }
        tuInfo.setSrcLanguage(srcLang);
        tuInfo.setTgtLangugage(tgtLang);
        getTuContext(vu, contextSize, tuInfo);
        List<FuzzySearchResult> result = tmMatcher.executeFuzzySearch(currentProject, tuInfo);
        if (!result.isEmpty()) {
            int matchMaxSimiInt = result.get(0).getSimilarity();
            // ===获取当前目标的匹配率===
            int currMaxSimInt = 0;
            vu.getVTDNav().push();
            AutoPilot targetAp = new AutoPilot(vu.getVTDNav());
            targetAp.selectXPath("./target");
            if (targetAp.evalXPath() != -1) {
                String targetContent = vu.getElementContent();
                if (targetContent != null && !targetContent.equals("")) {
                    Hashtable<String, String> attrs = vu.getCurrentElementAttributs();
                    if (attrs != null) {
                        String type = attrs.get("hs:matchType");
                        String quality = attrs.get("hs:quality");
                        if (type != null && type.equals("TM") && quality != null && !quality.equals("")) {
                            currMaxSimInt = Integer.parseInt(quality);
                        } else {
                            //对于这种没有匹配率的 segment(手动翻译了,但是没入库,没锁定的情况。),需要覆盖2013-09-02, Austen。
                            currMaxSimInt = 1;
                        }
                    }
                } else {
                    // target内容为空
                    needUpdateTarget = true;
                }
            } else {
                // 无target内容
                needUpdateTarget = true;
            }
            vu.getVTDNav().pop();
            if (currMaxSimInt != 0 && matchMaxSimiInt > currMaxSimInt) {
                needUpdateTarget = true;
            }
        }
        //  ===获取当前最大匹配结束===
        updateXliffFile(vu, tuInfo, result, xm, needUpdateTarget);
        needUpdateTarget = false;
        monitor.worked(1);
    }
}
Also used : FuzzySearchResult(net.heartsome.cat.common.bean.FuzzySearchResult) AutoPilot(com.ximpleware.AutoPilot) TransUnitInfo2TranslationBean(net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean)

Example 8 with FuzzySearchResult

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

FuzzySearchResult (net.heartsome.cat.common.bean.FuzzySearchResult)8 TmxProp (net.heartsome.cat.common.bean.TmxProp)5 TmxTU (net.heartsome.cat.common.bean.TmxTU)5 AutoPilot (com.ximpleware.AutoPilot)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 Statement (java.sql.Statement)3 Timestamp (java.sql.Timestamp)3 TmxSegement (net.heartsome.cat.common.bean.TmxSegement)3 TransUnitInfo2TranslationBean (net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean)3 Hashtable (java.util.Hashtable)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 CallableStatement (java.sql.CallableStatement)1 ArrayList (java.util.ArrayList)1 OracleCallableStatement (oracle.jdbc.OracleCallableStatement)1 OraclePreparedStatement (oracle.jdbc.OraclePreparedStatement)1