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

📄 eaf21transcriptionstore.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        } else {            parser = ParserFactory.getParser(ParserFactory.EAF21);        }        // NOTE: media file is not used by either Elan 1.4.1 or Elan 2.0        // Instead MediaDescriptors are introduced. Mediafile is temporarily maintained        // for compatibility of EAF 2.1 with Elan 1.4.1        // set media transcription's media file        String mediaFileName = parser.getMediaFile(trPathName);        if ((mediaFileName != null) && (mediaFileName.startsWith("file:"))) {            mediaFileName = mediaFileName.substring(5);        }        attisTr.setMainMediaFile(mediaFileName);        // make media descriptors available in transcription        ArrayList mediaDescriptors = parser.getMediaDescriptors(trPathName);        attisTr.setMediaDescriptors(new Vector(mediaDescriptors));        String svgFile = parser.getSVGFile(trPathName);        if (svgFile != null) {            if (!svgFile.startsWith("file:")) {                svgFile = "file:" + mediaFileName;            }            attisTr.setSVGFile(svgFile);        }        // set author        String author = parser.getAuthor(trPathName);        if (attisTr.getAuthor().equals("")) {            attisTr.setAuthor(author);        }        // make linguistic types available in transcription        ArrayList linguisticTypes = parser.getLinguisticTypes(trPathName);        Vector typesCopy = new Vector(linguisticTypes.size());        for (int i = 0; i < linguisticTypes.size(); i++) {            //           typesCopy.add(i, linguisticTypes.get(i));            LingTypeRecord ltr = (LingTypeRecord) linguisticTypes.get(i);            LinguisticType lt = new LinguisticType(ltr.getLingTypeId());            boolean timeAlignable = true;            if (ltr.getTimeAlignable().equals("false")) {                timeAlignable = false;            }            lt.setTimeAlignable(timeAlignable);            boolean graphicReferences = false;            if (ltr.getGraphicReferences().equals("true")) {                graphicReferences = true;            }            lt.setGraphicReferences(graphicReferences);            String stereotype = ltr.getStereoType();            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);            }            typesCopy.add(lt);        }        attisTr.setLinguisticTypes(typesCopy);        //attisTr.setLinguisticTypes(linguisticTypes);        TimeOrder timeOrder = attisTr.getTimeOrder();        // populate TimeOrder with TimeSlots        ArrayList order = parser.getTimeOrder(trPathName);        HashMap slots = parser.getTimeSlots(trPathName);        Hashtable timeSlothash = new Hashtable(); // temporarily stores map from id to TimeSlot object        Iterator orderedIter = order.iterator();        while (orderedIter.hasNext()) {            TimeSlot ts = null;            String key = (String) orderedIter.next();            long time = Long.parseLong((String) slots.get(key));            if (time != TimeSlot.TIME_UNALIGNED) {                ts = new TimeSlotImpl(time, timeOrder);            } else {                ts = new TimeSlotImpl(timeOrder);            }            timeOrder.insertTimeSlot(ts);            timeSlothash.put(key, ts);        }        Hashtable parentHash = new Hashtable();        if (!attisTr.isLoaded()) {            Iterator iter = parser.getTierNames(trPathName).iterator();            // HB, 27 aug 03, moved earlier            attisTr.setLoaded(true); // else endless recursion !!!!!            while (iter.hasNext()) {                String tierName = (String) iter.next();                TierImpl tier = new TierImpl(null, tierName, null, attisTr, null);                // set tier's metadata                String participant = parser.getParticipantOf(tierName,                        trPathName);                String linguisticTypeID = parser.getLinguisticTypeIDOf(tierName,                        trPathName);                LinguisticType linguisticType = null;                Iterator typeIter = typesCopy.iterator();                while (typeIter.hasNext()) {                    LinguisticType lt = (LinguisticType) typeIter.next();                    if (lt.getLinguisticTypeName().equals(linguisticTypeID)) {                        linguisticType = lt;                        break;                    }                }                Locale defaultLanguage = parser.getDefaultLanguageOf(tierName,                        trPathName);                tier.setMetadata("PARTICIPANT", participant);                tier.setLinguisticType(linguisticType);                if (defaultLanguage != null) { // HB, 29 oct 02: added condition, since DEFAULT_LOCALE is IMPLIED                    tier.setMetadata("DEFAULT_LOCALE", defaultLanguage);                }                // potentially, set tier's parent                String parentId = parser.getParentNameOf(tierName, trPathName);                if (parentId != null) {                    // store tier-parent_id pair until all Tiers instantiated                    parentHash.put(tier, parentId);                }                attisTr.addTier(tier);            }        }        // all Tiers are created. Now set all parent tiers        Iterator parentIter = parentHash.keySet().iterator();        while (parentIter.hasNext()) {            TierImpl t = (TierImpl) parentIter.next();            t.setParentTier(attisTr.getTierWithId((String) parentHash.get(t)));        }        //	attisTr.setLoaded(true);	// else endless recursion !!!!!        Vector tiers = attisTr.getTiers();        // create Annotations. Algorithm:        // 1. loop over annotationRecords Vector. Instantiate right Annotations. Store        //    references to annotations in intermediate data structures        // 2. loop over intermediate structure. Realize references to Annotations by object        //    references, iso using annotation_id's        Hashtable idToAnnotation = new Hashtable();        Hashtable references = new Hashtable();        Hashtable referenceChains = new Hashtable();        // HB, 2-1-02: temporarily store annotations, before adding them to tiers.        // Reason: object reference have to be in place to add annotations in correct order.        Hashtable tempAnnotationsForTiers = new Hashtable();        // create Annotations, either AlignableAnnotations or RefAnnotations        Iterator tierIter = tiers.iterator();        while (tierIter.hasNext()) {            Tier tier = (Tier) tierIter.next();            ArrayList annotationRecords = parser.getAnnotationsOf(tier.getName(),                    trPathName);            // HB, 2-1-02            Vector tempAnnotations = new Vector();            Iterator it1 = annotationRecords.iterator();            while (it1.hasNext()) {                Annotation annotation = null;                AnnotationRecord annotationRecord = (AnnotationRecord) it1.next();                if (annotationRecord.getAnnotationType().equals(AnnotationRecord.ALIGNABLE)) {                    // when the parser does not find an SVG_REF attribute the annotation is                     // marked alignable even if it is on a tier that allows graphic references,                    // therefore check here whether to create an AlignableAnnotation or a                    // SVGAlignableAnnotation                    if (((TierImpl) tier).getLinguisticType()                             .hasGraphicReferences()) {                        annotation = new SVGAlignableAnnotation((TimeSlot) timeSlothash.get(                                    annotationRecord.getBeginTimeSlotId()),                                (TimeSlot) timeSlothash.get(                                    annotationRecord.getEndTimeSlotId()), tier,                                null);                    } else {                        annotation = new AlignableAnnotation((TimeSlot) timeSlothash.get(                                    annotationRecord.getBeginTimeSlotId()),                                (TimeSlot) timeSlothash.get(                                    annotationRecord.getEndTimeSlotId()), tier);                    }                    /*                    annotation = new SVGAlignableAnnotation((TimeSlot) timeSlothash.get(                                timeSlotId1),                                (TimeSlot) timeSlothash.get(timeSlotId2), tier,                                null);                    */                } else if (annotationRecord.getAnnotationType().equals(AnnotationRecord.ALIGNABLE_SVG)) {                    annotation = new SVGAlignableAnnotation((TimeSlot) timeSlothash.get(                                annotationRecord.getBeginTimeSlotId()),                            (TimeSlot) timeSlothash.get(                                annotationRecord.getEndTimeSlotId()), tier,                            annotationRecord.getSvgReference());                } else if (annotationRecord.getAnnotationType().equals(AnnotationRecord.REFERENCE)) {                    annotation = new RefAnnotation(null, tier);                    references.put(annotationRecord.getAnnotationId(),                        annotationRecord.getReferredAnnotId());                    if (annotationRecord.getPreviousAnnotId() != null) {                        referenceChains.put(annotationRecord.getAnnotationId(),                            annotationRecord.getPreviousAnnotId());                    }                }                if (annotationRecord.getValue() != null) {                    annotation.setValue(annotationRecord.getValue());                }                idToAnnotation.put(annotationRecord.getAnnotationId(),                    annotation);                //	tier.addAnnotation(annotation);                // HB, 2-1-02                tempAnnotations.add(annotation);            }            // end of loop over annotation records            // HB, 2-1-02            tempAnnotationsForTiers.put(tier, tempAnnotations);        }        // end of loop over tierIter        // realize object references        Iterator refIter = references.keySet().iterator();        while (refIter.hasNext()) {            String key = (String) refIter.next();            Annotation referedAnnotation = (Annotation) idToAnnotation.get(references.get(                        key));            RefAnnotation refAnnotation = null;            try {                refAnnotation = (RefAnnotation) idToAnnotation.get(key);                refAnnotation.addReference(referedAnnotation);            } catch (Exception ex) {                //MK:02/09/17 adding exception handler                Object o = idToAnnotation.get(key);                System.out.println("failed to add a refanno to  (" +                    referedAnnotation.getTier().getName() + ", " +                    referedAnnotation.getBeginTimeBoundary() + ", " +                    referedAnnotation.getEndTimeBoundary() + ") " +                    referedAnnotation.getValue());                if (o instanceof AlignableAnnotation) {                    AlignableAnnotation a = (AlignableAnnotation) o;                    System.out.println("  found AlignableAnnotation (" +                        a.getTier().getName() + ", " +                        a.getBeginTimeBoundary() + ", " +                        a.getEndTimeBoundary() + ") " + a.getValue());                } else {                    System.out.println("  found " + o);                }            }        }        // realize reference chains (== within tiers)        Iterator rIter = referenceChains.keySet().iterator();        while (rIter.hasNext()) {            String key = (String) rIter.next();            RefAnnotation previous = (RefAnnotation) idToAnnotation.get(referenceChains.get(                        key));            RefAnnotation a = (RefAnnotation) idToAnnotation.get(key);            if (previous != null) {                previous.setNext(a);            }        }        // HB, 2-1-01: with object references in place, add annotations to the correct tiers.        // This is now done in the correct order (RefAnnotation.compareTo delegates comparison        // to it's parent annotation.        Iterator tIter = tempAnnotationsForTiers.keySet().iterator();        while (tIter.hasNext()) {            TierImpl t = (TierImpl) tIter.next();            Vector annots = (Vector) tempAnnotationsForTiers.get(t);            Iterator aIter = annots.iterator();            while (aIter.hasNext()) {                // HB, 14 aug 02, changed from addAnnotation                t.insertAnnotation((Annotation) aIter.next());            }        }        // HB, 4-7-02: with all annotations on the proper tiers, register implicit        // parent-child relations between alignable annotations explicitly        Iterator tierIter2 = tiers.iterator();        while (tierIter2.hasNext()) {            TierImpl t = (TierImpl) tierIter2.next();            if (t.isTimeAlignable() && t.hasParentTier()) {                Iterator alannIter = t.getAnnotations().iterator();                while (alannIter.hasNext()) {                    Annotation a = (Annotation) alannIter.next();                    if (a instanceof AlignableAnnotation) {                        ((AlignableAnnotation) a).registerWithParent();                    }                }            }        }        // if all root annotations unaligned (in case of shoebox or chat import)        // align them at 1 second intervals        if (attisTr.allRootAnnotsUnaligned()) {            attisTr.alignRootAnnots();        }        System.out.println("getName: " + attisTr.getName());        System.out.println("fullpath: " + attisTr.getFullPath());        System.out.println("pathname: " + attisTr.getPathName());    }}

⌨️ 快捷键说明

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