use of net.heartsome.cat.ts.core.bean.AltTransBean in project translationstudio8 by heartsome.
the class XLFHandler method getTransUnit.
/**
* 获取指定索引的翻译单元对象。
* @param rowId
* 行的唯一标识,由三部分拼成
*/
public TransUnitBean getTransUnit(String rowId) {
if (tuSizeMap == null || rowId == null) {
return null;
}
String tuNode = RowIdUtil.parseRowIdToXPath(rowId);
if (tuNode == null) {
return null;
}
VTDUtils vu = null;
VTDNav vn = getVTDNavByRowId(rowId);
try {
vu = new VTDUtils(vn);
} catch (NavException e1) {
String errorMsg = Messages.getString("file.XLFHandler.logger4");
LOGGER.error(errorMsg, e1);
return null;
}
try {
if (vu.pilot(tuNode) != -1) {
// 导航到 trans-unit 节点
String tuid = "";
String srcText = "";
String srcContent = "";
String tgtText = "";
String tgtContent = "";
Hashtable<String, String> srcProps = new Hashtable<String, String>();
Hashtable<String, String> tgtProps = new Hashtable<String, String>();
// 取翻译单元所有属性
vn.push();
Hashtable<String, String> tuProps = vu.getCurrentElementAttributs();
vn.pop();
if (tuProps != null) {
tuid = tuProps.get("id");
}
AutoPilot ap = new AutoPilot(vn);
ap.declareXPathNameSpace("xml", VTDUtils.XML_NAMESPACE_URL);
ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
// 取翻译单元源节点完整文本,含内部标记。
vn.push();
if (vu.pilot(ap, "./source") != -1) {
// 导航到 Source 子节点
// 源节点完整内容。
srcContent = vu.getElementContent();
// 源节点纯文本内容。
srcText = getTUPureText(vu.getVTDNav());
// 源节点属性集合。
srcProps = vu.getCurrentElementAttributs();
}
ap.resetXPath();
vn.pop();
// 取翻译单元目标节点完整文本,含内部标记。
vn.push();
if (vu.pilot(ap, "./target") != -1) {
// 导航到 Target 子节点
// 目标节点完整内容。
tgtContent = vu.getElementContent();
// 目标节点纯文本内容。
tgtText = getTUPureText(vu.getVTDNav());
// 目标节点属性集合。
tgtProps = vu.getCurrentElementAttributs();
}
vn.pop();
// 获取所有的 alttrans 匹配节点。
vn.push();
Vector<AltTransBean> matches = getAltTrans(vu);
vn.pop();
// 构建翻译单元对象,存储节点信息
TransUnitBean tub = new TransUnitBean(tuid, srcContent, srcText);
tub.setTuProps(tuProps);
tub.setSrcProps(srcProps);
tub.setTgtContent(tgtContent);
tub.setTgtText(tgtText);
tub.setTgtProps(tgtProps);
tub.setMatches(matches);
vn.push();
tub.setNotes(getNotes(vu));
vn.pop();
vn.push();
tub.setPropgroups(getPrpoGroups(vu));
vn.pop();
return tub;
}
} catch (XPathEvalException e) {
String errorMsg = Messages.getString("file.XLFHandler.logger5");
LOGGER.error(errorMsg, e);
return null;
} catch (NavException e) {
String errorMsg = Messages.getString("file.XLFHandler.logger6");
LOGGER.error(errorMsg, e);
return null;
} catch (XPathParseException e) {
String errorMsg = Messages.getString("file.XLFHandler.logger7");
LOGGER.error(errorMsg, e);
return null;
}
return null;
}
use of net.heartsome.cat.ts.core.bean.AltTransBean in project translationstudio8 by heartsome.
the class TmUtils method altTransInfoConverter.
/**
* 将从库中获取的匹配转成以 AltTransBean 封装的匹配数据,在转换的过程与当前 AltTrans重复的记录将被忽略
* @param dbMatches
* 从数据库中获取的匹配
* @param currentAltTrans
* 当前已经存原altTrans
* @return 和当前匹配不重复的AltTrans集;
*/
public static Vector<AltTransBean> altTransInfoConverter(List<FuzzySearchResult> dbMatches, Vector<AltTransBean> currentAltTrans) {
Vector<AltTransBean> altTrans = new Vector<AltTransBean>();
Vector<AltTransBean> existAltTrans = new Vector<AltTransBean>();
for (FuzzySearchResult result : dbMatches) {
AltTransBean atb = new AltTransBean();
// Map<String, String> match = tu.getTuInfo();
TmxTU tu = result.getTu();
// 获取源节点内容、属性及纯文本
atb.setSrcText(tu.getSource().getPureText());
atb.setTgtText(tu.getTarget().getPureText());
if (isMatchExist(currentAltTrans, atb, result.getDbName(), existAltTrans)) {
continue;
}
Hashtable<String, String> matchProps = new Hashtable<String, String>();
matchProps.put("match-quality", result.getSimilarity() + "");
matchProps.put("origin", result.getDbName());
matchProps.put("tool-id", "Translation Memory");
matchProps.put("hs:matchType", "TM");
matchProps.put("xml:space", "default");
atb.setMatchProps(matchProps);
Hashtable<String, String> srcProps = new Hashtable<String, String>();
srcProps.put("xml:lang", tu.getSource().getLangCode());
atb.setSrcProps(srcProps);
atb.setSrcContent(tu.getSource().getFullText());
Hashtable<String, String> tgtProps = new Hashtable<String, String>();
tgtProps.put("xml:lang", tu.getTarget().getLangCode());
atb.setTgtProps(tgtProps);
atb.setTgtContent(tu.getTarget().getFullText());
Vector<PropGroupBean> pgs = new Vector<PropGroupBean>();
Vector<PropBean> props = new Vector<PropBean>();
PropBean pb = new PropBean("creationId", tu.getCreationUser());
props.add(pb);
pb = new PropBean("creationDate", tu.getCreationDate());
props.add(pb);
pb = new PropBean("changeId", tu.getChangeUser());
props.add(pb);
pb = new PropBean("changeDate", tu.getChangeDate());
props.add(pb);
List<TmxProp> attrValList = tu.getProps();
for (TmxProp attr : attrValList) {
String name = attr.getName();
if (name == null || name.equals("")) {
continue;
}
String value = attr.getValue();
if (value == null || value.equals("")) {
continue;
}
PropBean prop = new PropBean(name, value);
props.add(prop);
}
PropGroupBean pg = new PropGroupBean(props);
// 获取属性组名称。
pg.setName("hs:prop-group");
pgs.add(pg);
atb.setPropGroups(pgs);
altTrans.add(atb);
}
if (altTrans.size() > 0) {
altTrans.addAll(existAltTrans);
} else {
currentAltTrans.addAll(existAltTrans);
}
return altTrans;
}
use of net.heartsome.cat.ts.core.bean.AltTransBean in project translationstudio8 by heartsome.
the class TmUtils method isMatchExist.
/**
* 判断当的匹配中是否已经存在了
* @param altTransVector
* 匹配集,已经存在的
* @param currAltTrans
* 当前匹配
* @return ;
*/
public static boolean isMatchExist(Vector<AltTransBean> altTransVector, AltTransBean currAltTrans, String currDbName, Vector<AltTransBean> dubliAlttrans) {
String src = currAltTrans.getSrcText();
String tgt = currAltTrans.getTgtText();
if (src == null || src.equals("") || tgt == null || tgt.equals("")) {
// 忽略源文为空,译文为空的匹配
return true;
}
for (int i = 0; i < altTransVector.size(); i++) {
AltTransBean existAltTrans = altTransVector.get(i);
String existSrc = existAltTrans.getSrcText();
String existTgt = existAltTrans.getTgtText();
if (existSrc == null || existTgt == null) {
// 当前匹配源文、译文为空将忽略配置
continue;
}
if (existSrc.trim().equals(src.trim()) && existTgt.trim().equals(tgt.trim())) {
dubliAlttrans.add(existAltTrans);
altTransVector.remove(i);
return true;
}
String existDbName = existAltTrans.getMatchProps().get("origin");
if (existSrc.trim().equals(src.trim()) && !existTgt.trim().equals(tgt.trim()) && existDbName.equals(currDbName)) {
altTransVector.remove(i);
i--;
}
}
return false;
}
use of net.heartsome.cat.ts.core.bean.AltTransBean in project translationstudio8 by heartsome.
the class TmUtils method checkMatchQuality.
/**
* 检查所有的匹配是否符合最低匹配率
* @param newAltTrans
* @param minQuality ;
*/
public static Vector<AltTransBean> checkMatchQuality(Vector<AltTransBean> newAltTrans, int minQuality) {
Vector<AltTransBean> result = new Vector<AltTransBean>();
for (AltTransBean bean : newAltTrans) {
String qualityStr = bean.getMatchProps().get("match-quality").trim();
if (qualityStr == null) {
continue;
}
if (qualityStr.endsWith("%")) {
qualityStr = qualityStr.substring(0, qualityStr.lastIndexOf("%"));
}
Integer q = Integer.parseInt(qualityStr);
if (q >= minQuality) {
result.add(bean);
}
}
return result;
}
Aggregations