Search in sources :

Example 11 with QAResultBean

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

the class TagConsistenceQA method startQA.

@Override
public String startQA(QAModel model, IProgressMonitor monitor, IFile iFile, QAXmlHandler xmlHandler, QATUDataBean tuDataBean) {
    if (tuDataBean.getTgtContent() == null || "".equals(tuDataBean.getTgtContent())) {
        return "";
    }
    hasError = false;
    //获取语言对
    String lineNumber = tuDataBean.getLineNumber();
    String rowId = tuDataBean.getRowId();
    String srcContent = tuDataBean.getSrcContent();
    String tgtContent = tuDataBean.getTgtContent();
    if (!(srcContent.indexOf("<") >= 0 || srcContent.indexOf("</") >= 0 || srcContent.indexOf("/>") >= 0) && !(tgtContent.indexOf("<") >= 0 || tgtContent.indexOf("</") >= 0 || tgtContent.indexOf("/>") >= 0)) {
        return "";
    }
    String srcContentXml = "<xml>" + srcContent + "</xml>";
    String tgtContentXml = "<xml>" + tgtContent + "</xml>";
    List<Map<String, String>> sourceTagList = xmlHandler.getTUTag(srcContentXml);
    List<Map<String, String>> targetTagList = xmlHandler.getTUTag(tgtContentXml);
    List<String> loseTag = new LinkedList<String>();
    List<String> changeTag = new LinkedList<String>();
    //开始比较源文本与目标文本标记的不同
    for (int sourceIndex = 0; sourceIndex < sourceTagList.size(); sourceIndex++) {
        Map<String, String> sourceTagMap = sourceTagList.get(sourceIndex);
        String tagName = sourceTagMap.get(QAConstant.QA_TAGNAME);
        String tagContent = sourceTagMap.get(QAConstant.QA_TAGCONTENT);
        //检查目标文本是否有该标记
        boolean hasTag = false;
        boolean tagChanged = false;
        for (int targetIndex = 0; targetIndex < targetTagList.size(); targetIndex++) {
            Map<String, String> targetTagMap = targetTagList.get(targetIndex);
            if (tagName.equals(targetTagMap.get(QAConstant.QA_TAGNAME))) {
                hasTag = true;
                if (!tagContent.equals(targetTagMap.get(QAConstant.QA_TAGCONTENT))) {
                    tagChanged = true;
                } else {
                    targetTagList.remove(targetIndex);
                    tagChanged = false;
                    break;
                }
            }
        }
        //如果该标记不存在,那么就是目标文本中缺失该标记
        if (!hasTag) {
            loseTag.add(tagName);
        }
        //如果有这个标记,但是它的标记内容不正确。
        if (hasTag && tagChanged) {
            changeTag.add(tagName);
        }
    }
    //处理标记缺失的情况
    int loseTagSize;
    if ((loseTagSize = loseTag.size()) > 0) {
        //			String qaTypeText = Messages.getString("qa.TagConsistenceQA.name1");
        //			String tagLoseTip = "";
        //			for (int index = 0; index < loseTagSize; index++) {
        //				tagLoseTip += "'" + loseTag.get(index) + "', ";
        //			}
        //			tagLoseTip = tagLoseTip.substring(0, tagLoseTip.length() - 2);
        //			String errorTip = MessageFormat.format(Messages.getString("qa.TagConsistenceQA.tip1"), tagLoseTip);
        hasError = true;
    }
    //处理标记不一致的情况
    int changeTagSize;
    if ((changeTagSize = changeTag.size()) > 0) {
        //			String qaTypeText = Messages.getString("qa.TagConsistenceQA.name2");
        //			String tagChangeTip = "";
        //			for (int index = 0; index < changeTagSize; index++) {
        //				tagChangeTip += "'" + changeTag.get(index) + "', ";
        //			}
        //			tagChangeTip = tagChangeTip.substring(0, tagChangeTip.length() - 2);
        //			String errorTip = MessageFormat.format(Messages.getString("qa.TagConsistenceQA.tip2"), tagChangeTip);
        hasError = true;
    }
    // 处理译文标记多出的情况
    int moreTagSize;
    if ((moreTagSize = targetTagList.size()) > 0) {
        //			String qaTypeText = Messages.getString("qa.TagConsistenceQA.addName1");
        //			String moreTagTip = "";
        //			for (int index = 0; index < moreTagSize; index++) {
        //				moreTagTip += "'" + targetTagList.get(index).get(QAConstant.QA_TAGNAME) + "', ";
        //			}
        //			moreTagTip = moreTagTip.substring(0, moreTagTip.length() - 2);
        //			String errorTip = MessageFormat.format(Messages.getString("qa.TagConsistenceQA.addTip1"), moreTagTip);
        hasError = true;
    }
    if (hasError) {
        String qaTypeText = Messages.getString("qa.TagConsistenceQA.name2");
        super.printQAResult(new QAResultBean(level, QAConstant.QA_TAG, qaTypeText, null, tuDataBean.getFileName(), lineNumber, srcContent, tgtContent, rowId));
    }
    String result = "";
    if (hasError && level == 0) {
        result = QAConstant.QA_TAG;
    }
    return result;
}
Also used : QAResultBean(net.heartsome.cat.ts.ui.qa.model.QAResultBean) Map(java.util.Map) LinkedList(java.util.LinkedList)

Example 12 with QAResultBean

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

the class TgtTextLengthLimitQA method startQA.

@Override
public String startQA(QAModel model, IProgressMonitor monitor, IFile iFile, QAXmlHandler xmlHandler, QATUDataBean tuDataBean) {
    if (tuDataBean.getTgtContent() == null || "".equals(tuDataBean.getTgtContent())) {
        return "";
    }
    hasError = false;
    String lineNumber = tuDataBean.getLineNumber();
    String qaTypeText = Messages.getString("qa.all.qaItem.TgtTextLengthLimitQA");
    String rowId = tuDataBean.getRowId();
    String srcPureText = tuDataBean.getSrcPureText();
    String tgtPureText = tuDataBean.getTgtPureText();
    int srcTextLength = srcPureText.length();
    int tgtTextLength = tgtPureText.length();
    if (isCheckTgtMaxLength) {
        int maxWidth = (int) (srcTextLength + srcTextLength * maxPercentage);
        if (tgtTextLength > maxWidth) {
            //				String errorTip = MessageFormat.format(Messages.getString("qa.TgtTextLengthLimitQA.tip1"),
            //						new Object[] { tgtTextLength, maxWidth });
            hasError = true;
        }
    }
    if (isCheckTgtMinLength) {
        int minWidth = (int) (srcTextLength - srcTextLength * minPercentage);
        minWidth = minWidth >= 0 ? minWidth : 0;
        if (tgtTextLength < minWidth) {
            //				String errorTip = MessageFormat.format(Messages.getString("qa.TgtTextLengthLimitQA.tip2"),
            //						new Object[] { tgtTextLength, minWidth });
            hasError = true;
        }
    }
    if (hasError) {
        super.printQAResult(new QAResultBean(level, QAConstant.QA_TGTTEXTLENGTHLIMIT, qaTypeText, null, tuDataBean.getFileName(), lineNumber, tuDataBean.getSrcContent(), tuDataBean.getTgtContent(), rowId));
    }
    String result = "";
    if (hasError && level == 0) {
        result = QAConstant.QA_TGTTEXTLENGTHLIMIT;
    }
    return result;
}
Also used : QAResultBean(net.heartsome.cat.ts.ui.qa.model.QAResultBean)

Example 13 with QAResultBean

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

the class QAResultViewPart method locationRow.

/**
	 * 双击或按回车键,将品质检查结果中的数据定位到翻译界面上去。
	 */
public void locationRow() {
    int[] selectRow = table.getRowSelection();
    if (selectRow.length <= 0) {
        return;
    }
    // 获取第一行选择的值
    QAResultBean bean = dataList.get(selectRow[0] - 1);
    // 如果是合并打开的文件
    if (isMultiFile) {
        IXliffEditor xliffEditor = openMultiFilesEditor();
        if (xliffEditor == null) {
            return;
        }
        int lineNumber = xliffEditor.getXLFHandler().getRowIndex(bean.getRowId());
        // 跳转到错误行
        xliffEditor.setFocus();
        xliffEditor.jumpToRow(lineNumber, true);
        return;
    } else {
        // 检查该文件是否已经打开,如果没有打开,就在界面上打开,再返回这个
        IXliffEditor xliffEditor = openEditor(RowIdUtil.getFileNameByRowId(bean.getRowId()));
        if (xliffEditor == null) {
            return;
        }
        int lineNumber = xliffEditor.getXLFHandler().getRowIndex(bean.getRowId());
        // 跳转到错误行
        xliffEditor.setFocus();
        xliffEditor.jumpToRow(lineNumber, false);
    }
}
Also used : QAResultBean(net.heartsome.cat.ts.ui.qa.model.QAResultBean) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) Point(org.eclipse.swt.graphics.Point)

Aggregations

QAResultBean (net.heartsome.cat.ts.ui.qa.model.QAResultBean)13 LinkedList (java.util.LinkedList)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 File (java.io.File)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 NonTransElementOperate (net.heartsome.cat.ts.ui.qa.nonTransElement.NonTransElementOperate)2 IFile (org.eclipse.core.resources.IFile)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Point (org.eclipse.swt.graphics.Point)2 PartInitException (org.eclipse.ui.PartInitException)2 FileOutputStream (java.io.FileOutputStream)1 Hashtable (java.util.Hashtable)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 SingleWord (net.heartsome.cat.ts.core.bean.SingleWord)1 ParaConsisDataBean (net.heartsome.cat.ts.core.qa.ParaConsisDataBean)1 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)1 ExportQAResult (net.heartsome.cat.ts.ui.qa.export.ExportQAResult)1