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