Search in sources :

Example 1 with QAXmlHandler

use of net.heartsome.cat.ts.core.qa.QAXmlHandler in project translationstudio8 by heartsome.

the class QualityAssurance method beginMultiFileQA.

/**
	 * 开始处理多个合并打开文件的品质检查,由于合并打开文件的处理,是个很特殊的例子,因为处理对像不再是单个文件,而是针对语言对。
	 * @param qaResult ;
	 */
public void beginMultiFileQA(final QAResult qaResult) {
    this.qaResult = qaResult;
    handler = new QAXmlHandler();
    Job job = new Job(Messages.getString("qa.all.qa")) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            long time1 = System.currentTimeMillis();
            int fileNum = model.getQaXlfList().size();
            // 定义的进度条总共五格,其中,解析文件1格,进行检查9格
            monitor.beginTask(Messages.getString("qa.QualityAssurance.tip1"), fileNum * 10);
            //先将所有的文件进行解析
            if (!openFile(monitor)) {
                monitor.done();
                return Status.CANCEL_STATUS;
            }
            if (model.getQaXlfList().size() == 0) {
                MessageDialog.openInformation(shell, _INFO, Messages.getString("qa.QualityAssurance.tip2"));
                return Status.CANCEL_STATUS;
            }
            initWorkInterval();
            int allTUSize = handler.getAllTUSize();
            //遍历tu节点的序列号
            int traversalTuIndex = 0;
            IProgressMonitor subMonitor = new SubProgressMonitor(monitor, fileNum * 9, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
            subMonitor.beginTask("", allTUSize % workInterval == 0 ? (allTUSize / workInterval) : (allTUSize / workInterval) + 1);
            QARealization realization = null;
            Map<String, ArrayList<String>> languageList = handler.getLanguages();
            int lineNumber = 0;
            IFile iFile;
            for (Entry<String, ArrayList<String>> langEntry : languageList.entrySet()) {
                String srcLang = langEntry.getKey();
                for (String tgtLang : langEntry.getValue()) {
                    List<String> rowIdsList = handler.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 = handler.getFilteredTUText(filePath, RowIdUtil.parseRowIdToXPath(rowId), model.getNotInclude());
                        if (tuDataBean == null) {
                            if (!monitorWork(subMonitor, traversalTuIndex, false)) {
                                closeDB();
                                return Status.CANCEL_STATUS;
                            }
                            continue;
                        }
                        if (!tuDataBean.isPassFilter()) {
                            if (!monitorWork(subMonitor, traversalTuIndex, false)) {
                                closeDB();
                                return Status.CANCEL_STATUS;
                            }
                            continue;
                        }
                        tuDataBean.setLineNumber(lineNumber + "");
                        tuDataBean.setFileName(iFile.getName());
                        tuDataBean.setSrcLang(srcLang);
                        tuDataBean.setTgtLang(tgtLang);
                        for (int i = 0; i < model.getBatchQAItemIdList().size(); i++) {
                            final String qaItemId = model.getBatchQAItemIdList().get(i);
                            realization = getClassInstance(qaItemId);
                            // 若没有该项检查的实例,提示出错
                            if (realization == null) {
                                Display.getDefault().asyncExec(new Runnable() {

                                    public void run() {
                                        MessageDialog.openError(shell, _ERROR, MessageFormat.format(Messages.getString("qa.QualityAssurance.tip4"), new Object[] { model.getQaItemId_Name_Class().get(qaItemId).get(QAConstant.QA_ITEM_NAME) }));
                                    }
                                });
                                closeDB();
                                return Status.CANCEL_STATUS;
                            }
                            // 开始进行该项文件的该项检查
                            final String result = realization.startQA(model, subMonitor, iFile, handler, tuDataBean);
                            // // 当未设置术语库、拼写检查词典配置 错误时才会返回 null,所以这时可以直接删。
                            if (result == null) {
                                model.getBatchQAItemIdList().remove(qaItemId);
                                i--;
                            }
                            if (monitor.isCanceled()) {
                                return Status.CANCEL_STATUS;
                            }
                        }
                        qaResult.sendDataToViewer(null);
                        if (!monitorWork(subMonitor, traversalTuIndex, false)) {
                            closeDB();
                            return Status.CANCEL_STATUS;
                        }
                    }
                }
                if (!monitorWork(subMonitor, traversalTuIndex, true)) {
                    closeDB();
                    return Status.CANCEL_STATUS;
                }
            }
            closeDB();
            qaResult.informQAEndFlag();
            subMonitor.done();
            monitor.done();
            System.out.println("所用时间为" + (System.currentTimeMillis() - time1));
            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 : 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) 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)

Example 2 with QAXmlHandler

use of net.heartsome.cat.ts.core.qa.QAXmlHandler in project translationstudio8 by heartsome.

the class AutomaticQA method setInitData.

public void setInitData(XLFHandler handler) {
    this.handler = handler;
    preferenceStore = Activator.getDefault().getPreferenceStore();
    model = new QAModel();
    window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    filterMap = getNotIncludePara();
    root = ResourcesPlugin.getWorkspace().getRoot();
    xmlHandler = new QAXmlHandler();
    // 存储品质检查的检查项
    model.setBatchQAItemIdList(getAutoQAItems());
    // 存储品质检查的检查时不包括的文本段
    model.setNotInclude(filterMap);
    model.setShell(window.getShell());
    XLIFFEditorImplWithNatTable nattable = XLIFFEditorImplWithNatTable.getCurrent();
    boolean isMultiFile = nattable.isMultiFile();
    if (isMultiFile) {
        model.setMuliFiles(true);
        IFile multiTempIFile = ((FileEditorInput) nattable.getEditorInput()).getFile();
        ArrayList<IFile> selectIFiles = (ArrayList<IFile>) ResourceUtils.filesToIFiles(nattable.getMultiFileList());
        model.setMultiOper(new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles, multiTempIFile));
    } else {
        model.setMuliFiles(false);
    }
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) QAXmlHandler(net.heartsome.cat.ts.core.qa.QAXmlHandler) ArrayList(java.util.ArrayList) MultiFilesOper(net.heartsome.cat.ts.ui.util.MultiFilesOper) QAModel(net.heartsome.cat.ts.ui.qa.model.QAModel)

Example 3 with QAXmlHandler

use of net.heartsome.cat.ts.core.qa.QAXmlHandler in project translationstudio8 by heartsome.

the class AspellConfig method getConfiguration.

/**
	 * 获取aspell配置,比如aspell安装路径,编码等
	 * @param shell2
	 * @param _configFile
	 */
private void getConfiguration(String aspellConfigFile) {
    try {
        QAXmlHandler handler = new QAXmlHandler();
        Map<String, Object> newResultMap = handler.openFile(aspellConfigFile);
        // 针对退出解析
        if (newResultMap != null && QAConstant.RETURNVALUE_RESULT_RETURN.equals(newResultMap.get(QAConstant.RETURNVALUE_RESULT))) {
            return;
        }
        commandLine = handler.getNodeText(aspellConfigFile, "/aspell/commandLine", "");
        if (!commandLine.equals("")) {
            if (handler.getNodeText(aspellConfigFile, "/aspell/utf8", "yes").equals("yes")) {
                utf8 = true;
            } else {
                utf8 = false;
            }
        } else {
            utf8 = false;
        }
        dictionaryList = handler.getAspellDictionaries(aspellConfigFile);
    } catch (Exception e) {
        e.printStackTrace();
        logger.error(Messages.getString("qa.spellCheck.all.log2"), e);
    }
}
Also used : QAXmlHandler(net.heartsome.cat.ts.core.qa.QAXmlHandler) IOException(java.io.IOException)

Example 4 with QAXmlHandler

use of net.heartsome.cat.ts.core.qa.QAXmlHandler in project translationstudio8 by heartsome.

the class FileAnalysisHandler method analysisFile.

/**
	 * 准备分析文件
	 */
public void analysisFile(String title) {
    final QAXmlHandler handler = new QAXmlHandler();
    Job job = new Job(title) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            // 要分析的文件的个数
            int fileNum = model.getAnalysisIFileList().size();
            model.setSubFileNum(fileNum);
            // 定义的进度条总共四格,其中,解析文件一格,分析文件三格
            monitor.beginTask("", fileNum * 4);
            // 解析文件,如果解析不成功,退出程序, 解析要分析的文件,用掉fileNum*1个格子
            if (!openXliff(handler, monitor)) {
                monitor.done();
                return Status.CANCEL_STATUS;
            }
            if (model.getAnalysisIFileList().size() == 0) {
                MessageDialog.openInformation(shell, Messages.getString("qa.all.dialog.info"), Messages.getString("qa.handlers.FileAnalysisHandler.tip4"));
                return Status.CANCEL_STATUS;
            }
            // 填充要分析文件的所有trans-unit节点个数的总和
            model.setAllTuSize(allTUSize);
            FileAnalysis fileAnalysis = getClassInstance(faItemId);
            // 分析文件用去fileNum*3个格子
            IProgressMonitor subMonitor = new SubProgressMonitor(monitor, fileNum * 3, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
            int analysisResult = fileAnalysis.beginAnalysis(model, subMonitor, handler);
            if (analysisResult == -1 || analysisResult == QAConstant.QA_ZERO) {
                return Status.CANCEL_STATUS;
            }
            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 : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) QAXmlHandler(net.heartsome.cat.ts.core.qa.QAXmlHandler) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Job(org.eclipse.core.runtime.jobs.Job) FileAnalysis(net.heartsome.cat.ts.core.qa.FileAnalysis) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 5 with QAXmlHandler

use of net.heartsome.cat.ts.core.qa.QAXmlHandler 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

QAXmlHandler (net.heartsome.cat.ts.core.qa.QAXmlHandler)7 IFile (org.eclipse.core.resources.IFile)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)4 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)4 Job (org.eclipse.core.runtime.jobs.Job)4 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)4 ArrayList (java.util.ArrayList)3 QATUDataBean (net.heartsome.cat.ts.core.qa.QATUDataBean)3 IOException (java.io.IOException)2 FileAnalysis (net.heartsome.cat.ts.core.qa.FileAnalysis)1 NumberConsistenceQA (net.heartsome.cat.ts.ui.qa.NumberConsistenceQA)1 TagConsistenceQA (net.heartsome.cat.ts.ui.qa.TagConsistenceQA)1 QAModel (net.heartsome.cat.ts.ui.qa.model.QAModel)1 MultiFilesOper (net.heartsome.cat.ts.ui.util.MultiFilesOper)1 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)1 FileEditorInput (org.eclipse.ui.part.FileEditorInput)1