⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eaf20parser.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            annotationRecord.addAll(((Vector) annotations.get(key)));            annotationVector.add(annotationRecord);        }        long duration = System.currentTimeMillis() - start;        //	System.out.println("Extracting Annotations took " + duration + " milli seconds");        return annotationVector;    }    /**     * Parses a EAF v2.0 xml file.     *     * @param fileName the EAF v2.0 xml file that must be parsed.     */    private void parse(String fileName) {        long start = System.currentTimeMillis();        //		System.out.println("Parse : " + fileName);        //		System.out.println("Free memory : " + Runtime.getRuntime().freeMemory());        // only parse the same file once        if (lastParsed.equals(fileName)) {            return;        }        // (re)set everything to null for each parse        tiers.clear();        tierNames.clear(); // HB, 2-1-02, to store name IN ORDER        tierAttributes.clear();        mediaFile = "";        linguisticTypes.clear();        locales.clear();        timeSlots.clear();        timeOrder.clear();        // parse the file        lastParsed = fileName;        currentFileName = fileName;        try {            saxParser.parse(fileName);        } catch (SAXException e) {            System.out.println("Parsing error: " + e.getMessage());        } catch (IOException e) {            e.printStackTrace();        } catch (Exception e) {            printErrorLocationInfo("Fatal(?) Error! " + e.getMessage());        }        long duration = System.currentTimeMillis() - start;        //	System.out.println("Parsing took " + duration + " milli seconds");    }    private void println(String s) {        if (verbose) {            System.out.println(s);        }    }    private void printErrorLocationInfo(String message) {        System.out.println(message);        System.out.println("Exception for " + currentFileName);        System.out.println("Tier id " + currentTierId);        System.out.println("Annotation id " + currentAnnotationId);    }    /**     * DOCUMENT ME!     * $Id: EAF20Parser.java,v 1.1.1.1 2004/03/25 16:23:20 wouthuij Exp $     * @author $Author: wouthuij $     * @version $Revision: 1.1.1.1 $     */    class EAFContentHandler implements ContentHandler {        private Locator locator;        /**         * DOCUMENT ME!         *         * @param locator DOCUMENT ME!         */        public void setDocumentLocator(Locator locator) {            this.locator = locator;        }        /**         * DOCUMENT ME!         *         * @param prefix DOCUMENT ME!         * @param uri DOCUMENT ME!         */        public void startPrefixMapping(String prefix, String uri) {        }        /**         * DOCUMENT ME!         *         * @param prefix DOCUMENT ME!         */        public void endPrefixMapping(String prefix) {        }        /**         * DOCUMENT ME!         *         * @param ch DOCUMENT ME!         * @param start DOCUMENT ME!         * @param end DOCUMENT ME!         *         * @throws SAXException DOCUMENT ME!         */        public void ignorableWhitespace(char[] ch, int start, int end)            throws SAXException {        }        /**         * DOCUMENT ME!         *         * @param name DOCUMENT ME!         *         * @throws SAXException DOCUMENT ME!         */        public void skippedEntity(String name) throws SAXException {        }        /**         * DOCUMENT ME!         *         * @param target DOCUMENT ME!         * @param data DOCUMENT ME!         *         * @throws SAXException DOCUMENT ME!         */        public void processingInstruction(String target, String data)            throws SAXException {        }        /**         * ContentHandler method         *         * @throws SAXException DOCUMENT ME!         */        public void startDocument() throws SAXException {            parseError = false;        }        /**         * ContentHandler method         *         * @throws SAXException DOCUMENT ME!         */        public void endDocument() throws SAXException {        }        /**         * ContentHandler method         *         * @param nameSpaceURI DOCUMENT ME!         * @param name DOCUMENT ME!         * @param rawName DOCUMENT ME!         * @param attributes DOCUMENT ME!         *         * @throws SAXException DOCUMENT ME!         */        public void startElement(String nameSpaceURI, String name,            String rawName, Attributes attributes) throws SAXException {            //	System.out.println("startElement called for name:" + name);            content = "";            if (name.equals("ANNOTATION_DOCUMENT")) {                author = attributes.getValue("AUTHOR");            } else if (name.equals("HEADER")) {                // implement when dealing with MediaObject                mediaFile = attributes.getValue("MEDIA_FILE");                svgFile = attributes.getValue("SVG_FILE");            } else if (name.equals("TIME_ORDER")) {                // nothing to be done, tierOrder Vector already created            } else if (name.equals("TIME_SLOT")) {                String timeValue = String.valueOf(TimeSlot.TIME_UNALIGNED);                if (attributes.getValue("TIME_VALUE") != null) {                    timeValue = attributes.getValue("TIME_VALUE");                }                timeSlots.put(attributes.getValue("TIME_SLOT_ID"), timeValue);                timeOrder.add(attributes.getValue("TIME_SLOT_ID"));            } else if (name.equals("TIER")) {                currentTierId = attributes.getValue("TIER_ID");                // First check whether this tier already exists                if (!tiers.containsKey(currentTierId)) {                    // create entries in the tiers and tierAttributes Hashtables for annotations and attributes resp.                    tiers.put(currentTierId, new Hashtable());                    tierAttributes.put(currentTierId, new Hashtable());                    // HB, 2-1-02                    tierNames.add(currentTierId);                }                // store tier attributes                Hashtable attrHash = (Hashtable) tierAttributes.get(currentTierId);                if (attributes.getValue("PARTICIPANT") != null) {                    attrHash.put("PARTICIPANT",                        attributes.getValue("PARTICIPANT"));                }                attrHash.put("LINGUISTIC_TYPE_REF",                    attributes.getValue("LINGUISTIC_TYPE_REF"));                if (attributes.getValue("DEFAULT_LOCALE") != null) { // HB, 29 oct 02: added condition                    attrHash.put("DEFAULT_LOCALE",                        attributes.getValue("DEFAULT_LOCALE"));                } else { // HB, 30 oct 02, added default case                    attrHash.put("DEFAULT_LOCALE", "en");                }                if (attributes.getValue("PARENT_REF") != null) {                    attrHash.put("PARENT_REF", attributes.getValue("PARENT_REF"));                }            } else if (name.equals("ALIGNABLE_ANNOTATION")) {                currentAnnotationId = attributes.getValue("ANNOTATION_ID");                // create new "AnnotationRecord" and add to annotations Hashtable for current tier                ((Hashtable) tiers.get(currentTierId)).put(currentAnnotationId,                    new Vector());                // mark type of annotation, add start and end times to this AnnotationRecord                String svg_ref = attributes.getValue("SVG_REF");                ((Vector) ((Hashtable) tiers.get(currentTierId)).get(currentAnnotationId)).add((svg_ref == null)                    ? "alignable" : "alignable_svg");                ((Vector) ((Hashtable) tiers.get(currentTierId)).get(currentAnnotationId)).add(attributes.getValue(                        "TIME_SLOT_REF1"));                ((Vector) ((Hashtable) tiers.get(currentTierId)).get(currentAnnotationId)).add(attributes.getValue(                        "TIME_SLOT_REF2"));                if (svg_ref != null) {                    ((Vector) ((Hashtable) tiers.get(currentTierId)).get(currentAnnotationId)).add(svg_ref);                }            } else if (name.equals("REF_ANNOTATION")) {                currentAnnotationId = attributes.getValue("ANNOTATION_ID");                // create new "AnnotationRecord" and add to annotations Hashtable for current tier                ((Hashtable) tiers.get(currentTierId)).put(currentAnnotationId,                    new Vector());                // mark type of annotation, add annotation reference to this AnnotationRecord                ((Vector) ((Hashtable) tiers.get(currentTierId)).get(currentAnnotationId)).add(                    "reference");                ((Vector) ((Hashtable) tiers.get(currentTierId)).get(currentAnnotationId)).add(attributes.getValue(                        "ANNOTATION_REF"));                if (attributes.getValue("PREVIOUS_ANNOTATION") != null) {                    ((Vector) ((Hashtable) tiers.get(currentTierId)).get(currentAnnotationId)).add(attributes.getValue(                            "PREVIOUS_ANNOTATION"));                } else {                    ((Vector) ((Hashtable) tiers.get(currentTierId)).get(currentAnnotationId)).add(                        "");                }            } else if (name.equals("LINGUISTIC_TYPE")) {                LinguisticType lt = new LinguisticType(attributes.getValue(                            "LINGUISTIC_TYPE_ID"));                boolean timeAlignable = true;                if ((attributes.getValue("TIME_ALIGNABLE") != null) &&                        (attributes.getValue("TIME_ALIGNABLE").equals("false"))) {                    timeAlignable = false;                }                lt.setTimeAlignable(timeAlignable);                boolean graphicReferences = false;                if ((attributes.getValue("GRAPHIC_REFERENCES") != null) &&                        (attributes.getValue("GRAPHIC_REFERENCES").equals("true"))) {                    graphicReferences = true;                }                lt.setGraphicReferences(graphicReferences);                String stereotype = attributes.getValue("CONSTRAINTS");                Constraint c = null;                if (stereotype != null) {                    stereotype = stereotype.replace('_', ' '); // for backwards compatibility                    if (stereotype.equals(                                Constraint.stereoTypes[Constraint.TIME_SUBDIVISION])) {                        c = new TimeSubdivision();                    } else if (stereotype.equals(                                Constraint.stereoTypes[Constraint.SYMBOLIC_SUBDIVISION])) {                        c = new SymbolicSubdivision();                    } else if (stereotype.equals(                                Constraint.stereoTypes[Constraint.SYMBOLIC_ASSOCIATION])) {                        c = new SymbolicAssociation();                    }                }                if (c != null) {                    lt.addConstraint(c);                }                linguisticTypes.add(lt);            } else if (name.equals("LOCALE")) {                String langCode = attributes.getValue("LANGUAGE_CODE");                String countryCode = attributes.getValue("COUNTRY_CODE");                if (countryCode == null) {                    countryCode = "";                }                String variant = attributes.getValue("VARIANT");                if (variant == null) {                    variant = "";                }                Locale l = new Locale(langCode, countryCode, variant);                locales.add(l);            }        }        //startElement        /**         * ContentHandler method         *         * @param nameSpaceURI DOCUMENT ME!         * @param name DOCUMENT ME!         * @param rawName DOCUMENT ME!         *         * @throws SAXException DOCUMENT ME!         */        public void endElement(String nameSpaceURI, String name, String rawName)            throws SAXException {            if (name.equals("ANNOTATION_VALUE")) {                ((Vector) ((Hashtable) tiers.get(currentTierId)).get(currentAnnotationId)).add(content);            }        }        /**         * ContentHandler method         *         * @param $paramType$ DOCUMENT ME!         * @param start DOCUMENT ME!         * @param end DOCUMENT ME!         *         * @throws SAXException DOCUMENT ME!         */        public void characters(char[] ch, int start, int end)            throws SAXException {            content += new String(ch, start, end);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -