Search in sources :

Example 6 with TransUnitInfo2TranslationBean

use of net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean 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 TransUnitInfo2TranslationBean

use of net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean in project translationstudio8 by heartsome.

the class PreTranslation method getTransUnitInfo.

private TransUnitInfo2TranslationBean getTransUnitInfo(VTDUtils vu) throws XPathParseException, XPathEvalException, NavException {
    TransUnitInfo2TranslationBean tuInfo = new TransUnitInfo2TranslationBean();
    vu.getVTDNav().push();
    AutoPilot sourceAp = new AutoPilot(vu.getVTDNav());
    sourceAp.selectXPath("./source");
    String fullText = "";
    String pureText = "";
    if (sourceAp.evalXPath() != -1) {
        fullText = vu.getElementContent();
        pureText = xlfHandler.getTUPureText(vu.getVTDNav());
    }
    vu.getVTDNav().pop();
    if (fullText == null || fullText.equals("") || pureText.equals("")) {
        return null;
    }
    tuInfo.setSrcFullText(fullText);
    tuInfo.setSrcPureText(pureText);
    return tuInfo;
}
Also used : AutoPilot(com.ximpleware.AutoPilot) TransUnitInfo2TranslationBean(net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean)

Example 8 with TransUnitInfo2TranslationBean

use of net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean 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 9 with TransUnitInfo2TranslationBean

use of net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean in project translationstudio8 by heartsome.

the class PreMachineTranslation method getTransUnitInfo.

private TransUnitInfo2TranslationBean getTransUnitInfo(VTDUtils vu) throws XPathParseException, XPathEvalException, NavException {
    TransUnitInfo2TranslationBean tuInfo = new TransUnitInfo2TranslationBean();
    vu.getVTDNav().push();
    AutoPilot sourceAp = new AutoPilot(vu.getVTDNav());
    sourceAp.selectXPath("./source");
    String fullText = "";
    String pureText = "";
    if (sourceAp.evalXPath() != -1) {
        fullText = vu.getElementContent();
        pureText = xlfHandler.getTUPureText(vu.getVTDNav());
    }
    vu.getVTDNav().pop();
    if (fullText == null || fullText.equals("") || pureText.equals("")) {
        return null;
    }
    tuInfo.setSrcFullText(fullText);
    tuInfo.setSrcPureText(pureText);
    return tuInfo;
}
Also used : AutoPilot(com.ximpleware.AutoPilot) TransUnitInfo2TranslationBean(net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean)

Example 10 with TransUnitInfo2TranslationBean

use of net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean in project translationstudio8 by heartsome.

the class MatchViewPart method reLoadMatches.

public void reLoadMatches(IXliffEditor editor, int rowIndex) {
    // 修复 Bug #3064 编辑匹配--更换记忆库后再编辑原记忆库匹配,出现异常.刷新问题
    // handler.getTransUnit(rowId);
    TransUnitBean transUnit = editor.getRowTransUnitBean(rowIndex);
    if (transUnit == null) {
        return;
    }
    XLFHandler handler = editor.getXLFHandler();
    if (handler == null) {
        return;
    }
    IProject prj = null;
    if (editor instanceof IEditorPart) {
        IEditorPart p = (IEditorPart) editor;
        FileEditorInput input = (FileEditorInput) p.getEditorInput();
        prj = input.getFile().getProject();
    }
    if (prj == null) {
        return;
    }
    String rowId = handler.getRowId(rowIndex);
    TransUnitInfo2TranslationBean tuInfoBean = getTuInfoBean(transUnit, handler, rowId);
    executeMatch(editor, rowId, transUnit, tuInfoBean, prj);
}
Also used : TransUnitBean(net.heartsome.cat.ts.core.bean.TransUnitBean) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler) IProject(org.eclipse.core.resources.IProject) TransUnitInfo2TranslationBean(net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean)

Aggregations

TransUnitInfo2TranslationBean (net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean)13 AutoPilot (com.ximpleware.AutoPilot)6 TransUnitBean (net.heartsome.cat.ts.core.bean.TransUnitBean)4 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)4 IProject (org.eclipse.core.resources.IProject)4 IEditorPart (org.eclipse.ui.IEditorPart)4 FileEditorInput (org.eclipse.ui.part.FileEditorInput)4 FuzzySearchResult (net.heartsome.cat.common.bean.FuzzySearchResult)3 TranslationUnitAnalysisResult (net.heartsome.cat.common.bean.TranslationUnitAnalysisResult)2 Point (org.eclipse.swt.graphics.Point)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Language (net.heartsome.cat.common.locale.Language)1 WordsFABean (net.heartsome.cat.ts.core.qa.WordsFABean)1 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)1 WordsFAResult (net.heartsome.cat.ts.ui.qa.model.WordsFAResult)1 IFile (org.eclipse.core.resources.IFile)1