use of net.heartsome.cat.ts.ui.qa.model.QAResultBean in project translationstudio8 by heartsome.
the class ParagraphConsistenceQA method compareNext.
/**
* 与其他文本段进行比较,获取相关值
* @param rowId
*/
private void compareNext(String rowId) {
// 先比较相同源文不同译文的情况
String sameSrcQaTypeText = Messages.getString("qa.ParagraphConsistenceQA.name1");
String mergeRowId = CommonFunction.createUUID();
for (int i = 0; i < srcRowIdList.size(); i++) {
// 如果该文本段存在与其他文本段的相同源文不同译文,那么就进行处理
List<String> curList = srcRowIdList.get(i);
if (curList.contains(rowId)) {
// 循环比较,找出源文相同,译文不同的文本段
List<Integer> sameSourceData = new LinkedList<Integer>();
for (String rowId_1 : curList) {
sameSourceData.clear();
ParaConsisDataBean bean_1 = dataMap.get(rowId_1);
String tgtText_1 = srcIgnoreTag ? bean_1.getTgtPureText() : bean_1.getTgtContent();
for (String rowId_2 : curList) {
if (rowId_2.equals(rowId_1)) {
continue;
}
ParaConsisDataBean bean_2 = dataMap.get(rowId_2);
String tgtText_2 = srcIgnoreTag ? bean_2.getTgtPureText() : bean_2.getTgtContent();
if (!checkEquals(tgtText_2, tgtText_1, srcIgnoreCase)) {
sameSourceData.add(bean_2.getLineNumber());
}
}
if (sameSourceData.size() > 0) {
int lineNum = bean_1.getLineNumber();
// String notSameTip = "";
// for (int k = 0; k < sameSourceData.size(); k++) {
// int k_lineNum = sameSourceData.get(k);
// notSameTip += MessageFormat.format(Messages.getString("qa.ParagraphConsistenceQA.tip1"), k_lineNum);
// }
// notSameTip = notSameTip.length() > 0 ? notSameTip.substring(0, notSameTip.length() - 1): notSameTip;
//
// String errorTip = Messages.getString("qa.ParagraphConsistenceQA.tip2");
// errorTip += Messages.getString("qa.ParagraphConsistenceQA.tip3");
// errorTip += notSameTip;
// errorTip += Messages.getString("qa.ParagraphConsistenceQA.tip4");
super.printQAResult(new QAResultBean(level, QAConstant.QA_PARAGRAPH, sameSrcQaTypeText, mergeRowId, new File(RowIdUtil.getFileNameByRowId(rowId_1)).getName(), lineNum + "", bean_1.getSrcContent(), bean_1.getTgtContent(), rowId_1));
}
}
srcRowIdList.remove(curList);
i--;
}
}
// 再比较相同译文不同源文的情况
mergeRowId = CommonFunction.createUUID();
String sameTgtQaTypeText = Messages.getString("qa.ParagraphConsistenceQA.name2");
for (int i = 0; i < tgtRowIdList.size(); i++) {
// 如果该文本段存在与其他文本段的相同源文不同译文,那么就进行处理
List<String> curList = tgtRowIdList.get(i);
if (curList.contains(rowId)) {
// 循环比较,找出源文相同,译文不同的文本段
List<Integer> sameTargetData = new LinkedList<Integer>();
for (String rowId_1 : curList) {
sameTargetData.clear();
ParaConsisDataBean bean_1 = dataMap.get(rowId_1);
String srcText_1 = tgtIgnoreTag ? bean_1.getSrcPureText() : bean_1.getSrcContent();
for (String rowId_2 : curList) {
if (rowId_2.equals(rowId_1)) {
continue;
}
ParaConsisDataBean bean_2 = dataMap.get(rowId_2);
String srcText_2 = tgtIgnoreTag ? bean_2.getSrcPureText() : bean_2.getSrcContent();
if (!checkEquals(srcText_2, srcText_1, tgtIgnoreCase)) {
sameTargetData.add(bean_2.getLineNumber());
}
}
if (sameTargetData.size() > 0) {
int lineNum = bean_1.getLineNumber();
// String notSameTip = "";
// for (int k = 0; k < sameTargetData.size(); k++) {
// int k_lineNum = sameTargetData.get(k);
// notSameTip += MessageFormat.format(Messages.getString("qa.ParagraphConsistenceQA.tip1"), k_lineNum);
// }
// notSameTip = notSameTip.length() > 0 ? notSameTip.substring(0, notSameTip.length() - 1): notSameTip;
//
// String errorTip = Messages.getString("qa.ParagraphConsistenceQA.tip2");
// errorTip += Messages.getString("qa.ParagraphConsistenceQA.tip3");
// errorTip += notSameTip;
// errorTip += Messages.getString("qa.ParagraphConsistenceQA.tip5");
super.printQAResult(new QAResultBean(level, QAConstant.QA_PARAGRAPH, sameTgtQaTypeText, mergeRowId, new File(RowIdUtil.getFileNameByRowId(rowId_1)).getName(), "" + lineNum, bean_1.getSrcContent(), bean_1.getTgtContent(), rowId_1));
}
}
tgtRowIdList.remove(curList);
i--;
}
}
}
use of net.heartsome.cat.ts.ui.qa.model.QAResultBean in project translationstudio8 by heartsome.
the class SpellQA method startQA.
@Override
public String startQA(final QAModel model, IProgressMonitor monitor, IFile iFile, QAXmlHandler xmlHandler, QATUDataBean tuDataBean) {
if (tuDataBean.getTgtContent() == null || "".equals(tuDataBean.getTgtContent())) {
return "";
}
if (monitor == null) {
monitor = new NullProgressMonitor();
}
hasError = false;
isContinue = false;
//目标语言
final String tgtLang = tuDataBean.getTgtLang();
//若未配置该目标语言的词典,退出程序的执行
if (nonSpellTarLangList.indexOf(tgtLang) != -1) {
return "";
}
String tgtPureText = TextUtil.resetSpecialString(tuDataBean.getTgtPureText());
String lineNumber = tuDataBean.getLineNumber();
String rowId = tuDataBean.getRowId();
if (spelling == null) {
if (isHunspell) {
spelling = new Hunspell(model.getShell());
if (ignoreNontrans) {
nontransOper = new NonTransElementOperate();
nontransOper.openNonTransDB();
}
} else {
spelling = new AspellChecker();
}
}
// 若拼写检查器错误,或者出错,返回 null
if (spelling == null || spelling.isError()) {
return null;
}
//如果该拼写检查实例为空,退出执行,并且下次遇到相同目标语言不再检查
if (!spelling.checkLangAvailable(tgtLang)) {
nonSpellTarLangList.add(tgtLang);
if (!isHunspell) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
String message = Messages.getString("qa.SpellQA.addTip1");
message = MessageFormat.format(message, new Object[] { tgtLang });
isContinue = MessageDialog.openConfirm(model.getShell(), Messages.getString("qa.all.dialog.confirm"), message);
}
});
if (!isContinue) {
monitor.setCanceled(true);
}
}
return "";
}
List<SingleWord> errorWords;
if (isHunspell) {
LinkedList<SingleWord> wordList = new LinkedList<SingleWord>();
getSingleWords(tgtPureText, wordList);
errorWords = spelling.getErrorWords(null, wordList, tgtLang);
} else {
LinkedList<SingleWord> wordList = new LinkedList<SingleWord>();
getSingleWords(tgtPureText, wordList);
errorWords = spelling.getErrorWords(tgtPureText, wordList, tgtLang);
}
if (spelling.isError()) {
return null;
}
//开始输入结果
if (errorWords == null || errorWords.size() == 0) {
return "";
}
String qaTypeText = Messages.getString("qa.all.qaItem.SpellQA");
// String errorTip = Messages.getString("qa.SpellQA.tip1");
// for (int i = 0; i < errorWords.size(); i++) {
// errorTip += "'" + errorWords.get(i).getPureWord() + "' 、";
// }
// errorTip = errorTip.substring(0, errorTip.length() - 1);
// errorTip += Messages.getString("qa.SpellQA.tip2");
hasError = true;
super.printQAResult(new QAResultBean(level, QAConstant.QA_SPELL, qaTypeText, null, tuDataBean.getFileName(), lineNumber, tuDataBean.getSrcContent(), tuDataBean.getTgtContent(), rowId));
String result = "";
if (hasError && level == 0) {
result = QAConstant.QA_SPELL;
}
return result;
}
use of net.heartsome.cat.ts.ui.qa.model.QAResultBean in project translationstudio8 by heartsome.
the class TermConsistenceQA method compareTerms.
/**
* 比较术语
* @param iFile 要检查的文件
* @param handler xml文件操作类
*/
private void compareTerms(IFile iFile, QAXmlHandler xmlHandler, QATUDataBean tuDataBean) {
String srcLang = tuDataBean.getSrcLang();
String tgtLang = tuDataBean.getTgtLang();
boolean souTerm_Context = getContext(srcLang);
boolean tarTerm_Context = getContext(tgtLang);
String sourceText = TextUtil.resetSpecialString(tuDataBean.getSrcPureText());
String targetText = TextUtil.resetSpecialString(tuDataBean.getTgtPureText());
targetText = TextUtil.normalise(targetText, true);
// targetText = TextUtil.cleanString(targetText);
sourceText = TextUtil.normalise(sourceText, true);
// sourceText = TextUtil.cleanString(sourceText);
Vector<Hashtable<String, String>> termsVector = matcher.serachTransUnitTerms(sourceText, srcLang, tgtLang, false);
String lineNumber = tuDataBean.getLineNumber();
String rowId = tuDataBean.getRowId();
//开始循环术语库中的术语,进行比较
for (int termIndex = 0; termIndex < termsVector.size(); termIndex++) {
String sourceTerm = termsVector.get(termIndex).get("srcWord");
String targetTerm = termsVector.get(termIndex).get("tgtWord");
if (containsTerm(sourceText, sourceTerm, souTerm_Context)) {
if (!containsTerm(targetText, targetTerm, tarTerm_Context)) {
// String errorTip = MessageFormat.format(Messages.getString("qa.TermConsistenceQA.tip1"),
// new Object[] { "'" + sourceTerm + "'", "'" + targetTerm + "'" });
hasError = true;
String qaTypeText = Messages.getString("qa.all.qaItem.TermConsistenceQA");
super.printQAResult(new QAResultBean(level, QAConstant.QA_TERM, qaTypeText, null, tuDataBean.getFileName(), lineNumber, tuDataBean.getSrcContent(), tuDataBean.getTgtContent(), rowId));
}
}
}
}
use of net.heartsome.cat.ts.ui.qa.model.QAResultBean in project translationstudio8 by heartsome.
the class NonTranslationQA 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;
if (nonTransElementsMap == null) {
//非译元素库的操作类
NonTransElementOperate operater = new NonTransElementOperate();
//先打开库
operater.openNonTransDB();
//开始从非译元素库中获取相关信息
nonTransElementsMap = operater.getNonTransElements();
}
srcNonTransData = new LinkedList<String>();
tgtNonTransData = new LinkedList<String>();
//获取纯文本
String sourceText = tuDataBean.getSrcPureText();
String targetText = tuDataBean.getTgtPureText();
String rowId = tuDataBean.getRowId();
srcLang = tuDataBean.getSrcLang();
tgtLang = tuDataBean.getTgtLang();
// UNDO 这里存在一个问题,就是web地址检查与ip地址检查的语句差不多,故存在会引起一个非译元素会同时被检查并多次提示。
for (int index = 0; index < nonTransElementsMap.size(); index++) {
NontransElementBean elementBean = nonTransElementsMap.get(index);
String elementContent = elementBean.getContent();
String elementRegular = elementBean.getRegular();
matchNontrans(sourceText, targetText, elementContent, elementRegular);
}
// UNDO 非译元素检查时,把数字也检查出来了
String lineNumber = tuDataBean.getLineNumber();
String fileName = tuDataBean.getFileName();
String qaTypeText = Messages.getString("qa.all.qaItem.NonTranslationQA");
//处理源文中的非译元素在译文中丢失的情况
if (srcNonTransData.size() > 0) {
String nonTransStr = "";
for (int index = 0; index < srcNonTransData.size(); index++) {
nonTransStr += "'" + srcNonTransData.get(index) + "', ";
}
nonTransStr = nonTransStr.substring(0, nonTransStr.length() - 2);
// String errorTip = MessageFormat.format(Messages.getString("qa.NonTranslationQA.tip1"), nonTransStr);
hasError = true;
}
//处理译文中的非译元素在源文中丢失的情况
if (tgtNonTransData.size() > 0) {
String nonTransStr = "";
for (int index = 0; index < tgtNonTransData.size(); index++) {
nonTransStr += "'" + tgtNonTransData.get(index) + "', ";
}
nonTransStr = nonTransStr.substring(0, nonTransStr.length() - 2);
// String errorTip = MessageFormat.format(Messages.getString("qa.NonTranslationQA.tip2"), nonTransStr);
hasError = true;
}
if (hasError) {
super.printQAResult(new QAResultBean(level, QAConstant.QA_NONTRANSLATION, qaTypeText, null, fileName, lineNumber, sourceText, targetText, rowId));
}
String result = "";
if (hasError && level == 0) {
result = QAConstant.QA_NONTRANSLATION;
}
return result;
}
use of net.heartsome.cat.ts.ui.qa.model.QAResultBean in project translationstudio8 by heartsome.
the class NumberConsistenceQA 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 srcPureText = tuDataBean.getSrcPureText();
String tgtPureText = tuDataBean.getTgtPureText();
String pattern = "-?\\d{1,}(\\.?\\d{1,})?";
Pattern patt = Pattern.compile(pattern);
//获取源文本中的所有数字
Matcher matcher = patt.matcher(srcPureText);
List<String> sourceNumbers = new LinkedList<String>();
while (matcher.find()) {
sourceNumbers.add(matcher.group());
}
//获取目标文本中的数字
matcher = patt.matcher(tgtPureText);
List<String> targetNumbers = new LinkedList<String>();
while (matcher.find()) {
targetNumbers.add(matcher.group());
}
String lineNumber = tuDataBean.getLineNumber();
String rowId = tuDataBean.getRowId();
String qaTypeText = Messages.getString("qa.all.qaItem.NumberConsistenceQA");
Map<String, List<String>> resultMap = compareNumber(sourceNumbers, targetNumbers);
if (resultMap.get("source") != null && resultMap.get("source").size() > 0) {
//输出数字一致性中目标文件所遗失的数字
List<String> resultList = resultMap.get("source");
String resultStr = "";
for (int index = 0; index < resultList.size(); index++) {
resultStr += "'" + resultList.get(index) + "', ";
}
if (resultStr.length() > 0) {
resultStr = resultStr.substring(QAConstant.QA_ZERO, resultStr.length() - QAConstant.QA_TWO);
// String errorTip = MessageFormat.format(Messages.getString("qa.NumberConsistenceQA.tip1"), resultStr);
hasError = true;
}
}
//输出数字一致性检查中目标文件中多出的数字
if (resultMap.get("target") != null && resultMap.get("target").size() > 0) {
//输出数字一致性中目标文件所遗失的数字
List<String> resultList = resultMap.get("target");
String resultStr = "";
for (int index = 0; index < resultList.size(); index++) {
resultStr += "'" + resultList.get(index) + "', ";
}
if (resultStr.length() > 0) {
resultStr = resultStr.substring(QAConstant.QA_ZERO, resultStr.length() - QAConstant.QA_TWO);
// String errorTip = MessageFormat.format(Messages.getString("qa.NumberConsistenceQA.tip2"), resultStr);
hasError = true;
}
}
if (hasError) {
super.printQAResult(new QAResultBean(level, QAConstant.QA_NUMBER, qaTypeText, null, tuDataBean.getFileName(), lineNumber, tuDataBean.getSrcContent(), tuDataBean.getTgtContent(), rowId));
}
String result = "";
if (hasError && level == 0) {
result = QAConstant.QA_NUMBER;
}
return result;
}
Aggregations