use of net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean in project translationstudio8 by heartsome.
the class LockTMSegment method searchTmAndLockTu.
/**
* 查询数据库的匹配并且锁定文本段
* @param xlfPath
* @param source_lan
* @param target_lan
* @param srcTextMap
*/
private void searchTmAndLockTu(String xlfPath, String source_lan, String target_lan, Map<String, String> srcTextMap) {
tuInfoBean = new TransUnitInfo2TranslationBean();
String srcContent = srcTextMap.get("content");
if (srcContent == null || "".equals(srcContent)) {
return;
}
tuInfoBean.setNextContext(srcTextMap.get("nextHash"));
tuInfoBean.setPreContext(srcTextMap.get("preHash"));
tuInfoBean.setSrcFullText(srcContent);
tuInfoBean.setSrcLanguage(source_lan);
tuInfoBean.setSrcPureText(srcTextMap.get("pureText"));
tuInfoBean.setTgtLangugage(target_lan);
int a = 1;
List<TranslationUnitAnalysisResult> tmResult = tmMatcher.analysTranslationUnit(curProject, tuInfoBean);
if (tmResult != null && tmResult.size() > 0) {
int similarity = tmResult.get(0).getSimilarity();
if (isLockedContextMatch && similarity == 101) {
xlfHandler.lockTransUnit(xlfPath, "no");
Integer lockedNum = lockedContextResult.get(xlfPath);
if (lockedNum == null) {
lockedContextResult.put(xlfPath, 1);
} else {
lockedContextResult.put(xlfPath, lockedNum + 1);
}
needLockRowIdMap.get(xlfPath).add(srcTextMap.get("rowId"));
} else if (isLockedFullMatch && similarity == 100) {
xlfHandler.lockTransUnit(xlfPath, "no");
Integer lockedNum = lockedFullMatchResult.get(xlfPath);
if (lockedNum == null) {
lockedFullMatchResult.put(xlfPath, 1);
} else {
lockedFullMatchResult.put(xlfPath, lockedNum + 1);
}
needLockRowIdMap.get(xlfPath).add(srcTextMap.get("rowId"));
}
a++;
}
}
use of net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean in project translationstudio8 by heartsome.
the class PreMachineTranslation method keepCurrentMatchs.
private void keepCurrentMatchs(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) {
if (monitor != null && monitor.isCanceled()) {
throw new InterruptedException();
}
if (parameters.isIgnoreLock()) {
// 1、如果忽略锁定文本
String locked = vu.getCurrentElementAttribut("translate", "yes");
if (locked.equals("no")) {
currentCounter.countLockedContextmatch();
continue;
}
}
if (parameters.isIgnoreExactMatch()) {
// 2、如果忽略匹配率
String qualityValue = vu.getElementAttribute("./target", "hs:quality");
if (null != qualityValue && !qualityValue.isEmpty()) {
qualityValue = qualityValue.trim();
if (qualityValue.equals("100") || qualityValue.equals("101")) {
currentCounter.countLockedFullMatch();
continue;
}
}
}
TransUnitInfo2TranslationBean tuInfo = getTransUnitInfo(vu);
if (tuInfo == null) {
continue;
}
tuInfo.setSrcLanguage(srcLang);
tuInfo.setTgtLangugage(tgtLang);
updateXliffFile(vu, tuInfo, xm);
monitor.worked(1);
}
}
use of net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean in project translationstudio8 by heartsome.
the class PreTranslation method keepCurrentMatchs.
private void keepCurrentMatchs(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 needUpdateTgt = true;
while (tuAp.evalXPath() != -1) {
// 循环 Trans-unit
if (monitor != null && monitor.isCanceled()) {
throw new InterruptedException();
}
// skip locked segment
String locked = vu.getCurrentElementAttribut("translate", "yes");
if (locked.equals("no")) {
continue;
}
String tgtContent = vu.getElementContent("./target");
if (tgtContent != null && !tgtContent.trim().equals("")) {
needUpdateTgt = false;
}
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);
updateXliffFile(vu, tuInfo, result, xm, needUpdateTgt);
needUpdateTgt = true;
monitor.worked(1);
}
}
use of net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean in project translationstudio8 by heartsome.
the class WordsFA method matching.
/**
* 开始处理匹配操作 如果返回null,则是用户点击退出按钮,执行退出操作
*/
public Map<String, WordsFAResult> matching(IProgressMonitor monitor) {
int matchTravelTuIndex = 0;
// 字数统计的结果集合
Map<String, WordsFAResult> wordsFAResultMap = new LinkedHashMap<String, WordsFAResult>();
Map<String, ArrayList<String>> languages = handler.getLanguages();
//先对每个文件存放一个结果集
for (IFile iFile : model.getAnalysisIFileList()) {
String filePath = iFile.getLocation().toOSString();
wordsFAResultMap.put(filePath, new WordsFAResult());
}
//针对每一个文件的结果集
WordsFAResult wordFaResult;
for (Entry<String, ArrayList<String>> langEntry : languages.entrySet()) {
String srcLanguage = langEntry.getKey();
for (String tgtLanguage : langEntry.getValue()) {
//针对每个文件,每种语言对获取其内容
allSrcTextsMap = getAllXlfSrcTexts(srcLanguage.toUpperCase(), tgtLanguage.toUpperCase());
// 如果返回的值为空,则标志用户点击了退出操作,那么退出程序
if (allSrcTextsMap == null) {
continue;
}
WordsFABean bean;
List<TranslationUnitAnalysisResult> exterMatchResult = null;
// 字数统计的结果集合
for (Entry<String, Map<String, WordsFABean>> textEntry : allSrcTextsMap.entrySet()) {
String filePath = textEntry.getKey();
IFile iFile = ResourceUtils.fileToIFile(filePath);
// 存储匹配结果的pojo类
wordFaResult = wordsFAResultMap.get(filePath);
Map<String, WordsFABean> fileSrcTextMap = textEntry.getValue();
monitor.setTaskName(MessageFormat.format(Messages.getString("qa.fileAnalysis.WordsFA.tip1"), iFile.getFullPath().toOSString()));
Iterator<Entry<String, WordsFABean>> it = fileSrcTextMap.entrySet().iterator();
while (it.hasNext()) {
Entry<String, WordsFABean> entry = (Entry<String, WordsFABean>) it.next();
matchTravelTuIndex++;
String rowId = entry.getKey();
bean = entry.getValue();
String srcPureText = bean.getSrcPureText();
int textLength = bean.getSrcLength();
String preTextHash = bean.getPreHash();
String nextTextHash = bean.getNextHash();
boolean isLocked = bean.isLocked();
String tagStr = bean.getTagStr();
int wordsCount = CountWord.wordCount(srcPureText, srcLanguage);
//若处于锁定状态,则添加到已锁定字数,然后跳出,执行下一文本段
if (isLocked) {
wordFaResult.setLockedPara(QAConstant.QA_FIRST);
wordFaResult.setLockedWords(wordsCount);
//删除该文本段,不再进行比较
fileSrcTextMap.remove(rowId);
it = fileSrcTextMap.entrySet().iterator();
continue;
}
// UNDO 应先判断数据库是否可用。
// 第一步,进行外部匹配,先封装参数。
tuInfoBean = new TransUnitInfo2TranslationBean();
tuInfoBean.setNextContext(bean.getNextHash());
tuInfoBean.setPreContext(bean.getPreHash());
tuInfoBean.setSrcFullText(bean.getSrcContent());
tuInfoBean.setSrcLanguage(srcLanguage);
tuInfoBean.setSrcPureText(bean.getSrcPureText());
tuInfoBean.setTgtLangugage(tgtLanguage);
exterMatchResult = tmMatcher.analysTranslationUnit(curProject, tuInfoBean);
int exterMatchRate = 0;
if (exterMatchResult != null && exterMatchResult.size() > 0) {
exterMatchRate = exterMatchResult.get(0).getSimilarity();
}
if (exterMatchRate == 100) {
// 如果锁定外部 100% 匹配,那么这些字数将被添加到锁定字数,而非外部 100% 匹配,外部101% 一样
if (model.isLockExter100()) {
wordFaResult.setLockedPara(QAConstant.QA_FIRST);
wordFaResult.setLockedWords(wordsCount);
needLockRowIdList.add(rowId);
} else {
wordFaResult.setExterRepeatPara(QAConstant.QA_FIRST);
wordFaResult.setExterMatchWords(wordsCount);
wordFaResult.setAllExterMatchWords(exterMatchRate, wordsCount);
}
//删除该文本段,不再进行比较
fileSrcTextMap.remove(rowId);
it = fileSrcTextMap.entrySet().iterator();
if (!handler.monitorWork(monitor, matchTravelTuIndex, workInterval, false)) {
return null;
}
continue;
}
if (exterMatchRate == 101) {
if (model.isLockExter101()) {
wordFaResult.setLockedPara(QAConstant.QA_FIRST);
wordFaResult.setLockedWords(wordsCount);
needLockRowIdList.add(rowId);
} else {
wordFaResult.setExterRepeatPara(QAConstant.QA_FIRST);
wordFaResult.setExterMatchWords(wordsCount);
wordFaResult.setAllExterMatchWords(exterMatchRate, wordsCount);
}
//删除该文本段,不再进行比较
fileSrcTextMap.remove(rowId);
it = fileSrcTextMap.entrySet().iterator();
if (!handler.monitorWork(monitor, matchTravelTuIndex, workInterval, false)) {
return null;
}
continue;
}
// 第二步,进行内部匹配
int inteMatchRate = 0;
// 如果要检查内部重复,那么就查找内部匹配
if (interRepeat) {
// 如果不进行内部模糊匹配,那么直接
int interNewWordsMaxMatchRate = interMatch ? newWordsMaxMatchRate : 100;
internalMatching(rowId, srcPureText, tagStr, textLength, preTextHash, nextTextHash, interNewWordsMaxMatchRate);
}
inteMatchRate = bean.getThisMatchRate() > inteMatchRate ? bean.getThisMatchRate() : inteMatchRate;
int maxMacthRate = exterMatchRate > inteMatchRate ? exterMatchRate : inteMatchRate;
if (inteMatchRate == 100 || inteMatchRate == 101) {
if (model.isLockInterRepeat()) {
wordFaResult.setLockedPara(QAConstant.QA_FIRST);
wordFaResult.setLockedWords(wordsCount);
needLockRowIdList.add(rowId);
} else {
wordFaResult.setInterRepeatPara(QAConstant.QA_FIRST);
wordFaResult.setInterMatchWords(wordsCount);
wordFaResult.setAllInterMatchWords(inteMatchRate, wordsCount);
}
} else if (maxMacthRate < newWordsMaxMatchRate) {
//最大匹配小于最小匹配时,就为新字数
wordFaResult.setNewPara(QAConstant.QA_FIRST);
wordFaResult.setNewWords(wordsCount);
} else {
if (inteMatchRate > exterMatchRate) {
// 内部匹配
wordFaResult.setInterMatchPara(QAConstant.QA_FIRST);
wordFaResult.setInterMatchWords(wordsCount);
wordFaResult.setAllInterMatchWords(inteMatchRate, wordsCount);
} else {
//外部匹配
wordFaResult.setExterMatchPara(QAConstant.QA_FIRST);
wordFaResult.setExterMatchWords(wordsCount);
wordFaResult.setAllExterMatchWords(exterMatchRate, wordsCount);
}
}
//删除该文本段,不再进行比较
fileSrcTextMap.remove(rowId);
it = fileSrcTextMap.entrySet().iterator();
if (!handler.monitorWork(monitor, matchTravelTuIndex, workInterval, false)) {
return null;
}
}
wordsFAResultMap.put(filePath, wordFaResult);
}
if (!handler.monitorWork(monitor, matchTravelTuIndex, workInterval, false)) {
return null;
}
}
}
lockRepeatTU(wordsFAResultMap);
return wordsFAResultMap;
}
use of net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean in project translationstudio8 by heartsome.
the class MatchViewPart method selectionChanged.
/**
* 监听XLFEditor的选择事件
*/
public void selectionChanged(final IWorkbenchPart part, final ISelection selection) {
if (part == null || selection == null) {
return;
}
if (!(part instanceof IEditorPart)) {
updateActionState();
return;
}
if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
updateActionState();
return;
}
IXliffEditor editor = (IXliffEditor) part;
IStructuredSelection structuredSelecion = (IStructuredSelection) selection;
final Object object = structuredSelecion.getFirstElement();
if (object instanceof Integer) {
int rowIndex = -1;
int selRowIndex = (Integer) object;
if (rowIndex == selRowIndex) {
if (gridTable.getItemCount() != 0) {
updateActionState();
}
return;
} else {
rowIndex = selRowIndex;
}
XLFHandler handler = editor.getXLFHandler();
String rowId = handler.getRowId(rowIndex);
// handler.getTransUnit(rowId);
TransUnitBean transUnit = editor.getRowTransUnitBean(rowIndex);
if (transUnit == null) {
updateActionState();
return;
}
TransUnitInfo2TranslationBean tuInfoBean = getTuInfoBean(transUnit, handler, rowId);
FileEditorInput input = (FileEditorInput) getSite().getPage().getActiveEditor().getEditorInput();
IProject currentProject = input.getFile().getProject();
copyEnable.resetSelection();
gridTable.removeAll();
altTransCacheList.clear();
menuMgr.setEditor(editor);
menuMgr.setRowIndex(rowIndex);
executeMatch(editor, rowId, transUnit, tuInfoBean, currentProject);
}
}
Aggregations