use of net.heartsome.cat.ts.core.bean.FuzzyTransDataBean in project translationstudio8 by heartsome.
the class RepeatRowSearcher method getRepeateRowsForFuzzy.
/**
* 针对繁殖翻译,获取所有满足条件的rowId
*/
public static Map<String, List<String>> getRepeateRowsForFuzzy(XLFHandler handler) {
Map<String, List<String>> resultMap = new LinkedHashMap<String, List<String>>();
// 获取当前界面上所显示的所有行的 rowId
ArrayList<String> rowIdList = handler.getRowIds();
Map<String, FuzzyTransDataBean> srcTextMap = handler.getAllSrcTextForFuzzy(rowIdList, ignoreTag);
// 排序
List<Map.Entry<String, FuzzyTransDataBean>> mapList = new ArrayList<Map.Entry<String, FuzzyTransDataBean>>(srcTextMap.entrySet());
Map<String, FuzzyTransDataBean> sameMap = new LinkedHashMap<String, FuzzyTransDataBean>();
for (int i = 0; i < mapList.size(); i++) {
Entry<String, FuzzyTransDataBean> entry = mapList.get(i);
FuzzyTransDataBean bean = entry.getValue();
boolean isSame = false;
sameMap.clear();
for (int j = i + 1; j < mapList.size(); j++) {
Entry<String, FuzzyTransDataBean> curEntry = mapList.get(j);
FuzzyTransDataBean curBean = curEntry.getValue();
if (bean.getSrcText().equalsIgnoreCase(curBean.getSrcText())) {
if (!isSame) {
sameMap.put(entry.getKey(), bean);
}
isSame = true;
sameMap.put(curEntry.getKey(), curBean);
mapList.remove(j);
j--;
}
}
ananysisFuzzyDataMap(sameMap, resultMap);
}
return resultMap;
}
use of net.heartsome.cat.ts.core.bean.FuzzyTransDataBean in project translationstudio8 by heartsome.
the class RepeatRowSearcher method ananysisFuzzyDataMap.
/**
* 处理源文相同的文本段。得到要进行繁殖翻译的 rowId
* @param sameMap
* @param resultMap
*/
private static void ananysisFuzzyDataMap(Map<String, FuzzyTransDataBean> sameMap, Map<String, List<String>> resultMap) {
// 先获取目标文本不为空的文本段。以最后一个为主
String rootRowId = "";
for (Entry<String, FuzzyTransDataBean> entry : sameMap.entrySet()) {
if (!entry.getValue().isTgtNull()) {
rootRowId = entry.getKey();
}
}
if ("".equals(rootRowId)) {
return;
}
List<String> childRowIdList = new ArrayList<String>();
for (Entry<String, FuzzyTransDataBean> entry : sameMap.entrySet()) {
FuzzyTransDataBean bean = entry.getValue();
if (bean.isTgtNull() && !bean.isLock()) {
childRowIdList.add(entry.getKey());
}
}
if (childRowIdList.size() > 0) {
resultMap.put(rootRowId, childRowIdList);
}
}
use of net.heartsome.cat.ts.core.bean.FuzzyTransDataBean in project translationstudio8 by heartsome.
the class XLFHandler method getAllSrcTextForFuzzy.
/**
* 针对繁殖翻译。获取所有的源文。robert 2012-09-20
* @return
*/
public Map<String, FuzzyTransDataBean> getAllSrcTextForFuzzy(ArrayList<String> rowIdList, boolean ignoreTag) {
Map<String, FuzzyTransDataBean> textMap = new LinkedHashMap<String, FuzzyTransDataBean>();
try {
VTDNav vn = null;
AutoPilot ap = new AutoPilot();
VTDUtils vUtils = new VTDUtils();
AutoPilot childAp = new AutoPilot();
for (String rowId : rowIdList) {
// 标识译文是否为空,如果为空,则为true,不为空则为 false
boolean isTargetNull = false;
// 是否锁定
boolean isLock = false;
vn = getVTDNavByRowId(rowId).duplicateNav();
ap.bind(vn);
vUtils.bind(vn);
childAp.bind(vn);
vn.push();
ap.selectXPath(RowIdUtil.parseRowIdToXPath(rowId));
if (ap.evalXPath() != -1) {
// 如果,当前文本段是处于锁定状态的,就不用获取
int index = vn.getAttrVal("translate");
if (index != -1 && "no".equalsIgnoreCase(vn.toString(index))) {
isLock = true;
}
String srcText = null;
vn.push();
childAp.selectXPath("./source");
if (childAp.evalXPath() != -1) {
// 如果忽略标记的话,就没有必要获取source节点的完整内容了
if (!ignoreTag) {
srcText = vUtils.getElementContent();
} else {
srcText = getTUPureText(vn);
}
}
vn.pop();
vn.push();
childAp.selectXPath("./target[text()!='' or *]");
if (childAp.evalXPath() != -1) {
isTargetNull = false;
} else {
isTargetNull = true;
}
vn.pop();
// 存放值
textMap.put(rowId, new FuzzyTransDataBean(srcText.trim(), isTargetNull, isLock));
}
vn.pop();
}
} catch (Exception e) {
e.printStackTrace();
}
return textMap;
}
Aggregations