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

📄 shoeboxparser.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            if (annotRecordToTierMap.get(annRec).equals(tierName)) {                resultAnnotRecords.add(annRec);            }        }        return resultAnnotRecords;    }    private void parse(String fileName) {        if (lastParsed.equals(fileName)) {            return;        }        // (re)set everything to null for each parse        // these calls could be removed since the parser is no longer         // used as a singleton        lingTypeRecords.clear();        participantOrder.clear();        tierNameSet.clear();        parentHash.clear();        timeOrder.clear();        timeSlots.clear();        annotationRecords.clear();        annotRecordToTierMap.clear();        rootSlots.clear();        annotId = 0;        tsId = 0;        tiertree = null;        // parse the file        lastParsed = fileName;        // fall back: check if mkr file present in shoebox txt file's directory        List markers = null;        String typFileName = "";        if (decoderInfo != null) {            markers = decoderInfo.getShoeboxMarkers();            typFileName = decoderInfo.getTypeFile();        }        // parse        checkArguments(fileName, typFileName, markers);        try {            if (typFileName.equals("")) {                typfile = new ShoeboxTypFile(markers);            } else {                typfile = new ShoeboxTypFile(new File(typFileName));                typfile.setAllTiersUnicode(decoderInfo.isAllUnicode());            }            String rootMarker = null;            if (typfile.interlinearRootMarker != null) {                rootMarker = "\\" + typfile.interlinearRootMarker;            }            sbxfile = new ShoeboxArray(new File(fileName), rootMarker, typfile);            tiertreeInit();            for (int i = 0; i < sbxfile.getNumberOfBlocks(); i++)                createBlock(i);            // loop over root slots            /*            long[] slot;            for (int i = 0; i < rootSlots.size(); i++) {                slot = (long[]) rootSlots.get(i);                System.out.println("" + i + ": " + slot[1]);            }            */            // calculate times for unaligned 'root' slots            calculateRootTimes();            /*            for (int i = 0; i < rootSlots.size(); i++) {                slot = (long[]) rootSlots.get(i);                System.out.println("" + i + ": " + slot[1]);            }            */        } catch (Exception e) {            e.printStackTrace();        }    }    /**     * DOCUMENT ME!     *     * @param sbxfn DOCUMENT ME!     * @param typfn DOCUMENT ME!     * @param mfn DOCUMENT ME!     *     * @throws IllegalArgumentException DOCUMENT ME!     */    private final void checkArguments(String sbxfn, String typfn, List markers)        throws IllegalArgumentException {        if ((sbxfn == null) || (sbxfn.length() == 0)) {            throw new IllegalArgumentException("Please specify a shoebox file.");        }        if (((typfn == null) || (typfn.length() == 0)) &&                (markers.size() == 0)) {            // try to fall back on sbxfn.mkr file in same directory            String mkrFileName = sbxfn;            if (sbxfn.endsWith(".txt")) {                mkrFileName = sbxfn.substring(0, sbxfn.length() - 4) + ".mkr";            }            if (new File(mkrFileName).exists()) {                readMarkersFromFile(mkrFileName, markers);            } else {                throw new IllegalArgumentException(                    "Please specify a shoebox typ file or define markers.");            }        }        if (!(new File(sbxfn)).exists()) {            throw new IllegalArgumentException("Shoebox file doesn't exist.");        }        if ((typfn != null) && (typfn.length() > 0) &&                !(new File(typfn)).exists()) {            throw new IllegalArgumentException(                "Shoebox type file doesn't exist.");        }    }    private void readMarkersFromFile(String mkrFileName, List markers) {        File f = new File(mkrFileName);        if (f != null) {            String line = null;            try {                FileReader filereader = new FileReader(f);                BufferedReader br = new BufferedReader(filereader);                MarkerRecord newRecord = null;                while ((line = br.readLine()) != null) {                    line = line.trim();                    String label = getLabelPart(line);                    String value = getValuePart(line);                    if (label.equals("marker")) {                        newRecord = new MarkerRecord();                        if (!value.equals("null")) {                            newRecord.setMarker(value);                        }                    } else if (label.equals("parent")) {                        if (!value.equals("null")) {                            newRecord.setParentMarker(value);                        }                    } else if (label.equals("stereotype")) {                        if (!value.equals("null")) {                            newRecord.setStereoType(value);                        }                    } else if (label.equals("charset")) {                        if (!value.equals("null")) {                            newRecord.setCharset(value);                        }                    } else if (label.equals("exclude")) {                        if (!value.equals("null")) {                            if (value.equals("true")) {                                newRecord.setExcluded(true);                            } else {                                newRecord.setExcluded(false);                            }                        }                    } else if (label.equals("participant")) {                        if (!value.equals("null")) {                            if (value.equals("true")) {                                newRecord.setParticipantMarker(true);                            } else {                                newRecord.setParticipantMarker(false);                            }                        }                        markers.add(newRecord);                    }                }            } catch (Exception ex) {                ex.printStackTrace();            }        }    }    private String getLabelPart(String theLine) {        String label = null;        int index = theLine.indexOf(':');        if (index > 0) {            label = theLine.substring(0, index);        }        return label;    }    private String getValuePart(String theLine) {        String value = null;        int index = theLine.indexOf(':');        if (index < (theLine.length() - 2)) {            value = theLine.substring(index + 1).trim();        }        return value;    }    /**     * Initialise tiertree.     */    private final void tiertreeInit() {        DefaultMutableTreeNode elanTopNode = null;        String rec = "\\" + typfile.interlinearRootMarker;        tiertree = new DefaultMutableTreeNode();        // when exported from ELAN multiple tier trees can exist.        // in that case, put \ELANExport label on top of all trees.        if (typfile.getDatabaseType().equals(ShoeboxEncoder.defaultDBType)) { // ELAN exported            elanTopNode = new DefaultMutableTreeNode(ShoeboxEncoder.elanELANLabel);            tiertree.add(elanTopNode);        } else {            elanTopNode = tiertree;        }        for (int i = 0; i < sbxfile.getNumberOfLabels(); i++) {            String label = sbxfile.getLabel(i);            if (label.startsWith("\\ELAN")) {                continue;            }            DefaultMutableTreeNode labelNode = sbxfile.getLabelNode(i);            if (label.equals(rec)) {                //	tiertree.add(labelNode);                elanTopNode.add(labelNode);                continue;            }            DefaultMutableTreeNode parentnode = null;            String parent = null;            if (typfile.tofromHash.containsKey(label)) {                parent = (String) typfile.tofromHash.get(label);                parentnode = sbxfile.getLabelNode(parent);            } else if (!typfile.excludeFromImport(label)) {                if (typfile.getDatabaseType().equals(ShoeboxEncoder.defaultDBType)) {                    parentnode = elanTopNode;                } else {                    parentnode = sbxfile.getLabelNode(rec);                }            }            //			  logger.log(Level.INFO, "attaching " + label + " to " + parent);            //			if (parent != null) {            if (parentnode != null) {                //				parentnode = sbxfi le.getLabelNode(parent);                parentnode.add(labelNode);            }        }        // Loop all fields(columns in array), in breadth-first order        //		Enumeration fibfo = tiertree.breadthFirstEnumeration();        //        //		while (fibfo.hasMoreElements()) {        //			DefaultMutableTreeNode dmt = (DefaultMutableTreeNode) fibfo.nextElement();        //           logger.log(Level.INFO,        //               "-- tiertree: " + dmt.getParent() + " ... " + dmt);        //		}    }    /**     * <p>     * MK:02/06/10<br> The top tier starts with the shoebox record marker.     * Because the same shoebox top tier can have different speakers with each     * block, which map to different CLOM-participants with each     * CLOM-annotation, in CLOM, there will be as many top tiers as there are     * speakers, build as ref_AT_Paul, ref_AT_Mary, etc.<br>     * </p>     *     * @param row Sbxfile row     *     * @throws Exception up     */    private void createBlock(int row) throws Exception {        //       logger.log(Level.INFO, "== createBlock(" + row);        String spk = sbxfile.getSpeaker(row);        long t0 = sbxfile.getT0(row);        long t1 = sbxfile.getT1(row);        String rootMarker = sbxfile.getRootMarkerForBlock(row);        //		String val = sbxfile.getCell("\\" + typfile.interlinearRootMarker, row);        String val = sbxfile.getCell(rootMarker, row);        if ((decoderInfo != null) && decoderInfo.isTimeInRefMarker()) {            t0 = sbxfile.toMilliSeconds(val, row);            t1 = -1;        }        // top tier name: typfile.recordMarker@spk        //		String tierName = "\\" + typfile.interlinearRootMarker + "@"  + spk;        String tierName = rootMarker + "@" + spk;        if (!participantOrder.contains(spk)) {            participantOrder.add(spk);        }        tierNameSet.add(tierName);        // add AnnotationRecord.        //   create timeslot        AnnotationRecord annRec = new AnnotationRecord();        annRec.setAnnotationId(ANN_ID_PREFIX + annotId++);        annRec.setAnnotationType(AnnotationRecord.ALIGNABLE);        long beginTSId = tsId++;        long endTSId = tsId++;        annRec.setBeginTimeSlotId(TS_ID_PREFIX + Long.toString(beginTSId));        annRec.setEndTimeSlotId(TS_ID_PREFIX + Long.toString(endTSId));        annRec.setValue(val);        annotationRecords.add(annRec);        annotRecordToTierMap.put(annRec, tierName);        // store timeslots        long[] begin = { beginTSId, t0 };        long[] end = { endTSId, t1 };        timeSlots.add(begin);        timeSlots.add(end);        timeOrder.add(begin);        timeOrder.add(end);        rootSlots.add(begin);        rootSlots.add(end);        // HACK: make sure top tier of interlinearized tiers is the first        String topTierName = "";        /*        Set toNames = typfile.tofromHash.keySet();                Enumeration e = typfile.tofromHash.elements(); // iterate over 'parents'                while (e.hasMoreElements()) {                    String fromName = (String) e.nextElement();                    if (!toNames.contains(fromName)) { // 'from' name not also pointed at                        topTierName = fromName;                        break;                    }                }        */        // hb, 17 sep 04: alternative hack, one that does work        // (what fun it is to work with old shit)

⌨️ 快捷键说明

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