use of net.heartsome.xml.vtdimpl.VTDUtils in project translationstudio8 by heartsome.
the class XLFHandler method getTUPureText.
/**
* 针对trans-unit节点而言,获取其下source和target节点的纯文本字符串 robert 2011-12-14 (从QAXmlHandler中拷取)
* @param xlfPath
* @param nodeXpath
* @return
*/
public String getTUPureText(VTDNav vn) {
vn.push();
AutoPilot ap = new AutoPilot(vn);
String pureText = "";
try {
VTDUtils vUtils = new VTDUtils(vn);
pureText = vUtils.getElementContent();
// 如果子节点大于0,那继续处理
if (vUtils.getChildElementsCount() > 0) {
ap.resetXPath();
ap.selectXPath("./*");
while (ap.evalXPath() != -1) {
String childNodeName = vUtils.getCurrentElementName();
if (QAConstant.QA_mrk.equals(childNodeName)) {
// "")
if (vUtils.getChildElementsCount() <= 0) {
String childFrag = vUtils.getElementFragment();
String childContent = vUtils.getElementContent();
childContent = childContent == null ? "" : childContent;
pureText = pureText.replace(childFrag, childContent);
} else {
String childFrag = vUtils.getElementFragment();
String childContent = getTUPureText(vn);
childContent = childContent == null ? "" : childContent;
pureText = pureText.replace(childFrag, childContent);
}
} else if (QAConstant.QA_g.equals(childNodeName) || QAConstant.QA_sub.equals(childNodeName)) {
if (vUtils.getChildElementsCount() <= 0) {
String childFrag = vUtils.getElementFragment();
String childContent = vUtils.getElementContent();
childContent = childContent == null ? "" : childContent;
pureText = pureText.replace(childFrag, childContent);
} else {
String childFrag = vUtils.getElementFragment();
String childContent = getTUPureText(vn);
childContent = childContent == null ? "" : childContent;
pureText = pureText.replace(childFrag, childContent);
}
} else {
// ph节点的值为code data或者一个sub节点,因此,要考虑到sub节点的情况
if (vUtils.getChildElementsCount() <= 0) {
String childFrag = vUtils.getElementFragment();
pureText = pureText.replace(childFrag, "");
} else {
String childFrag = vUtils.getElementFragment();
String childContent = getSubNodePureText(vn);
pureText = pureText.replace(childFrag, childContent);
}
}
}
}
} catch (Exception e) {
LOGGER.error("", e);
e.printStackTrace();
} finally {
vn.pop();
}
return pureText;
}
use of net.heartsome.xml.vtdimpl.VTDUtils in project translationstudio8 by heartsome.
the class XLFHandler method deleteSplitInfoParent.
/**
* 删除目标文件的切割信息的父节点<hs:splitInfos>
* @param xlfPath
*/
public void deleteSplitInfoParent(String xlfPath) {
VTDNav vn = vnMap.get(xlfPath);
Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + xlfPath);
try {
// --robert split
String xPath = "/xliff/file/header/hs:splitInfos";
// String xPath = "/xliff/file/header/splitInfos";
VTDUtils vu = new VTDUtils(vn);
AutoPilot ap = new AutoPilot(vn);
ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
XMLModifier xm = vu.delete(ap, null, xPath, VTDUtils.PILOT_TO_END);
saveAndReparse(xm, xlfPath);
} catch (Exception e) {
LOGGER.error("", e);
e.printStackTrace();
}
}
use of net.heartsome.xml.vtdimpl.VTDUtils in project translationstudio8 by heartsome.
the class XLFHandler method getTgtContent.
/**
* 得到目标的完整内容
* @param rowId
* 行的唯一标识
* @return 目标的完整内容;
*/
public String getTgtContent(String rowId) {
String tuXPath = RowIdUtil.parseRowIdToXPath(rowId);
VTDNav vn = getVTDNavByRowId(rowId);
try {
VTDUtils vu = new VTDUtils(vn);
return vu.getValue(tuXPath + "/target/text()");
} catch (NavException e) {
LOGGER.error("", e);
e.printStackTrace();
}
return null;
}
use of net.heartsome.xml.vtdimpl.VTDUtils in project translationstudio8 by heartsome.
the class XLFHandler method getSrcPureText.
/**
* 得到源的纯文本内容
* @param rowId
* 行的唯一标识
* @return 源的纯文本内容;
*/
public String getSrcPureText(String rowId) {
String tuXPath = RowIdUtil.parseRowIdToXPath(rowId);
VTDNav vn = getVTDNavByRowId(rowId);
try {
VTDUtils vu = new VTDUtils(vn);
vn.push();
vu.pilot(tuXPath + "/source");
String result = getTUPureText(vu.getVTDNav());
vn.pop();
return result;
} catch (NavException e) {
LOGGER.error("", e);
e.printStackTrace();
}
return null;
}
use of net.heartsome.xml.vtdimpl.VTDUtils in project translationstudio8 by heartsome.
the class TSFileHandler method analysisStatus.
// 分析文件字数状态。直接返回报告内容的 XML 字符串。
protected String analysisStatus(VTDNav vn, final String filepath, float eqvFactor) throws NavException, XPathParseException, XPathEvalException {
VTDUtils vu = new VTDUtils(vn);
StringBuilder sb = new StringBuilder();
sb.append("\t<status-infos purpose=\"");
sb.append(Messages.getString("file.TSFileHandler.analysisStatus"));
sb.append("\" filepath=\"" + filepath + "\">\n");
// 新文本段。无内外匹配、无内外重复的文本段。
int newSegs = 0;
// 内部匹配。所有来自文件内互相比较产生的繁殖匹配,即包含有 autoFazzy_
int innerMatchSegs = 0;
// 前缀的匹配。
// 外部匹配。所有来自记忆库的翻译匹配,即不包含 autoFazzy_ 前缀的匹配。
int outerMatchSegs = 0;
// 内部重复。所有在同批分析的其它 XLIFF 文件中的重复。
int innerRepeatedSegs = 0;
// 外部重复。所有来自记忆库匹配的 100% 匹配,UE 版以下的包括上下文匹配。
int outerRepeatedSegs = 0;
int countSegs = 0;
int newWords = 0;
int innerMatchWords = 0;
int outerMatchWords = 0;
int innerRepeatedWords = 0;
int outerRepeatedWords = 0;
int countWords = 0;
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath("//trans-unit");
while (ap.evalXPath() != -1) {
String tgtText = vu.getChildPureText("target");
vn.push();
// 开始统计分析。
String srcText = vu.getChildPureText("source");
String lang = vu.getElementAttribute("source", "xml:lang");
int words = wordCount(srcText, lang);
vn.pop();
}
sb.append("\t</status-infos>\n");
return sb.toString();
}
Aggregations