use of java.util.Hashtable in project translationstudio8 by heartsome.
the class QuickTranslationImpl method executeTranslation.
/**
* (non-Javadoc)
* @see net.heartsome.cat.ts.tm.complexMatch.AbstractComplexMatch#executeTranslation()
*/
public Vector<AltTransBean> executeTranslation(TransUnitBean transUnitBean, IProject currentProject) {
Vector<AltTransBean> result = new Vector<AltTransBean>();
// 100%以上的记忆库匹配不做快译
if (transUnitBean == null) {
return result;
}
Vector<AltTransBean> tmalt = transUnitBean.getMatchesByToolId(Constants.TM_TOOLID);
if (tmalt.size() < 1) {
return result;
}
AltTransBean tmMatches = tmalt.get(0);
if (tmMatches == null) {
return result;
}
String tmQuality = tmMatches.getMatchProps().get("match-quality");
if (tmQuality.endsWith("%")) {
tmQuality = tmQuality.substring(0, tmQuality.length() - 1);
}
int tmQualityInt = Integer.parseInt(tmQuality);
if (tmQualityInt >= 100) {
return result;
}
String srcLang = tmMatches.getSrcLang();
String tgtLang = tmMatches.getTgtLang();
if (srcLang == null || srcLang.equals("")) {
return result;
}
if (tgtLang == null || tgtLang.equals("")) {
return result;
}
String tmSrcText = tmMatches.getSrcText();
if (tmSrcText == null || tmSrcText.equals("")) {
return result;
}
String tmTgtText = tmMatches.getTgtText();
if (tmTgtText == null || tmTgtText.equals("")) {
return result;
}
String tuSrcText = transUnitBean.getSrcText();
if (tuSrcText == null || tuSrcText.equals("")) {
return result;
}
tbMatcher.setCurrentProject(currentProject);
// 获取翻译单源文中的术语
Vector<Hashtable<String, String>> tuTerms = findTerms(tuSrcText, srcLang, tgtLang);
if (tuTerms.size() == 0) {
return result;
}
// 获取记忆库匹配中的术语
Vector<Hashtable<String, String>> tmTerms = findTerms(tmSrcText, srcLang, tgtLang);
if (tmTerms.size() == 0) {
return result;
}
int tuTermSize = tuTerms.size();
int tmTermSize = tmTerms.size();
if (tuTermSize > tmTermSize) {
int j = 0;
while (j < tuTermSize) {
Hashtable<String, String> tempTuTerm = tuTerms.get(j);
String tmpTuSrcWord = tempTuTerm.get(CON_SRCWORD);
for (Hashtable<String, String> tempTmTerm : tmTerms) {
if (tempTmTerm.get(CON_SRCWORD).equals(tmpTuSrcWord)) {
tuTerms.remove(j);
tmTerms.remove(tempTmTerm);
break;
}
}
tuTermSize = tuTerms.size();
j++;
}
} else {
int j = 0;
while (j < tmTermSize) {
Hashtable<String, String> tempTmTerm = tmTerms.get(j);
String tmpTmSrcWord = tempTmTerm.get(CON_SRCWORD);
for (Hashtable<String, String> tempTuTerm : tuTerms) {
if (tempTuTerm.get(CON_SRCWORD).equals(tmpTmSrcWord)) {
tmTerms.remove(j);
tuTerms.remove(tempTuTerm);
break;
}
}
tmTermSize = tmTerms.size();
j++;
}
}
tuTermSize = tuTerms.size();
tmTermSize = tmTerms.size();
if (tuTermSize == 0 || tmTermSize == 0) {
return result;
}
int replaceSize = tuTermSize < tmTermSize ? tuTermSize : tmTermSize;
for (int i = 0; i < replaceSize; i++) {
Hashtable<String, String> tmTerm = tmTerms.get(i);
String tmTermSrc = tmTerm.get(CON_SRCWORD);
String tmTermTgt = tmTerm.get(CON_TGTWORD);
Hashtable<String, String> tuTerm = tuTerms.get(i);
String tuTermSrc = tuTerm.get(CON_SRCWORD);
String tuTermTgt = tuTerm.get(CON_TGTWORD);
tmSrcText = tmSrcText.replace(tmTermSrc, tuTermSrc);
tmTgtText = tmTgtText.replace(tmTermTgt, tuTermTgt);
}
int quality = MatchQuality.similarity(tuSrcText, tmSrcText);
AltTransBean bean = new AltTransBean(tmSrcText, tmTgtText, srcLang, tgtLang, getMathcerOrigin(), getToolId());
bean.getMatchProps().put("match-quality", quality + "");
bean.setSrcContent(tmSrcText);
bean.setTgtContent(tmTgtText);
bean.getMatchProps().put("hs:matchType", getMatcherType());
result.add(bean);
return result;
}
use of java.util.Hashtable in project translationstudio8 by heartsome.
the class RTFCleanerDialog method handleFile.
/**
* 处理 RTF 文件 ;
*/
private void handleFile() {
FileDialog dialog = new FileDialog(getShell(), SWT.MULTI);
dialog.setText(Messages.getString("dialog.RTFCleanerDialog.dialogTitle"));
String[] extensions = { "*.rtf", "*" };
String[] filters = { Messages.getString("dialog.RTFCleanerDialog.filters1"), Messages.getString("dialog.RTFCleanerDialog.filters2") };
dialog.setFilterExtensions(extensions);
dialog.setFilterNames(filters);
dialog.setFilterPath(System.getProperty("user.home"));
dialog.open();
String[] arrSource = dialog.getFileNames();
if (arrSource == null || arrSource.length == 0) {
return;
}
int errors = 0;
for (int i = 0; i < arrSource.length; i++) {
//$NON-NLS-1$
File f = new File(dialog.getFilterPath() + System.getProperty("file.separator") + arrSource[i]);
Hashtable<String, String> params = new Hashtable<String, String>();
//$NON-NLS-1$
params.put("source", f.getAbsolutePath());
//$NON-NLS-1$
params.put("output", f.getAbsolutePath());
Vector<String> result = RTFCleaner.run(params);
if (!"0".equals(result.get(0))) {
//$NON-NLS-1$
String msg = MessageFormat.format(Messages.getString("dialog.RTFCleanerDialog.msg1"), arrSource[i]) + (String) result.get(1);
MessageDialog.openInformation(getShell(), Messages.getString("dialog.RTFCleanerDialog.msgTitle"), msg);
errors++;
}
}
if (errors < arrSource.length) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.RTFCleanerDialog.msgTitle"), Messages.getString("dialog.RTFCleanerDialog.msg2"));
}
}
use of java.util.Hashtable in project translationstudio8 by heartsome.
the class TBXMakerDialog method maxColumns.
private int maxColumns() throws IOException {
int max = 0;
InputStreamReader input = new InputStreamReader(new FileInputStream(csvPath), encoding);
BufferedReader buffer = new BufferedReader(input);
Hashtable<String, Integer> table1 = new Hashtable<String, Integer>();
String line = buffer.readLine();
while (line != null) {
int i = countColumns(line);
if (table1.containsKey("" + i)) {
int count = table1.get("" + i).intValue() + 1;
table1.put("" + i, new Integer(count));
} else {
table1.put("" + i, new Integer(1));
}
line = buffer.readLine();
}
Enumeration<String> e = table1.keys();
String key = "";
while (e.hasMoreElements()) {
String s = e.nextElement();
int value = table1.get(s).intValue();
if (value > max) {
max = value;
key = s;
}
}
return Integer.parseInt(key);
}
use of java.util.Hashtable in project translationstudio8 by heartsome.
the class CSV2TMXConverterDialog method maxColumns.
private int maxColumns() throws IOException {
int max = 0;
InputStreamReader input = new InputStreamReader(new FileInputStream(csvPath), encoding);
BufferedReader buffer = new BufferedReader(input);
Hashtable<String, Integer> table1 = new Hashtable<String, Integer>();
String line = buffer.readLine();
while (line != null) {
int i = countColumns(line);
if (table1.containsKey("" + i)) {
//$NON-NLS-1$
//$NON-NLS-1$
int count = table1.get("" + i).intValue() + 1;
//$NON-NLS-1$
table1.put("" + i, new Integer(count));
} else {
//$NON-NLS-1$
table1.put("" + i, new Integer(1));
}
line = buffer.readLine();
}
Enumeration<String> e = table1.keys();
//$NON-NLS-1$
String key = "";
while (e.hasMoreElements()) {
String s = e.nextElement();
int value = table1.get(s).intValue();
if (value > max) {
max = value;
key = s;
}
}
return Integer.parseInt(key);
}
use of java.util.Hashtable 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));
}
}
}
}
Aggregations