Search in sources :

Example 1 with FuzzyTransDataBean

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

the class RepeatRowSearcher method getRepeateRowsForFuzzy.

/**
	 * 针对繁殖翻译,获取所有满足条件的rowId
	 */
public static Map<String, List<String>> getRepeateRowsForFuzzy(XLFHandler handler) {
    Map<String, List<String>> resultMap = new LinkedHashMap<String, List<String>>();
    // 获取当前界面上所显示的所有行的 rowId
    ArrayList<String> rowIdList = handler.getRowIds();
    Map<String, FuzzyTransDataBean> srcTextMap = handler.getAllSrcTextForFuzzy(rowIdList, ignoreTag);
    // 排序
    List<Map.Entry<String, FuzzyTransDataBean>> mapList = new ArrayList<Map.Entry<String, FuzzyTransDataBean>>(srcTextMap.entrySet());
    Map<String, FuzzyTransDataBean> sameMap = new LinkedHashMap<String, FuzzyTransDataBean>();
    for (int i = 0; i < mapList.size(); i++) {
        Entry<String, FuzzyTransDataBean> entry = mapList.get(i);
        FuzzyTransDataBean bean = entry.getValue();
        boolean isSame = false;
        sameMap.clear();
        for (int j = i + 1; j < mapList.size(); j++) {
            Entry<String, FuzzyTransDataBean> curEntry = mapList.get(j);
            FuzzyTransDataBean curBean = curEntry.getValue();
            if (bean.getSrcText().equalsIgnoreCase(curBean.getSrcText())) {
                if (!isSame) {
                    sameMap.put(entry.getKey(), bean);
                }
                isSame = true;
                sameMap.put(curEntry.getKey(), curBean);
                mapList.remove(j);
                j--;
            }
        }
        ananysisFuzzyDataMap(sameMap, resultMap);
    }
    return resultMap;
}
Also used : ArrayList(java.util.ArrayList) FuzzyTransDataBean(net.heartsome.cat.ts.core.bean.FuzzyTransDataBean) LinkedHashMap(java.util.LinkedHashMap) Entry(java.util.Map.Entry) List(java.util.List) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with FuzzyTransDataBean

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

the class RepeatRowSearcher method ananysisFuzzyDataMap.

/**
	 * 处理源文相同的文本段。得到要进行繁殖翻译的 rowId
	 * @param sameMap
	 * @param resultMap
	 */
private static void ananysisFuzzyDataMap(Map<String, FuzzyTransDataBean> sameMap, Map<String, List<String>> resultMap) {
    // 先获取目标文本不为空的文本段。以最后一个为主
    String rootRowId = "";
    for (Entry<String, FuzzyTransDataBean> entry : sameMap.entrySet()) {
        if (!entry.getValue().isTgtNull()) {
            rootRowId = entry.getKey();
        }
    }
    if ("".equals(rootRowId)) {
        return;
    }
    List<String> childRowIdList = new ArrayList<String>();
    for (Entry<String, FuzzyTransDataBean> entry : sameMap.entrySet()) {
        FuzzyTransDataBean bean = entry.getValue();
        if (bean.isTgtNull() && !bean.isLock()) {
            childRowIdList.add(entry.getKey());
        }
    }
    if (childRowIdList.size() > 0) {
        resultMap.put(rootRowId, childRowIdList);
    }
}
Also used : ArrayList(java.util.ArrayList) FuzzyTransDataBean(net.heartsome.cat.ts.core.bean.FuzzyTransDataBean)

Example 3 with FuzzyTransDataBean

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

the class XLFHandler method getAllSrcTextForFuzzy.

/**
	 * 针对繁殖翻译。获取所有的源文。robert 2012-09-20
	 * @return
	 */
public Map<String, FuzzyTransDataBean> getAllSrcTextForFuzzy(ArrayList<String> rowIdList, boolean ignoreTag) {
    Map<String, FuzzyTransDataBean> textMap = new LinkedHashMap<String, FuzzyTransDataBean>();
    try {
        VTDNav vn = null;
        AutoPilot ap = new AutoPilot();
        VTDUtils vUtils = new VTDUtils();
        AutoPilot childAp = new AutoPilot();
        for (String rowId : rowIdList) {
            // 标识译文是否为空,如果为空,则为true,不为空则为 false
            boolean isTargetNull = false;
            // 是否锁定
            boolean isLock = false;
            vn = getVTDNavByRowId(rowId).duplicateNav();
            ap.bind(vn);
            vUtils.bind(vn);
            childAp.bind(vn);
            vn.push();
            ap.selectXPath(RowIdUtil.parseRowIdToXPath(rowId));
            if (ap.evalXPath() != -1) {
                // 如果,当前文本段是处于锁定状态的,就不用获取
                int index = vn.getAttrVal("translate");
                if (index != -1 && "no".equalsIgnoreCase(vn.toString(index))) {
                    isLock = true;
                }
                String srcText = null;
                vn.push();
                childAp.selectXPath("./source");
                if (childAp.evalXPath() != -1) {
                    // 如果忽略标记的话,就没有必要获取source节点的完整内容了
                    if (!ignoreTag) {
                        srcText = vUtils.getElementContent();
                    } else {
                        srcText = getTUPureText(vn);
                    }
                }
                vn.pop();
                vn.push();
                childAp.selectXPath("./target[text()!='' or *]");
                if (childAp.evalXPath() != -1) {
                    isTargetNull = false;
                } else {
                    isTargetNull = true;
                }
                vn.pop();
                // 存放值
                textMap.put(rowId, new FuzzyTransDataBean(srcText.trim(), isTargetNull, isLock));
            }
            vn.pop();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return textMap;
}
Also used : VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) FuzzyTransDataBean(net.heartsome.cat.ts.core.bean.FuzzyTransDataBean) VTDNav(com.ximpleware.VTDNav) NavException(com.ximpleware.NavException) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) XPathParseException(com.ximpleware.XPathParseException) FileNotFoundException(java.io.FileNotFoundException) XQException(javax.xml.xquery.XQException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TranscodeException(com.ximpleware.TranscodeException) XPathEvalException(com.ximpleware.XPathEvalException) IOException(java.io.IOException) ModifyException(com.ximpleware.ModifyException) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

FuzzyTransDataBean (net.heartsome.cat.ts.core.bean.FuzzyTransDataBean)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 AutoPilot (com.ximpleware.AutoPilot)1 ModifyException (com.ximpleware.ModifyException)1 NavException (com.ximpleware.NavException)1 TranscodeException (com.ximpleware.TranscodeException)1 VTDNav (com.ximpleware.VTDNav)1 XPathEvalException (com.ximpleware.XPathEvalException)1 XPathParseException (com.ximpleware.XPathParseException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 XQException (javax.xml.xquery.XQException)1 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)1 CoreException (org.eclipse.core.runtime.CoreException)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1