ConceptParser.java 文件源码

java
阅读 17 收藏 0 点赞 0 评论 0

项目:similarity 作者:
private static void load(InputStream inputStream) throws IOException {
    long start = System.currentTimeMillis();
    int count = 0;
    try {
        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
        XMLEventReader xmlEventReader = inputFactory.createXMLEventReader(inputStream);
        while (xmlEventReader.hasNext()) {
            XMLEvent event = xmlEventReader.nextEvent();
            if (event.isStartElement()) {
                StartElement startElement = event.asStartElement();
                if (startElement.getName().toString().equals("c")) {
                    String word = startElement.getAttributeByName(QName.valueOf("w")).getValue();
                    String define = startElement.getAttributeByName(QName.valueOf("d")).getValue();
                    String pos = startElement.getAttributeByName(QName.valueOf("p")).getValue();
                    CONCEPTS.put(word, new Concept(word, pos, define));
                    count++;
                }
            }
        }
        inputStream.close();
    } catch (Exception e) {
        throw new IOException(e);
    }
    logger.info("complete! count num:" + count + ",time spend:" + (System.currentTimeMillis() - start) + "ms");
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号