Search in sources :

Example 1 with NumberConsistenceQA

use of net.heartsome.cat.ts.ui.qa.NumberConsistenceQA in project translationstudio8 by heartsome.

the class NumberOrTagConsisQAHandler method beginQA.

private void beginQA(final ArrayList<IFile> selectIFiles, final QAModel model, final boolean isNumberQA, final QAResult qaResult) {
    final String titile = isNumberQA ? Messages.getString("qa.NumberOrTagConsisQAHandler.jobTitle1") : Messages.getString("qa.NumberOrTagConsisQAHandler.jobTitle2");
    Job job = new Job(titile) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            // 解析一格,其余九格
            monitor.beginTask(titile, 10 * selectIFiles.size());
            xmlHandler = new QAXmlHandler();
            // 首先解析文件,如果为false,则退出
            if (!openFile(selectIFiles, monitor)) {
                return Status.OK_STATUS;
            }
            int allTUSize = 0;
            for (IFile iFile : selectIFiles) {
                allTUSize += xmlHandler.getTuSizeMap().get(iFile.getLocation().toOSString());
            }
            initWorkInterval(allTUSize);
            // 开始进行数据处理
            IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 9, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
            subMonitor.beginTask(titile + "...", allTUSize % workInterval == 0 ? (allTUSize / workInterval) : (allTUSize / workInterval) + 1);
            Map<String, ArrayList<String>> languageList = xmlHandler.getLanguages();
            int lineNumber = 0;
            int traversalTuIndex = 0;
            IFile iFile;
            for (Entry<String, ArrayList<String>> langEntry : languageList.entrySet()) {
                String srcLang = langEntry.getKey();
                for (String tgtLang : langEntry.getValue()) {
                    List<String> rowIdsList = xmlHandler.getAllRowIdsByLanguages(srcLang.toUpperCase(), tgtLang.toUpperCase());
                    model.setRowIdsList(rowIdsList);
                    // 开始针对每一个文本段进行检查
                    for (String rowId : rowIdsList) {
                        traversalTuIndex++;
                        // 行号
                        lineNumber = rowIdsList.indexOf(rowId) + 1;
                        String filePath = RowIdUtil.getFileNameByRowId(rowId);
                        iFile = ResourceUtils.fileToIFile(filePath);
                        String langPair = srcLang + Hyphen + tgtLang;
                        QATUDataBean tuDataBean = xmlHandler.getFilteredTUText(filePath, RowIdUtil.parseRowIdToXPath(rowId), model.getNotInclude());
                        if (tuDataBean == null) {
                            if (!xmlHandler.monitorWork(subMonitor, traversalTuIndex, workInterval, false)) {
                                return Status.CANCEL_STATUS;
                            }
                            continue;
                        }
                        if (!tuDataBean.isPassFilter()) {
                            if (!xmlHandler.monitorWork(subMonitor, traversalTuIndex, workInterval, false)) {
                                return Status.CANCEL_STATUS;
                            }
                            continue;
                        } else if (tuDataBean.getTgtContent() == null || "".equals(tuDataBean.getTgtContent())) {
                            // 因为文本段完整性检查要判断译文是否为空的情况,所以,如果译文为空,只有文本段完整性要进行检查,其他检查项都跳过。
                            continue;
                        }
                        tuDataBean.setLineNumber(lineNumber + "");
                        tuDataBean.setFileName(iFile.getName());
                        tuDataBean.setSrcLang(srcLang);
                        tuDataBean.setTgtLang(tgtLang);
                        if (isNumberQA) {
                            NumberConsistenceQA numberQA = new NumberConsistenceQA();
                            qaResult.setMultiOper(model.getMultiOper());
                            numberQA.setQaResult(qaResult);
                            numberQA.startQA(model, subMonitor, iFile, xmlHandler, tuDataBean);
                        } else {
                            TagConsistenceQA tagQA = new TagConsistenceQA();
                            qaResult.setMultiOper(model.getMultiOper());
                            tagQA.setQaResult(qaResult);
                            tagQA.startQA(model, subMonitor, iFile, xmlHandler, tuDataBean);
                        }
                        qaResult.sendDataToViewer(null);
                        if (!xmlHandler.monitorWork(subMonitor, traversalTuIndex, workInterval, false)) {
                            return Status.CANCEL_STATUS;
                        }
                    }
                }
                if (!xmlHandler.monitorWork(subMonitor, traversalTuIndex, workInterval, false)) {
                    return Status.CANCEL_STATUS;
                }
            }
            qaResult.informQAEndFlag();
            subMonitor.done();
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    // 当程序退出时,检测当前 job 是否正常关闭
    CommonFunction.jobCantCancelTip(job);
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void running(IJobChangeEvent event) {
            ProgressIndicatorManager.displayProgressIndicator();
            super.running(event);
        }

        @Override
        public void done(IJobChangeEvent event) {
            ProgressIndicatorManager.hideProgressIndicator();
            super.done(event);
        }
    });
    job.setUser(true);
    job.schedule();
}
Also used : NumberConsistenceQA(net.heartsome.cat.ts.ui.qa.NumberConsistenceQA) IFile(org.eclipse.core.resources.IFile) QATUDataBean(net.heartsome.cat.ts.core.qa.QATUDataBean) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) QAXmlHandler(net.heartsome.cat.ts.core.qa.QAXmlHandler) ArrayList(java.util.ArrayList) TagConsistenceQA(net.heartsome.cat.ts.ui.qa.TagConsistenceQA) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

ArrayList (java.util.ArrayList)1 QATUDataBean (net.heartsome.cat.ts.core.qa.QATUDataBean)1 QAXmlHandler (net.heartsome.cat.ts.core.qa.QAXmlHandler)1 NumberConsistenceQA (net.heartsome.cat.ts.ui.qa.NumberConsistenceQA)1 TagConsistenceQA (net.heartsome.cat.ts.ui.qa.TagConsistenceQA)1 IFile (org.eclipse.core.resources.IFile)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 Job (org.eclipse.core.runtime.jobs.Job)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1