📄 shoeboxencoder.java
字号:
prefix = curPref; } else if (!prefix.equals(curPref)) { justOneRoot = false; break; } } } } for (int i = 0; i < outputLines.length; i++) { // add tier labels String tierLabel = interlinearizer.getMetrics().getTierLabelAt(i); if (tierLabel == null) { tierLabel = ""; } if (rootTierNames.get(tierLabel) != null) { participantString = (String) rootTierNames.get(tierLabel); lineForRootAnnot = true; } if (!tierLabel.startsWith("\\") && !tierLabel.equals("")) { tierLabel = "\\" + tierLabel; } if (tierLabel.indexOf("@") > 0) { tierLabel = tierLabel.substring(0, tierLabel.indexOf("@")); } if (tierLabel.indexOf(" ") >= 0) { // substitute spaces tierLabel = tierLabel.replace(' ', '_'); } if (tierLabel.startsWith("\\TC")) { // time code, subsitute with 2 lines String beginString = outputLines[i].substring(0, outputLines[i].indexOf("-")).trim(); String endString = outputLines[i].substring(outputLines[i].indexOf( "-") + 1).trim(); // only write aligned time slots if (!beginString.startsWith(Interlinearizer.UNALIGNED_SSMS)) { write((elanBeginLabel + " " + beginString + "\n")); } if (!endString.startsWith(Interlinearizer.UNALIGNED_SSMS)) { write((elanEndLabel + " " + endString + "\n")); } if ((participantString != null) && !participantString.equals("")) { write((elanParticipantLabel + " " + participantString + "\n")); } } else { // get character encoding for outputLine i int charEncoding = interlinearizer.getCharEncoding(interlinearizer.getMetrics() .getTierLabelAt(i)); String encodingString = "ISO-8859-1"; if (charEncoding == Interlinearizer.UTF8) { encodingString = "UTF-8"; } else if (charEncoding == Interlinearizer.SIL) { encodingString = "SIL-IPA93"; } if (lineForRootAnnot) { if (!justOneRoot) { DecimalFormat df = new DecimalFormat("#000"); String cntString = df.format(blockCounter++); write(elanBlockStart + " " + cntString + "\n"); } lineForRootAnnot = false; } write(tierLabel + " " + outputLines[i].replace('\n', ' ') + "\n", encodingString); } } } catch (Exception rex) { rex.printStackTrace(); } } private void setShoeboxArguments(Transcription transcription, Interlinearizer interlinearizer, Vector tierOrder, EncoderInfo encoderInfo) { String[] visTiers = new String[tierOrder.size()]; tierOrder.copyInto(visTiers); int width = 80; int timeFormat = Interlinearizer.SSMS; if (encoderInfo != null) { width = ((ToolboxEncoderInfo) encoderInfo).getPageWidth(); timeFormat = ((ToolboxEncoderInfo) encoderInfo).getTimeFormat(); } interlinearizer.setVisibleTiers(visTiers); interlinearizer.setAlignmentUnit(Interlinearizer.BYTES); interlinearizer.setBlockWrapStyle(Interlinearizer.EACH_BLOCK); interlinearizer.setWidth(width); interlinearizer.setBlockSpacing(1); interlinearizer.setTierLabelsShown(false); interlinearizer.setTimeCodeShown(true); interlinearizer.setTimeCodeType(timeFormat); interlinearizer.setCorrectAnnotationTimes(((ToolboxEncoderInfo) encoderInfo).getCorrectAnnotationTimes()); // set default char encodings to ISO-Latin if (((ToolboxEncoderInfo) encoderInfo).getMarkerSource() == ToolboxEncoderInfo.TIERNAMES) { setDefaultCharEncodings(transcription, interlinearizer, Interlinearizer.UTF8); } else if (((ToolboxEncoderInfo) encoderInfo).getMarkerSource() == ToolboxEncoderInfo.TYPFILE) { // typfile if (((ToolboxEncoderInfo) encoderInfo).isAllUnicode()) { setDefaultCharEncodings(transcription, interlinearizer, Interlinearizer.UTF8); } else { setDefaultCharEncodings(transcription, interlinearizer, Interlinearizer.ISOLATIN); } } else { // markers setDefaultCharEncodings(transcription, interlinearizer, Interlinearizer.ISOLATIN); // iterate over markers, set to UTF-8 or SIL where necessary List markers = ((ToolboxEncoderInfo) encoderInfo).getMarkers(); if (markers != null) { for (int i = 0; i < markers.size(); i++) { MarkerRecord mkrRec = (MarkerRecord) markers.get(i); // find all tiers starting with the same prefix; crucial in case there // is a tiergroup per participant List matchingTiers = getMatchingTiers(transcription, mkrRec.getMarker()); String name; for (int j = 0; j < matchingTiers.size(); j++) { name = (String) matchingTiers.get(j); if (!"".equals(name)) { if (mkrRec.getCharset() == MarkerRecord.ISOLATIN) { interlinearizer.setCharEncoding(name, Interlinearizer.ISOLATIN); } else if (mkrRec.getCharset() == MarkerRecord.UTF8) { interlinearizer.setCharEncoding(name, Interlinearizer.UTF8); } else if (mkrRec.getCharset() == MarkerRecord.SILIPA) { interlinearizer.setCharEncoding(name, Interlinearizer.SIL); } } } } } } } private void setDefaultCharEncodings(Transcription transcription, Interlinearizer interlinearizer, int encoding) { Vector tiers = transcription.getTiers(); for (int i = 0; i < tiers.size(); i++) { String tierName = ((Tier) tiers.elementAt(i)).getName(); interlinearizer.setCharEncoding(tierName, encoding); } } /** * Returns all tiers that start with this marker and that have a "@" character * following the marker. * * @param transcription the transcription * @param marker the marker name or label * * @return a list of tiers */ private List getMatchingTiers(Transcription transcription, String marker) { ArrayList tierList = new ArrayList(5); Vector tiers = transcription.getTiers(); for (int i = 0; i < tiers.size(); i++) { String tierName = ((Tier) tiers.elementAt(i)).getName(); if (tierName.startsWith(marker)) { if ((tierName.length() == marker.length()) || (tierName.indexOf('@') == marker.length())) { tierList.add(tierName); } } } return tierList; } /** * Write using ISO-8859-1 (ISO-LATIN) char set * @param string */ private void write(String string) { write(string, "ISO-8859-1"); } private void write(String string, String charsetName) { OutputStreamWriter osw = isoLatinWriter; try { if (charsetName.equals("SIL-IPA93")) { if (simpleConverter == null) { simpleConverter = new SimpleConverter(null); } string = simpleConverter.toBinary(string); } else if (charsetName.equals("UTF-8")) { osw = utf8Writer; } osw.write(string); osw.flush(); } catch (Exception ex) { ex.printStackTrace(); } } /** * Try to close the file writers, catching and ignoring any exception. */ private void closeFile() { try { isoLatinWriter.flush(); utf8Writer.flush(); isoLatinWriter.close(); utf8Writer.close(); } catch (Exception ex) { } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -