use of net.heartsome.cat.ts.core.bean.SingleWord 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.core.bean.SingleWord in project translationstudio8 by heartsome.
the class SpellQA method getSingleWords.
/**
* 获取单个单词,这里面主要是根据不同的选项。得到要进行拼写检查的单词
*/
private void getSingleWords(String pureText, List<SingleWord> tgtWordList) {
stringToken = new StringTokenizer(pureText, Constant.SEPARATORS, false);
List<Integer[]> ignoreParaList = null;
// 如果要处理忽略非译元素,那么执行如下操作 (备注:所有的忽略项。只是针对 hunspell)
if (isHunspell && ignoreNontrans) {
ignoreParaList = nontransOper.getIgnorePara(pureText, null);
}
int start = 0;
int length = 0;
int end = 0;
while (stringToken.hasMoreTokens()) {
String pureWord = stringToken.nextToken();
start = pureText.indexOf(pureWord, start);
length = pureWord.length();
end = start + length;
// 经过一系列的判断,从而删除一些不符合标准的单词。将剩下的单词传入拼写检查器中进行检查
if (isHunspell) {
// 是否忽略非译元素
if (ignoreNontrans) {
boolean needIgnore = false;
for (Integer[] ignoreIndexs : ignoreParaList) {
if (start >= ignoreIndexs[0] && end <= ignoreIndexs[1]) {
needIgnore = true;
break;
}
}
if (needIgnore) {
start = start + pureWord.length();
continue;
}
}
// 是否忽略首字母为数字
if (ignoreDigitalFirst && checkDigitalFirst(pureWord)) {
start = start + pureWord.length();
continue;
}
// 是否忽略首字母为大写
if (ignoreUpperCaseFirst && checkUpperCaseFirst(pureWord)) {
start = start + pureWord.length();
continue;
}
//是否忽略全大写单词
if (ignoreAllUpperCase && checkAllUpperCase(pureWord)) {
start = start + pureWord.length();
continue;
}
}
tgtWordList.add(new SingleWord(null, pureWord, start, length));
start = start + pureWord.length();
}
}
use of net.heartsome.cat.ts.core.bean.SingleWord in project translationstudio8 by heartsome.
the class RealTimeSpellCheck method getSingleWords.
/**
* 获取单个单词,这里面主要是根据不同的选项。得到要进行拼写检查的单词
*/
private void getSingleWords(String tgtText, List<SingleWord> tgtWordList) {
stringToken = new StringTokenizer(tgtText, Constant.SEPARATORS, false);
List<Integer[]> ignoreParaList = null;
// 如果要处理忽略非译元素,那么执行如下操作 (备注:所有的忽略项。只是针对 hunspell)
if (isHunspell && ignoreNontrans) {
List<Integer> tagPositionList = getTagPosition(tgtText);
String pureText = PlaceHolderEditModeBuilder.PATTERN.matcher(tgtText).replaceAll("");
ignoreParaList = nontransOper.getIgnorePara(pureText, tagPositionList);
}
int start = 0;
int length = 0;
int end = 0;
while (stringToken.hasMoreTokens()) {
String word = stringToken.nextToken();
String pureWord = PlaceHolderEditModeBuilder.PATTERN.matcher(word).replaceAll("");
start = tgtText.indexOf(word, start);
length = word.length();
end = start + length;
// 经过一系列的判断,从而删除一些不符合标准的单词。将剩下的单词传入拼写检查器中进行检查
if (isHunspell) {
// 是否忽略非译元素
if (ignoreNontrans) {
boolean needIgnore = false;
for (Integer[] ignoreIndexs : ignoreParaList) {
if (start >= ignoreIndexs[0] && end <= ignoreIndexs[1]) {
needIgnore = true;
break;
}
}
if (needIgnore) {
start = start + word.length();
continue;
}
}
// 是否忽略首字母为数字
if (ignoreDigitalFirst && checkDigitalFirst(pureWord)) {
start = start + word.length();
continue;
}
// 是否忽略首字母为大写
if (ignoreUpperCaseFirst && checkUpperCaseFirst(pureWord)) {
start = start + word.length();
continue;
}
//是否忽略全大写单词
if (ignoreAllUpperCase && checkAllUpperCase(pureWord)) {
start = start + word.length();
continue;
}
}
tgtWordList.add(new SingleWord(word, pureWord, start, length));
start = start + word.length();
}
}
use of net.heartsome.cat.ts.core.bean.SingleWord in project translationstudio8 by heartsome.
the class AspellChecker method parseSuggestions.
/**
* 分解查询结果,将错误单词添加到结果集中
* 查询结果如:& yayay 62 1: Maya, ayah, ya, Yalu, Yuan, yaws, yuan, yaw, 第二个值为错误单词,第三个值为建议单词个数,第四个值为该单词起始下标(从1开始的)
* @param line ;
*/
private void parseSuggestions(String line) {
StringTokenizer st = new StringTokenizer(line);
if (st.hasMoreTokens()) {
st.nextToken();
st.nextToken();
st.nextToken();
int start = -1;
if (st.hasMoreTokens()) {
// 备注,aspell 的查询结果,每个单词的起始坐标是从 1 开始的
start = Integer.parseInt(st.nextToken().replace(":", "")) - 1;
} else {
return;
}
int startAdd = 0;
if (tagPositionList != null) {
// 将标记放回去,使每个非译片段回复之前未去标记的状态
for (Integer tagIndex : tagPositionList) {
if (start > tagIndex) {
startAdd++;
}
}
start = start + startAdd;
}
boolean exsit = false;
for (SingleWord word : wordList) {
if (word.getStart() == start) {
errorWords.add(word);
exsit = true;
break;
}
}
if (!exsit) {
logger.error("Aspell check error.");
}
}
}
use of net.heartsome.cat.ts.core.bean.SingleWord in project translationstudio8 by heartsome.
the class HsMultiCellEditorControl method tgtTextRealTimeSpellCheck.
/**
* 当文本处于正在编辑时,实时进行拼写检查,<div style='color:red'>该方法与{@link #tgtTextFirstRealTimeSpellCheck} 类似</div>
*/
private static void tgtTextRealTimeSpellCheck(final String tgtLang, final HsMultiCellEditor targetEditor) {
final StyledTextCellEditor tgtEditor = targetEditor.getCellEditor();
final StyledText text = tgtEditor.getSegmentViewer().getTextWidget();
if (tgtLang == null) {
return;
}
text.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
String tgtText = text.getText();
if (tgtText.isEmpty()) {
return;
}
String endStr = tgtText.substring(tgtText.length() - 1, tgtText.length());
if (endStr.matches(ENDREGEX)) {
List<SingleWord> errorWordList = new LinkedList<SingleWord>();
errorWordList = spellTrigger.getErrorWords(tgtText, tgtLang);
if (errorWordList != null && errorWordList.size() > 0) {
targetEditor.highLightedErrorWord(tgtText, errorWordList);
} else {
targetEditor.refreshErrorWordsStyle(null);
}
}
}
});
}
Aggregations