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();
}
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;
}
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);
}
Aggregations