【问题标题】:Create translation web services in java?在 Java 中创建翻译 Web 服务?
【发布时间】:2015-10-16 14:33:29
【问题描述】:
  1. 用词创建 XML 库?
  2. 当客户需要翻译中的特定单词时, 服务检查其基于 XML 的单词如果有单词, 服务作为向客户端的输出广播一个翻译后的单词。如果 XML 文件中不存在该词,服务广播 足够的信息。因为在 XML 文件中进行测试需要添加一个 几句话。
  3. 客户端通过调用方法 translate 来受益于描述的服务, 三个字符串参数。示例:translate(”butterfly”, ”english”, ”russian”);

SAXParser:

public class Main {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    SAXParser sp = spf.newSAXParser();
    sp.parse ("words.xml", new MySaxHandler());
}
}

处理程序:

class MySaxHandler extends DefaultHandler {
private String actualNodeName;

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    this.actualNodeName = qName;
}

@Override
public void characters(char[] ch, int start, int length) throws SAXException {
    if(!actualNodeName.equals("bs"))
        return;
    String nodeValue = new String(ch,start,length);

    if (!nodeValue.trim().equals(""))
        System.out.println (nodeValue);
}
}

【问题讨论】:

  • 接下来我是什么..... ??
  • 你能发布示例 xml 结构吗..?

标签: java xml soap machine-translation


【解决方案1】:
package servis;


Document doc;

public Prevodilac() throws ParserConfigurationException, SAXException, IOException{
    String xmlFile ;

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    InputSource is = new InputSource(new StringReader(xmlFile));
    doc = builder.parse(is);

}

/**
 * Web service operation
 */
@WebMethod(operationName = "pretraga")
public String pretraga(String key) {
    Element r = doc.getDocumentElement();
    NodeList language = r.getElementsByTagName("phrase");
    String result = "Not Found";
    for(int index = 0;index<language.getLength();index++){
        Node attr = language.item(index).getAttributes().getNamedItem("key");
        if(attr)
    }
    return result;
}

}

【讨论】:

  • 需要 if(attr) 的帮助..我需要检查属性是否对应于关键参数并用属性值填充结果
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多