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

📄 eaf21transcriptionstore.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        while (tierIter.hasNext()) {            TierImpl t = (TierImpl) tierIter.next();            String id = t.getName();            String participant = (String) t.getMetadataValue("PARTICIPANT");            String lingType = t.getLinguisticType().getLinguisticTypeName();            if (lingType == null) {                lingType = "not specified";            }            Locale lang = (Locale) t.getMetadataValue("DEFAULT_LOCALE");            if (lang == null) {                lang = new Locale("not specified", "", "");            }            // check is quick solution, TreeSet would do this but compareTo causes ClassCastException            if (!usedLocales.contains(lang)) {                usedLocales.add(lang);            }            String parentName = null;            if (t.getParentTier() != null) {                parentName = t.getParentTier().getName();            }            Element tierElement = eafFactory.newTier(id, participant, lingType,                    lang, parentName);            annotDocument.appendChild(tierElement);            tierElements.put(t.getName(), tierElement); // store for later use            Vector annotations = t.getAnnotations();            Iterator annotIter = annotations.iterator();            while (annotIter.hasNext()) {                Annotation ann = (Annotation) annotIter.next();                annotationIds.put(ann, "a" + annIndex);                annIndex++;            }        }        // ANNOTATIONS        // second pass. Actually creates and adds Annotation Elements        Iterator tierIter2 = storeOrder.iterator();        while (tierIter2.hasNext()) {            TierImpl t = (TierImpl) tierIter2.next();            Vector annotations = t.getAnnotations();            Iterator annotIter2 = annotations.iterator();            while (annotIter2.hasNext()) {                Annotation ann = (Annotation) annotIter2.next();                Element annElement = eafFactory.newAnnotation();                ((Element) tierElements.get(t.getName())).appendChild(annElement);                Element annSubElement = null;                String annId = (String) annotationIds.get(ann);                if (ann instanceof AlignableAnnotation) {                    String beginTsId = (String) timeSlotIds.get(((AlignableAnnotation) ann).getBegin());                    String endTsId = (String) timeSlotIds.get(((AlignableAnnotation) ann).getEnd());                    if (ann instanceof SVGAlignableAnnotation) {                        if (((SVGAlignableAnnotation) ann).getShape() != null) {                            String svgId = "ga" + svgIndex;                            ((SVGAlignableAnnotation) ann).setSVGElementID(svgId);                            svgIndex++;                            //svgIds.put(ann, svgId);                            annSubElement = eafFactory.newAlignableAnnotation(annId,                                    beginTsId, endTsId, svgId);                        } else {                            ((SVGAlignableAnnotation) ann).setSVGElementID(null);                            annSubElement = eafFactory.newAlignableAnnotation(annId,                                    beginTsId, endTsId, null);                        }                    } else {                        annSubElement = eafFactory.newAlignableAnnotation(annId,                                beginTsId, endTsId, null);                    }                } else if (ann instanceof RefAnnotation) {                    String refId = null;                    String prevId = null;                    Vector refs = ((RefAnnotation) ann).getReferences();                    RefAnnotation prev = ((RefAnnotation) ann).getPrevious();                    // for the moment, take the first, if it exists                    if (refs.size() > 0) {                        refId = (String) annotationIds.get((Annotation) refs.firstElement());                    }                    if (prev != null) {                        prevId = (String) annotationIds.get(prev);                    }                    annSubElement = eafFactory.newRefAnnotation(annId, refId,                            prevId);                }                annElement.appendChild(annSubElement);                // ANNOTATION_VALUE                Element valueElement = eafFactory.newAnnotationValue(ann.getValue());                annSubElement.appendChild(valueElement);            }        }        // LINGUISTIC_TYPES        Vector lTypes = attisTr.getLinguisticTypes();        if (lTypes != null) {            Iterator typeIter = lTypes.iterator();            while (typeIter.hasNext()) {                // HB, april 24, 2002: for the moment, just store lt name                LinguisticType lt = (LinguisticType) typeIter.next();                String stereotype = null;                if (lt.hasConstraints()) {                    stereotype = Constraint.stereoTypes[lt.getConstraints()                                                          .getStereoType()];                    stereotype = stereotype.replace(' ', '_');                }                Element typeElement = eafFactory.newLinguisticType(lt.getLinguisticTypeName(),                        lt.isTimeAlignable(), lt.hasGraphicReferences(),                        stereotype);                annotDocument.appendChild(typeElement);            }        }        // LOCALES        Iterator locIter = usedLocales.iterator();        while (locIter.hasNext()) {            Locale l = (Locale) locIter.next();            Element locElement = eafFactory.newLocale(l);            annotDocument.appendChild(locElement);        }        // HB, 18 jul 02: for the moment manually add relevant Constraints        // CONSTRAINTS        Element timeSubdivision = eafFactory.newConstraint(Constraint.stereoTypes[Constraint.TIME_SUBDIVISION].replace(                    ' ', '_'),                "Time subdivision of parent annotation's time interval, no time gaps allowed within this interval");        Element symbSubdivision = eafFactory.newConstraint(Constraint.stereoTypes[Constraint.SYMBOLIC_SUBDIVISION].replace(                    ' ', '_'),                "Symbolic subdivision of a parent annotation. Annotations refering to the same parent are ordered");        Element symbAssociation = eafFactory.newConstraint(Constraint.stereoTypes[Constraint.SYMBOLIC_ASSOCIATION].replace(                    ' ', '_'), "1-1 association with a parent annotation");        annotDocument.appendChild(timeSubdivision);        annotDocument.appendChild(symbSubdivision);        annotDocument.appendChild(symbAssociation);        return eafFactory.getDocumentElement();    }    //M_P    public void storeTranscriptionAsTemplateIn(Transcription theTranscription,        Vector tierOrder, String path) {        Element documentElement = createTemplateDOM(theTranscription, tierOrder);        if (this.fileToWriteXMLinto != null) {            save(documentElement, fileToWriteXMLinto.getAbsolutePath(), true);        } else {            save(documentElement, path, false);        }    }    /**     * DOCUMENT ME!     *     * @param theTranscription DOCUMENT ME!     * @param tierOrder DOCUMENT ME!     *     * @return DOCUMENT ME!     */    public static Element createTemplateDOM(Transcription theTranscription,        Vector tierOrder) {        Hashtable tierElements = new Hashtable(); // for temporary storage of created tier Elements        Hashtable annotationIds = new Hashtable(); // for temporary storage of generated annIds        Vector usedLocales = new Vector(); // for storage of used locales        TranscriptionImpl attisTr = (TranscriptionImpl) theTranscription;        if (attisTr == null) {            System.out.println(                "[[ASSERTION FAILED]] EAF21TranscriptionStore/storeTranscription: theTranscription is null");        }        ;        if (attisTr.getMediaObject() == null) {            System.out.println(                "[[ASSERTION FAILED]] EAF21TranscriptionStore/storeTranscription: theTranscription.getMediaObject() is null");        }        ;        EAF21 eafFactory = null;        try {            eafFactory = new EAF21();        } catch (Exception ex) {            ex.printStackTrace();        }        // ANNOTATION_DOCUMENT        SimpleDateFormat dateFmt = new SimpleDateFormat("yyyy.MM.dd HH:mm z");        String dateString = dateFmt.format(Calendar.getInstance().getTime());        String author = attisTr.getAuthor();        //always set author to empty in template        author = "";        String version = "2.1"; // version of DTD/format, not of file. That is handled by 'date'        Element annotDocument = eafFactory.newAnnotationDocument(dateString,                author, version);        eafFactory.appendChild(annotDocument);        // HEADER        //always set header to empty in template        //Element header = eafFactory.newHeader(attisTr.getMediaObject().getMediaURL().toString());        Element header = eafFactory.newHeader("");        annotDocument.appendChild(header);        // TIERS        Vector tiers = attisTr.getTiers();        Vector storeOrder = new Vector(tierOrder); // start with tiers in specified order        Iterator tIter = tiers.iterator();        while (tIter.hasNext()) { // add other tiers in document order            Tier t = (Tier) tIter.next();            if (!storeOrder.contains(t)) {                storeOrder.add(t);            }        }        int annIndex = 1; // used to create annotation id values        Iterator tierIter = storeOrder.iterator();        while (tierIter.hasNext()) {            TierImpl t = (TierImpl) tierIter.next();            String id = t.getName();            String participant = (String) t.getMetadataValue("PARTICIPANT");            String lingType = t.getLinguisticType().getLinguisticTypeName();            if (lingType == null) {                lingType = "not specified";            }            Locale lang = (Locale) t.getMetadataValue("DEFAULT_LOCALE");            if (lang == null) {                lang = new Locale("not specified", "", "");            }            // check is quick solution, TreeSet would do this but compareTo causes ClassCastException            if (!usedLocales.contains(lang)) {                usedLocales.add(lang);            }            String parentName = null;            if (t.getParentTier() != null) {                parentName = t.getParentTier().getName();            }            Element tierElement = eafFactory.newTier(id, participant, lingType,                    lang, parentName);            annotDocument.appendChild(tierElement);            tierElements.put(t.getName(), tierElement); // store for later use            Vector annotations = t.getAnnotations();            Iterator annotIter = annotations.iterator();            while (annotIter.hasNext()) {                Annotation ann = (Annotation) annotIter.next();                annotationIds.put(ann, "a" + annIndex);                annIndex++;            }        }        // LINGUISTIC_TYPES        Vector lTypes = attisTr.getLinguisticTypes();        if (lTypes != null) {            Iterator typeIter = lTypes.iterator();            while (typeIter.hasNext()) {                // HB, april 24, 2002: for the moment, just store lt name                LinguisticType lt = (LinguisticType) typeIter.next();                String stereotype = null;                if (lt.hasConstraints()) {                    stereotype = Constraint.stereoTypes[lt.getConstraints()                                                          .getStereoType()];                    stereotype = stereotype.replace(' ', '_');                }                Element typeElement = eafFactory.newLinguisticType(lt.getLinguisticTypeName(),                        lt.isTimeAlignable(), lt.hasGraphicReferences(),                        stereotype);                annotDocument.appendChild(typeElement);            }        }        // LOCALES        Iterator locIter = usedLocales.iterator();        while (locIter.hasNext()) {            Locale l = (Locale) locIter.next();            Element locElement = eafFactory.newLocale(l);            annotDocument.appendChild(locElement);        }        // HB, 18 jul 02: for the moment manually add relevant Constraints        // CONSTRAINTS        Element timeSubdivision = eafFactory.newConstraint(Constraint.stereoTypes[Constraint.TIME_SUBDIVISION].replace(                    ' ', '_'),                "Time subdivision of parent annotation's time interval, no time gaps allowed within this interval");        Element symbSubdivision = eafFactory.newConstraint(Constraint.stereoTypes[Constraint.SYMBOLIC_SUBDIVISION].replace(                    ' ', '_'),                "Symbolic subdivision of a parent annotation. Annotations refering to the same parent are ordered");        Element symbAssociation = eafFactory.newConstraint(Constraint.stereoTypes[Constraint.SYMBOLIC_ASSOCIATION].replace(                    ' ', '_'), "1-1 association with a parent annotation");        annotDocument.appendChild(timeSubdivision);        annotDocument.appendChild(symbSubdivision);        annotDocument.appendChild(symbAssociation);        return eafFactory.getDocumentElement();    }    /**     * DOCUMENT ME!     *     * @param theTranscription DOCUMENT ME!     */    public void loadTranscription(Transcription theTranscription) {        //	System.out.println("EAFTranscriptionStore.loadTranscription called");        TranscriptionImpl attisTr = (TranscriptionImpl) theTranscription;        String trPathName = attisTr.getPathName();        Parser parser = null;        if (trPathName.endsWith("cha")) {            parser = ParserFactory.getParser(ParserFactory.CHAT);

⌨️ 快捷键说明

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