use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class QAXmlHandler method getTUTag.
/**
* 获取trans-unit节点下source与target节点的标记信息,如果节点不存在,或者为空,则返回null
* @param xlfPath
* @param nodeXPath
* @return
*/
public List<Map<String, String>> getTUTag(String xlfPath, String nodeXPath) {
VTDNav vn = vnMap.get(xlfPath);
Assert.isNotNull(vn, Messages.getString("qa.QAXmlHandler.msg1") + xlfPath);
try {
AutoPilot ap = apMap.get(xlfPath);
VTDUtils vUtils = new VTDUtils(vn);
ap.selectXPath(nodeXPath);
while (ap.evalXPath() != -1) {
String nodeContent = vUtils.getElementContent();
if (nodeContent == null || "".equals(nodeContent)) {
return null;
}
//开始获取所有的标记
return getTUTag(vn);
}
} catch (Exception e) {
e.printStackTrace();
logger.error(Messages.getString("qa.QAXmlHandler.logger18"), e);
}
return null;
}
use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class QAXmlHandler method getNodePureText.
/**
* 获取一个节点的纯文本,将所有的标记除外,包括标记里面的内容
* @return
*/
public String getNodePureText(String xlfPath, String nodeXpath) {
String pureText = "";
VTDNav vn = vnMap.get(xlfPath);
AutoPilot ap = apMap.get(xlfPath);
validNull(vn, ap, xlfPath);
try {
VTDUtils vUtils = new VTDUtils(vn);
ap.selectXPath(nodeXpath);
while (ap.evalXPath() != -1) {
pureText = vUtils.getElementPureText();
}
} catch (Exception e) {
e.printStackTrace();
logger.error(Messages.getString("qa.QAXmlHandler.logger14"), e);
}
return pureText;
}
use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class QAXmlHandler method getHunspellAvailableLang.
/**
* 获取 hunspell 所支持的语言 2013-01-15
* @param xmlPath
* @return
*/
public Map<String, String> getHunspellAvailableLang(String xmlPath) {
Map<String, String> langMap = new HashMap<String, String>();
VTDGen vg = new VTDGen();
if (!vg.parseFile(xmlPath, true)) {
logger.error("Hunspell 语言管理文件破损,无法解析。");
return null;
}
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
AutoPilot childAP = new AutoPilot(vn);
String xpath = "/config/language";
try {
ap.selectXPath(xpath);
while (ap.evalXPath() != -1) {
String code = null;
String dictionary = null;
vn.push();
childAP.selectXPath("./isoCode");
if (childAP.evalXPath() != -1) {
if (vn.getText() != -1) {
code = vn.toRawString(vn.getText());
}
}
vn.pop();
vn.push();
childAP.selectXPath("./dict");
if (childAP.evalXPath() != -1) {
if (vn.getText() != -1) {
dictionary = vn.toRawString(vn.getText());
}
}
vn.pop();
if (code != null && dictionary != null && !"".equals(code) && !"".equals(dictionary)) {
langMap.put(code, dictionary);
}
}
} catch (Exception e) {
logger.error("Hunspell 语言管理文件内容获取失败!", e);
}
return langMap;
}
use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class QAXmlHandler method getEditProgressData.
/**
* 针对文件分析的翻译进度分析,获取每个节点的未翻译文本段数、字数,已翻译文本段数、字数。
* 如果返回为null,则标志用户退出分析
* @param filePath 要处理的文件的路径
* @param monitor 进度条
* @param ignoreTag 是否忽略标记
* @param workInterval 进度条前进一格的间隔
* @param traversalTuIndex 循环trans-unit节点的序列号
* @return editProgDataMap,下面是其健值对详解
* key: notApprovedParas --> 未批准文本段数
* key: approvedParas --> 已批准文本段数
* key: notApprovedWords --> 未批准字数
* key: approvedWords --> 已批准字数
*/
public Map<String, Integer> getEditProgressData(String filePath, IProgressMonitor monitor, int workInterval, int traversalTuIndex) {
Map<String, Integer> editProgDataMap = new HashMap<String, Integer>();
int notApprovedParas = 0;
int approvedParas = 0;
int lockedParas = 0;
int notApprovedWords = 0;
int approvedWords = 0;
int lockedWords = 0;
try {
VTDNav vn = vnMap.get(filePath);
Assert.isNotNull(vn, Messages.getString("qa.QAXmlHandler.msg1") + filePath);
AutoPilot ap = new AutoPilot(vn);
VTDUtils vUtils = new VTDUtils(vn);
AutoPilot sourceAp = new AutoPilot(vn);
sourceAp.selectXPath("./source[text()!='' or ./*]");
String srcLang = vUtils.getElementAttribute("/xliff/file[1]", "source-language");
ap.selectXPath(XPATH_ALL_TU);
while (ap.evalXPath() != -1) {
traversalTuIndex++;
int curWordsNum = 0;
//判断是否锁定
boolean isLocked = false;
int inx = vn.getAttrVal("translate");
if (inx != -1 && "no".equals(vn.toString(inx))) {
isLocked = true;
}
//根据是否忽略标记,获取源文本的字数
vn.push();
if (sourceAp.evalXPath() != -1) {
String sourceText = getTUPureText(vn);
curWordsNum = CountWord.wordCount(sourceText, srcLang);
}
sourceAp.resetXPath();
vn.pop();
String approved = "";
int approveIndex = vn.getAttrVal("approved");
if (approveIndex != -1) {
approved = vn.toString(approveIndex);
}
if ("yes".equals(approved)) {
approvedParas++;
approvedWords += curWordsNum;
} else {
notApprovedParas++;
notApprovedWords += curWordsNum;
}
if (!monitorWork(monitor, traversalTuIndex, workInterval, false)) {
return null;
}
if (isLocked) {
lockedParas++;
lockedWords += curWordsNum;
}
}
} catch (Exception e) {
if (!monitorWork(monitor, traversalTuIndex, workInterval, false)) {
return null;
}
e.printStackTrace();
logger.error(MessageFormat.format(Messages.getString("qa.QAXmlHandler.logger24"), filePath), e);
}
editProgDataMap.put("notApprovedParas", notApprovedParas);
editProgDataMap.put("approvedParas", approvedParas);
editProgDataMap.put("lockedParas", lockedParas);
editProgDataMap.put("notApprovedWords", notApprovedWords);
editProgDataMap.put("approvedWords", approvedWords);
editProgDataMap.put("lockedWords", lockedWords);
return editProgDataMap;
}
use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class XLFHandler method getFileCountInXliff.
/**
* 得到 File 节点个数(此方法仅用于解析单个文件时)
* @return ;
*/
public int getFileCountInXliff(String fileName) {
VTDNav vn = vnMap.get(fileName);
Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + fileName);
AutoPilot ap = new AutoPilot(vn);
try {
ap.selectXPath("count(/xliff/file)");
// 整个 xliff 文件中的
int countAllFile = (int) ap.evalXPathToNumber();
// file 节点的个数
return countAllFile;
} catch (XPathParseException e) {
LOGGER.error("", e);
e.printStackTrace();
}
return -1;
}
Aggregations