Search in sources :

Example 6 with ISimpleMatcher

use of net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher in project translationstudio8 by heartsome.

the class PreMachineTranslation method executeSimpleMatch.

/**
	 * 访问机器翻译API
	 * @param vu
	 * @param tuInfo
	 * @param xm
	 * @return
	 * @throws XPathParseException
	 * @throws XPathEvalException
	 * @throws NavException
	 *             ;
	 */
private String executeSimpleMatch(VTDUtils vu, TransUnitInfo2TranslationBean tuInfo, XMLModifier xm) throws XPathParseException, XPathEvalException, NavException {
    StringBuffer bf = new StringBuffer();
    for (ISimpleMatcher matcher : simpleMatchers) {
        // 1、是否支持预存机器翻译
        if (!matcher.isSuportPreTrans()) {
            continue;
        }
        String toolId = matcher.getMathcerToolId();
        vu.getVTDNav().push();
        AutoPilot ap = new AutoPilot(vu.getVTDNav());
        ap.selectXPath("./alt-trans[@tool-id='" + toolId + "']");
        // 3、 是否有预存翻译,有预存的机器翻译,不进行预存
        if (ap.evalXPath() != -1) {
            vu.getVTDNav().pop();
            continue;
        }
        vu.getVTDNav().pop();
        String tgtText = matcher.executeMatch(tuInfo);
        if (tgtText.equals("")) {
            continue;
        }
        AltTransBean bean = new AltTransBean(tuInfo.getSrcPureText(), tgtText, tuInfo.getSrcLanguage(), tuInfo.getTgtLangugage(), matcher.getMathcerOrigin(), matcher.getMathcerToolId());
        bean.getMatchProps().put("match-quality", "100");
        bean.setSrcContent(tuInfo.getSrcPureText());
        bean.setTgtContent(tgtText);
        bean.getMatchProps().put("hs:matchType", matcher.getMatcherType());
        bf.append(bean.toXMLString());
    }
    return bf.toString();
}
Also used : AltTransBean(net.heartsome.cat.ts.core.bean.AltTransBean) ISimpleMatcher(net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher) AutoPilot(com.ximpleware.AutoPilot)

Example 7 with ISimpleMatcher

use of net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher in project translationstudio8 by heartsome.

the class PreMachineTranslation method getMacthers.

private List<ISimpleMatcher> getMacthers() {
    List<ISimpleMatcher> spMatchers = SimpleMatcherFactory.getInstance().getCuurentMatcher();
    List<ISimpleMatcher> useableSimeMathers = new ArrayList<ISimpleMatcher>();
    if (parameters.isBingTranslate()) {
        // 1、是否勾选bing翻译
        for (ISimpleMatcher matcher : spMatchers) {
            if (matcher.getMathcerOrigin().equals("Bing Translation")) {
                useableSimeMathers.add(matcher);
                break;
            }
        }
    }
    if (parameters.isGoogleTranslate()) {
        // 2、是否勾选google翻译
        for (ISimpleMatcher matcher : spMatchers) {
            if (matcher.getMathcerOrigin().equals("Google Translation")) {
                useableSimeMathers.add(matcher);
                break;
            }
        }
    }
    return useableSimeMathers;
}
Also used : ISimpleMatcher(net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher) ArrayList(java.util.ArrayList)

Example 8 with ISimpleMatcher

use of net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher in project translationstudio8 by heartsome.

the class TranslationTaskContainer method pushTranslationTask.

public synchronized void pushTranslationTask(TranslationTaskData data) {
    Object matcher = data.getMatcher();
    if (matcher instanceof ISimpleMatcher) {
        ISimpleMatcher _matcher = (ISimpleMatcher) matcher;
        for (TranslationTaskData d : dataList) {
            Object m = d.getMatcher();
            if (m instanceof ISimpleMatcher) {
                ISimpleMatcher _m = (ISimpleMatcher) m;
                if (_m.getMathcerToolId().equals(_matcher.getMathcerToolId())) {
                    return;
                }
            }
        }
    } else if (matcher instanceof IComplexMatch) {
        IComplexMatch _matcher = (IComplexMatch) matcher;
        for (TranslationTaskData d : dataList) {
            Object m = d.getMatcher();
            if (m instanceof IComplexMatch) {
                IComplexMatch _m = (IComplexMatch) m;
                if (_m.getToolId().equals(_matcher.getToolId())) {
                    return;
                }
            }
        }
    }
    dataList.add(0, data);
}
Also used : IComplexMatch(net.heartsome.cat.ts.tm.complexMatch.IComplexMatch) ISimpleMatcher(net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher)

Aggregations

ISimpleMatcher (net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher)8 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)4 MatchViewPart (net.heartsome.cat.ts.ui.translation.view.MatchViewPart)4 IEditorPart (org.eclipse.ui.IEditorPart)4 IViewPart (org.eclipse.ui.IViewPart)4 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)4 AutoPilot (com.ximpleware.AutoPilot)2 AltTransBean (net.heartsome.cat.ts.core.bean.AltTransBean)2 PrefrenceParameters (net.heartsome.cat.ts.machinetranslation.bean.PrefrenceParameters)2 ArrayList (java.util.ArrayList)1 SimpleMatcherBingImpl (net.heartsome.cat.ts.bingtrans.SimpleMatcherBingImpl)1 PrefrenceParameters (net.heartsome.cat.ts.bingtrans.bean.PrefrenceParameters)1 SimpleMatcherGoogleImpl (net.heartsome.cat.ts.googletrans.SimpleMatcherGoogleImpl)1 PrefrenceParameters (net.heartsome.cat.ts.googletrans.bean.PrefrenceParameters)1 SimpleMatcherBingImpl (net.heartsome.cat.ts.machinetranslation.SimpleMatcherBingImpl)1 SimpleMatcherGoogleImpl (net.heartsome.cat.ts.machinetranslation.SimpleMatcherGoogleImpl)1 IComplexMatch (net.heartsome.cat.ts.tm.complexMatch.IComplexMatch)1