diff --git a/src/org/exmaralda/common/corpusbuild/ReplaceTypesInCategory.java b/src/org/exmaralda/common/corpusbuild/ReplaceTypesInCategory.java new file mode 100644 index 00000000..2345f492 --- /dev/null +++ b/src/org/exmaralda/common/corpusbuild/ReplaceTypesInCategory.java @@ -0,0 +1,74 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package org.exmaralda.common.corpusbuild; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.exmaralda.partitureditor.jexmaralda.BasicTranscription; +import org.exmaralda.partitureditor.jexmaralda.Event; +import org.exmaralda.partitureditor.jexmaralda.Tier; +import org.xml.sax.SAXException; + +/** + * + * @author bernd + */ +public class ReplaceTypesInCategory extends AbstractCorpusChecker { + + + String category; + String type; + Map replacementMap; + public int allReplacementCounts = 0; + + public ReplaceTypesInCategory(String c, String t, Map rm) { + super(); + category = c; + type = t; + replacementMap = rm; + } + + + @Override + public void processTranscription(BasicTranscription bt, String currentFilename) throws URISyntaxException, SAXException { + for (int i=0; i0){ + try { + bt.writeXMLToFile(currentFilename, "none"); + } catch (IOException ex) { + Logger.getLogger(ReplaceTypesInCategory.class.getName()).log(Level.SEVERE, null, ex); + throw new SAXException(ex); + } + } + allReplacementCounts+=c; + + + + } + } + + +} diff --git a/src/org/exmaralda/folker/application/ApplicationFrame.java b/src/org/exmaralda/folker/application/ApplicationFrame.java index 597a5c92..90aee55b 100644 --- a/src/org/exmaralda/folker/application/ApplicationFrame.java +++ b/src/org/exmaralda/folker/application/ApplicationFrame.java @@ -294,7 +294,7 @@ public ImageIcon getWelcomeScreen() { public void resetSettings(){ try { java.util.prefs.Preferences.userRoot().node(getPreferencesNode()).clear(); - JOptionPane.showMessageDialog(rootPane, "Preferences reset.\nRestart the editor."); + JOptionPane.showMessageDialog(rootPane, "Preferences reset.
Restart the editor."); } catch (BackingStoreException ex) { Logger.getLogger(ApplicationFrame.class.getName()).log(Level.SEVERE, null, ex); JOptionPane.showMessageDialog(rootPane, "Problem resetting preferences:\n" + ex.getLocalizedMessage()); diff --git a/src/org/exmaralda/orthonormal/application/ApplicationFrame.java b/src/org/exmaralda/orthonormal/application/ApplicationFrame.java index 20e41c4d..fc9320eb 100644 --- a/src/org/exmaralda/orthonormal/application/ApplicationFrame.java +++ b/src/org/exmaralda/orthonormal/application/ApplicationFrame.java @@ -691,7 +691,7 @@ public void resetSettings(){ JOptionPane.showMessageDialog(rootPane, "Preferences reset.\nRestart the editor."); } catch (BackingStoreException ex) { ex.printStackTrace(); - JOptionPane.showMessageDialog(rootPane, "Problem resetting preferences:\n" + ex.getLocalizedMessage()); + JOptionPane.showMessageDialog(rootPane, "Preferences reset.
Restart the editor."); } } diff --git a/src/org/exmaralda/partitureditor/jexmaralda/AbstractEventTier.java b/src/org/exmaralda/partitureditor/jexmaralda/AbstractEventTier.java index a8b34c7a..b72258b4 100644 --- a/src/org/exmaralda/partitureditor/jexmaralda/AbstractEventTier.java +++ b/src/org/exmaralda/partitureditor/jexmaralda/AbstractEventTier.java @@ -298,8 +298,12 @@ public boolean respectsTimeline(Timeline tl){ /** bridges gaps, i.e. intervals (according to the given timeline) * that contain no events, if their duration (according to the absolute - * time values of the given timeline) is smaller than the parameter maxDiff */ - public void bridgeGaps(double maxDiff, Timeline tl){ + * time values of the given timeline) is smaller than the parameter maxDiff + * @param maxDiff + * @param tl + * @return */ + public int bridgeGaps(double maxDiff, Timeline tl){ + int count=0; tl.makeConsistent(); sort(tl); for (int pos=0; pos=0 && startTime>=0 && startTime-endTime referencedFiles = new Vector();; + private Vector referencedFiles = new Vector<>();; private UDInformationHashtable udMetaInformation; private String comment; private String transcriptionConvention; diff --git a/src/org/exmaralda/partitureditor/jexmaralda/Tier.java b/src/org/exmaralda/partitureditor/jexmaralda/Tier.java index 747766a9..bfcdbeba 100644 --- a/src/org/exmaralda/partitureditor/jexmaralda/Tier.java +++ b/src/org/exmaralda/partitureditor/jexmaralda/Tier.java @@ -274,6 +274,7 @@ public List> getSegmentChains(Timeline commonTimeline) { return result; } + diff --git a/src/org/exmaralda/partitureditor/jexmaralda/convert/WhisperJSONConverter.java b/src/org/exmaralda/partitureditor/jexmaralda/convert/WhisperJSONConverter.java index 1a62b21f..5f9f0ae2 100644 --- a/src/org/exmaralda/partitureditor/jexmaralda/convert/WhisperJSONConverter.java +++ b/src/org/exmaralda/partitureditor/jexmaralda/convert/WhisperJSONConverter.java @@ -91,6 +91,10 @@ public static BasicTranscription readWhisperJSON(File jsonFile, boolean wantsWor Timeline timeline = result.getBody().getCommonTimeline(); while (iterator.hasNext()){ JsonNode segmentNode = iterator.next(); + if (segmentNode.get("text")==null){ + String message = "Expected text node not found. Format may be wrong."; + throw new IOException(message); + } String text = segmentNode.get("text").asText(); if (text.trim().length()==0){ diff --git a/src/org/exmaralda/partitureditor/jexmaralda/errorChecker/Utilities.java b/src/org/exmaralda/partitureditor/jexmaralda/errorChecker/Utilities.java index 59a11d59..43ec49cb 100644 --- a/src/org/exmaralda/partitureditor/jexmaralda/errorChecker/Utilities.java +++ b/src/org/exmaralda/partitureditor/jexmaralda/errorChecker/Utilities.java @@ -73,8 +73,12 @@ public static Document makeEmptyDocument(){ public static Element makeError(String path, String tier, String start, String text) throws URISyntaxException{ Element e = new Element("error"); e.setAttribute("file", path); - e.setAttribute("tier", tier); - e.setAttribute("start", start); + if (tier!=null){ + e.setAttribute("tier", tier); + } + if (start!=null){ + e.setAttribute("start", start); + } e.setAttribute("done", "no"); e.setText(text); return e; diff --git a/src/org/exmaralda/partitureditor/jexmaralda/segment/InelEventBasedSegmentation.java b/src/org/exmaralda/partitureditor/jexmaralda/segment/InelEventBasedSegmentation.java index d44312eb..88867638 100644 --- a/src/org/exmaralda/partitureditor/jexmaralda/segment/InelEventBasedSegmentation.java +++ b/src/org/exmaralda/partitureditor/jexmaralda/segment/InelEventBasedSegmentation.java @@ -5,7 +5,6 @@ package org.exmaralda.partitureditor.jexmaralda.segment; import java.util.ArrayList; -import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -14,15 +13,12 @@ import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.MutableTreeNode; import org.exmaralda.partitureditor.fsm.FSMException; -import org.exmaralda.partitureditor.jexmaralda.AbstractSegment; import org.exmaralda.partitureditor.jexmaralda.Annotation; import org.exmaralda.partitureditor.jexmaralda.AtomicTimedSegment; import org.exmaralda.partitureditor.jexmaralda.BasicTranscription; import org.exmaralda.partitureditor.jexmaralda.Event; -import org.exmaralda.partitureditor.jexmaralda.Identifiable; import org.exmaralda.partitureditor.jexmaralda.JexmaraldaException; import org.exmaralda.partitureditor.jexmaralda.NonTimedSegment; import org.exmaralda.partitureditor.jexmaralda.SegmentList; @@ -70,24 +66,71 @@ public class InelEventBasedSegmentation extends AbstractSegmentation { @Override public Vector getSegmentationErrors(BasicTranscription bt) throws SAXException { - // just return empty for now + Vector result = new Vector<>(); + + SegmentedTranscription plainSegmented = bt.toSegmentedTranscription(); + for (int i=0; i parsedSegments = parseEvent(event); for (MutableTreeNode as : parsedSegments){ @@ -137,6 +181,7 @@ public SegmentedTranscription BasicToSegmented(BasicTranscription bt) throws SAX } if (utteranceEndPoints.contains(event.getEnd())){ currentUtterance.setEnd(event.getEnd()); + //checkParentheses(currentUtterance); currentUtterance = new TimedSegment(); currentUtterance.setID(tierID + ".u" + Integer.toString(uttCount)); currentUtterance.setName("INEL:u"); @@ -151,6 +196,8 @@ public SegmentedTranscription BasicToSegmented(BasicTranscription bt) throws SAX } if (!currentUtterance.children().hasMoreElements()){ targetSegmentChain.remove(currentUtterance); + } else { + //checkParentheses(currentUtterance); } } } @@ -174,12 +221,14 @@ public SegmentedTranscription BasicToSegmented(BasicTranscription bt) throws SAX private List parseEvent(TimedSegment event) throws FSMException { List result = new ArrayList<>(); String text = event.getDescription(); + + // **************************** if (text.startsWith("((")){ result.addAll(makeNonTimedSegments("((", event.getID() + ".1")); int endIndex = text.lastIndexOf("))"); if (endIndex<0){ FSMException ex = new FSMException("Unclosed double round brackets", text, event.getStart(), null); - throw(ex); + throw ex; } AtomicTimedSegment ats = new AtomicTimedSegment(); ats.setStart(event.getStart()); @@ -188,10 +237,16 @@ private List parseEvent(TimedSegment event) throws FSMException ats.setDescription(text.substring(2, endIndex)); ats.setID(event.getID() + ".ats"); result.add(ats); - result.addAll(makeNonTimedSegments(text.substring(endIndex), event.getID() + ".2")); + String remainingText = text.substring(endIndex); + if (!(remainingText.matches("[" + WORD_EXTERNAL_PUNCUTATION_REGEX + "]*"))){ + FSMException ex = new FSMException("Word characters after double closing round parentheses", text, event.getStart(), null); + throw ex; + } + result.addAll(makeNonTimedSegments(text.substring(endIndex), event.getID() + ".2")); return result; } - Pattern p = Pattern.compile("^[" + WORD_EXTERNAL_PUNCUTATION_REGEX + "]+"); + // **************************** + Pattern p = Pattern.compile("^[" + WORD_EXTERNAL_PUNCUTATION_REGEX + "]+"); // puncutation at the beginning Matcher m = p.matcher(text); if (m.find()){ int end = m.end(); @@ -199,11 +254,18 @@ private List parseEvent(TimedSegment event) throws FSMException text = text.substring(end); result.addAll(makeNonTimedSegments(punctuation, event.getID() + ".1")); } - p = Pattern.compile("[" + WORD_EXTERNAL_PUNCUTATION_REGEX + "]+$"); + p = Pattern.compile("[" + WORD_EXTERNAL_PUNCUTATION_REGEX + "]+$"); // puncutation at the end m = p.matcher(text); if (m.find()){ int start = m.start(); String word = text.substring(0, start); + p = Pattern.compile("[" + WORD_EXTERNAL_PUNCUTATION_REGEX + "]"); // puncutation anywhere + m = p.matcher(word); + if (m.find()){ + String parsedText = text.substring(0, m.start()); + FSMException ex = new FSMException("Punctutation between word characters", parsedText, event.getStart(), null); + throw ex; + } TimedSegment ts = new TimedSegment(); ts.setName("INEL:w"); ts.setStart(event.getStart()); @@ -214,6 +276,16 @@ private List parseEvent(TimedSegment event) throws FSMException String punctuation = text.substring(start); result.addAll(makeNonTimedSegments(punctuation, event.getID() + ".2")); } else { + // now there shouldn't be any puncutation inside text + // if there is, it is a segmentation error + p = Pattern.compile("[" + WORD_EXTERNAL_PUNCUTATION_REGEX + "]"); // puncutation anywhere + m = p.matcher(text); + if (m.find()){ + String parsedText = text.substring(0, m.start()); + FSMException ex = new FSMException("Punctutation between word characters", parsedText, event.getStart(), null); + throw ex; + } + TimedSegment ts = new TimedSegment(); ts.setName("INEL:w"); ts.setStart(event.getStart()); @@ -226,7 +298,7 @@ private List parseEvent(TimedSegment event) throws FSMException return result; } - private List makeNonTimedSegments(String text, String baseID) { + private List makeNonTimedSegments(String text, String baseID) throws FSMException { List result = new ArrayList<>(); int i=1; for (char c : text.toCharArray()){ @@ -239,5 +311,27 @@ private List makeNonTimedSegments(String text, String baseID) { } return result; } + + private void checkParentheses(TimedSegment currentUtterance) throws FSMException { + Vector allParentheses = currentUtterance.getAllSegmentsWithName("INEL:ip"); + boolean parenthOpen = false; + for (Object o : allParentheses){ + NonTimedSegment pSegment = (NonTimedSegment)o; + if (pSegment.getDescription().equals("(")){ + if (parenthOpen){ + // don't care where the error is? + FSMException ex = new FSMException("Non-matching parenthesis", null, null, null); + throw ex; + } + parenthOpen = true; + } + parenthOpen = parenthOpen && (!(pSegment.getDescription().equals(")"))); + System.out.println(pSegment.getDescription() + " " + Boolean.toString(parenthOpen)); + } + if (parenthOpen){ + FSMException ex = new FSMException("Non-matching parenthesis", null, null, null); + throw ex; + } + } } diff --git a/src/org/exmaralda/partitureditor/jexmaraldaswing/CleanupDialog.form b/src/org/exmaralda/partitureditor/jexmaraldaswing/CleanupDialog.form index 7c6e3ce7..7aae9f73 100644 --- a/src/org/exmaralda/partitureditor/jexmaraldaswing/CleanupDialog.form +++ b/src/org/exmaralda/partitureditor/jexmaraldaswing/CleanupDialog.form @@ -25,7 +25,7 @@ - + @@ -34,10 +34,23 @@ - + - + + + + + + + + + + + + + + @@ -50,7 +63,7 @@ - + @@ -81,7 +94,7 @@ - + @@ -108,7 +121,7 @@ - + @@ -121,7 +134,7 @@ - + @@ -145,7 +158,7 @@ - + @@ -171,7 +184,7 @@ - + diff --git a/src/org/exmaralda/partitureditor/jexmaraldaswing/CleanupDialog.java b/src/org/exmaralda/partitureditor/jexmaraldaswing/CleanupDialog.java index be56c41d..cfac129c 100644 --- a/src/org/exmaralda/partitureditor/jexmaraldaswing/CleanupDialog.java +++ b/src/org/exmaralda/partitureditor/jexmaraldaswing/CleanupDialog.java @@ -25,6 +25,11 @@ public CleanupDialog(java.awt.Frame parent, boolean modal) { Internationalizer.internationalizeDialogToolTips(this); } + public boolean removeUnusedSpeakers(){ + return removeUnusedSpeakersCheckBox.isSelected(); + } + + public boolean removeEmptyEvents(){ return removeEmptyEventsCheckBox.isSelected(); } @@ -67,26 +72,28 @@ public boolean normalizeIDs(){ // //GEN-BEGIN:initComponents private void initComponents() { - jPanel1 = new javax.swing.JPanel(); - jPanel3 = new javax.swing.JPanel(); + mainPanel = new javax.swing.JPanel(); + removeUnusedSpeakersPanel = new javax.swing.JPanel(); + removeUnusedSpeakersCheckBox = new javax.swing.JCheckBox(); + removeEmtpyEventsPanel = new javax.swing.JPanel(); removeEmptyEventsCheckBox = new javax.swing.JCheckBox(); - jPanel8 = new javax.swing.JPanel(); + smoothTimelinePanel = new javax.swing.JPanel(); smoothTimelineCheckBox = new javax.swing.JCheckBox(); smoothTimelineSlider = new javax.swing.JSlider(); jLabel2 = new javax.swing.JLabel(); - jPanel4 = new javax.swing.JPanel(); + bridgeGapsPanel = new javax.swing.JPanel(); bridgeGapsCheckBox = new javax.swing.JCheckBox(); bridgeGapsSlider = new javax.swing.JSlider(); jLabel1 = new javax.swing.JLabel(); - jPanel5 = new javax.swing.JPanel(); + removeUnusedTimelineITemsPanel = new javax.swing.JPanel(); removeUnusedTLICheckBox = new javax.swing.JCheckBox(); - jPanel6 = new javax.swing.JPanel(); + removeGapsPanel = new javax.swing.JPanel(); removeGapsCheckBox = new javax.swing.JCheckBox(); jLabel4 = new javax.swing.JLabel(); - jPanel7 = new javax.swing.JPanel(); + normalizeIDsPanel = new javax.swing.JPanel(); normalizeIDsCheckBox = new javax.swing.JCheckBox(); jLabel3 = new javax.swing.JLabel(); - jPanel2 = new javax.swing.JPanel(); + okCancelPanel = new javax.swing.JPanel(); okButton = new javax.swing.JButton(); cancelButton = new javax.swing.JButton(); @@ -97,23 +104,32 @@ public void windowClosing(java.awt.event.WindowEvent evt) { } }); - jPanel1.setLayout(new java.awt.GridLayout(6, 1)); + mainPanel.setLayout(new java.awt.GridLayout(7, 1)); + + removeUnusedSpeakersPanel.setLayout(new javax.swing.BoxLayout(removeUnusedSpeakersPanel, javax.swing.BoxLayout.LINE_AXIS)); + + removeUnusedSpeakersCheckBox.setSelected(true); + removeUnusedSpeakersCheckBox.setText("Remove unused speakers"); + removeUnusedSpeakersCheckBox.setToolTipText("Remove events without a description"); + removeUnusedSpeakersPanel.add(removeUnusedSpeakersCheckBox); + + mainPanel.add(removeUnusedSpeakersPanel); - jPanel3.setLayout(new javax.swing.BoxLayout(jPanel3, javax.swing.BoxLayout.LINE_AXIS)); + removeEmtpyEventsPanel.setLayout(new javax.swing.BoxLayout(removeEmtpyEventsPanel, javax.swing.BoxLayout.LINE_AXIS)); removeEmptyEventsCheckBox.setSelected(true); removeEmptyEventsCheckBox.setText("Remove empty events"); removeEmptyEventsCheckBox.setToolTipText("Remove events without a description"); - jPanel3.add(removeEmptyEventsCheckBox); + removeEmtpyEventsPanel.add(removeEmptyEventsCheckBox); - jPanel1.add(jPanel3); + mainPanel.add(removeEmtpyEventsPanel); - jPanel8.setLayout(new javax.swing.BoxLayout(jPanel8, javax.swing.BoxLayout.LINE_AXIS)); + smoothTimelinePanel.setLayout(new javax.swing.BoxLayout(smoothTimelinePanel, javax.swing.BoxLayout.LINE_AXIS)); smoothTimelineCheckBox.setSelected(true); smoothTimelineCheckBox.setText("Smooth timeline with a threshhold of"); smoothTimelineCheckBox.setToolTipText("Treat nearby timeline items as identical "); - jPanel8.add(smoothTimelineCheckBox); + smoothTimelinePanel.add(smoothTimelineCheckBox); smoothTimelineSlider.setMajorTickSpacing(50); smoothTimelineSlider.setMaximum(200); @@ -122,70 +138,70 @@ public void windowClosing(java.awt.event.WindowEvent evt) { smoothTimelineSlider.setPaintTicks(true); smoothTimelineSlider.setValue(10); smoothTimelineSlider.setPreferredSize(new java.awt.Dimension(180, 47)); - jPanel8.add(smoothTimelineSlider); + smoothTimelinePanel.add(smoothTimelineSlider); jLabel2.setText(" ms"); - jPanel8.add(jLabel2); + smoothTimelinePanel.add(jLabel2); - jPanel1.add(jPanel8); + mainPanel.add(smoothTimelinePanel); - jPanel4.setLayout(new javax.swing.BoxLayout(jPanel4, javax.swing.BoxLayout.LINE_AXIS)); + bridgeGapsPanel.setLayout(new javax.swing.BoxLayout(bridgeGapsPanel, javax.swing.BoxLayout.LINE_AXIS)); bridgeGapsCheckBox.setSelected(true); bridgeGapsCheckBox.setText("Bridge gaps smaller than "); bridgeGapsCheckBox.setToolTipText("Treat nearby timeline items as identical if the corresponding interval is a gap"); - jPanel4.add(bridgeGapsCheckBox); + bridgeGapsPanel.add(bridgeGapsCheckBox); bridgeGapsSlider.setMajorTickSpacing(250); bridgeGapsSlider.setMaximum(1000); bridgeGapsSlider.setMinorTickSpacing(100); bridgeGapsSlider.setPaintLabels(true); bridgeGapsSlider.setPaintTicks(true); - jPanel4.add(bridgeGapsSlider); + bridgeGapsPanel.add(bridgeGapsSlider); jLabel1.setText(" ms"); - jPanel4.add(jLabel1); + bridgeGapsPanel.add(jLabel1); - jPanel1.add(jPanel4); + mainPanel.add(bridgeGapsPanel); - jPanel5.setLayout(new javax.swing.BoxLayout(jPanel5, javax.swing.BoxLayout.LINE_AXIS)); + removeUnusedTimelineITemsPanel.setLayout(new javax.swing.BoxLayout(removeUnusedTimelineITemsPanel, javax.swing.BoxLayout.LINE_AXIS)); removeUnusedTLICheckBox.setSelected(true); removeUnusedTLICheckBox.setText("Remove unused timeline items"); removeUnusedTLICheckBox.setToolTipText("Remove timeline items where no event starts or ends"); - jPanel5.add(removeUnusedTLICheckBox); + removeUnusedTimelineITemsPanel.add(removeUnusedTLICheckBox); - jPanel1.add(jPanel5); + mainPanel.add(removeUnusedTimelineITemsPanel); - jPanel6.setLayout(new javax.swing.BoxLayout(jPanel6, javax.swing.BoxLayout.LINE_AXIS)); + removeGapsPanel.setLayout(new javax.swing.BoxLayout(removeGapsPanel, javax.swing.BoxLayout.LINE_AXIS)); removeGapsCheckBox.setText("Remove gaps"); removeGapsCheckBox.setToolTipText("Remove gaps in the timeline (i.e. join events interrupted only by stretches of empty events, remove the intervening timeline items)"); - jPanel6.add(removeGapsCheckBox); + removeGapsPanel.add(removeGapsCheckBox); jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N jLabel4.setForeground(java.awt.Color.red); jLabel4.setText(" [USE WITH CAUTION!]"); jLabel4.setToolTipText("Removing gaps s can have unintended side effects. Use this option only if you are very sure you know what you are doing. Make a safety backup of your file first."); - jPanel6.add(jLabel4); + removeGapsPanel.add(jLabel4); - jPanel1.add(jPanel6); + mainPanel.add(removeGapsPanel); - jPanel7.setLayout(new javax.swing.BoxLayout(jPanel7, javax.swing.BoxLayout.LINE_AXIS)); + normalizeIDsPanel.setLayout(new javax.swing.BoxLayout(normalizeIDsPanel, javax.swing.BoxLayout.LINE_AXIS)); normalizeIDsCheckBox.setText("Normalize IDs"); normalizeIDsCheckBox.setToolTipText("Normalize speaker, tier and timeline IDs - disabled, suspected to cause a serious bug with larg files"); - jPanel7.add(normalizeIDsCheckBox); + normalizeIDsPanel.add(normalizeIDsCheckBox); jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N jLabel3.setForeground(java.awt.Color.red); jLabel3.setText(" [USE WITH CAUTION!]"); jLabel3.setToolTipText("Normalizing IDs can have unintended side effects. Use this option only if you are very sure you know what you are doing. Make a safety backup of your file first."); - jPanel7.add(jLabel3); + normalizeIDsPanel.add(jLabel3); - jPanel1.add(jPanel7); + mainPanel.add(normalizeIDsPanel); - getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER); + getContentPane().add(mainPanel, java.awt.BorderLayout.CENTER); okButton.setText("OK"); okButton.setMaximumSize(new java.awt.Dimension(110, 27)); @@ -196,7 +212,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { okButtonActionPerformed(evt); } }); - jPanel2.add(okButton); + okCancelPanel.add(okButton); cancelButton.setText("Cancel"); cancelButton.setMaximumSize(new java.awt.Dimension(110, 27)); @@ -206,9 +222,9 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { cancelButtonActionPerformed(evt); } }); - jPanel2.add(cancelButton); + okCancelPanel.add(cancelButton); - getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH); + getContentPane().add(okCancelPanel, java.awt.BorderLayout.SOUTH); pack(); }// //GEN-END:initComponents @@ -244,26 +260,28 @@ public static void main(String args[]) { // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JCheckBox bridgeGapsCheckBox; + private javax.swing.JPanel bridgeGapsPanel; private javax.swing.JSlider bridgeGapsSlider; private javax.swing.JButton cancelButton; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; - private javax.swing.JPanel jPanel1; - private javax.swing.JPanel jPanel2; - private javax.swing.JPanel jPanel3; - private javax.swing.JPanel jPanel4; - private javax.swing.JPanel jPanel5; - private javax.swing.JPanel jPanel6; - private javax.swing.JPanel jPanel7; - private javax.swing.JPanel jPanel8; + private javax.swing.JPanel mainPanel; private javax.swing.JCheckBox normalizeIDsCheckBox; + private javax.swing.JPanel normalizeIDsPanel; private javax.swing.JButton okButton; + private javax.swing.JPanel okCancelPanel; private javax.swing.JCheckBox removeEmptyEventsCheckBox; + private javax.swing.JPanel removeEmtpyEventsPanel; private javax.swing.JCheckBox removeGapsCheckBox; + private javax.swing.JPanel removeGapsPanel; + private javax.swing.JCheckBox removeUnusedSpeakersCheckBox; + private javax.swing.JPanel removeUnusedSpeakersPanel; private javax.swing.JCheckBox removeUnusedTLICheckBox; + private javax.swing.JPanel removeUnusedTimelineITemsPanel; private javax.swing.JCheckBox smoothTimelineCheckBox; + private javax.swing.JPanel smoothTimelinePanel; private javax.swing.JSlider smoothTimelineSlider; // End of variables declaration//GEN-END:variables diff --git a/src/org/exmaralda/partitureditor/jexmaraldaswing/EditPreferencesDialog.form b/src/org/exmaralda/partitureditor/jexmaraldaswing/EditPreferencesDialog.form index e33d6faa..b3ed6a9d 100644 --- a/src/org/exmaralda/partitureditor/jexmaraldaswing/EditPreferencesDialog.form +++ b/src/org/exmaralda/partitureditor/jexmaraldaswing/EditPreferencesDialog.form @@ -1305,17 +1305,17 @@ - + - + - + diff --git a/src/org/exmaralda/partitureditor/jexmaraldaswing/EditPreferencesDialog.java b/src/org/exmaralda/partitureditor/jexmaraldaswing/EditPreferencesDialog.java index b5f6da1a..07314cb4 100644 --- a/src/org/exmaralda/partitureditor/jexmaraldaswing/EditPreferencesDialog.java +++ b/src/org/exmaralda/partitureditor/jexmaraldaswing/EditPreferencesDialog.java @@ -907,13 +907,13 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { jLabel17.setText(" "); languagePanel.add(jLabel17); - jLabel18.setText("Choose your language, then restart the Partitur-Editor."); + jLabel18.setText("Choose your language, then restart the Partitur-Editor."); languagePanel.add(jLabel18); - jLabel19.setText("Waehlen Sie Ihre Sprache, und starten Sie dann den Partitur-Editor neu."); + jLabel19.setText("Wählen Sie Ihre Sprache, und starten Sie dann den Partitur-Editor neu."); languagePanel.add(jLabel19); - jLabel20.setText("Choisissez votre langue, puis redémarrez le Partitur-Editor."); + jLabel20.setText("Choisissez votre langue, puis redémarrez le Partitur-Editor."); languagePanel.add(jLabel20); tabbedPane.addTab("Language", languagePanel); diff --git a/src/org/exmaralda/partitureditor/jexmaraldaswing/SelectMediaFileDialog.form b/src/org/exmaralda/partitureditor/jexmaraldaswing/SelectMediaFileDialog.form new file mode 100644 index 00000000..8bf2e51f --- /dev/null +++ b/src/org/exmaralda/partitureditor/jexmaraldaswing/SelectMediaFileDialog.form @@ -0,0 +1,106 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/org/exmaralda/partitureditor/jexmaraldaswing/SelectMediaFileDialog.java b/src/org/exmaralda/partitureditor/jexmaraldaswing/SelectMediaFileDialog.java new file mode 100644 index 00000000..51ceea65 --- /dev/null +++ b/src/org/exmaralda/partitureditor/jexmaraldaswing/SelectMediaFileDialog.java @@ -0,0 +1,154 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JDialog.java to edit this template + */ +package org.exmaralda.partitureditor.jexmaraldaswing; + +import java.io.File; +import javax.swing.DefaultComboBoxModel; + +/** + * + * @author bernd + */ +public class SelectMediaFileDialog extends javax.swing.JDialog { + + public boolean approved = false; + /** + * Creates new form SelectMediaFileDialog + */ + public SelectMediaFileDialog(java.awt.Frame parent, boolean modal, File[] files) { + super(parent, modal); + initComponents(); + DefaultComboBoxModel dcbm = new DefaultComboBoxModel(); + for (File f : files){ + dcbm.addElement(f); + } + filesComboBox.setModel(dcbm); + filesComboBox.setRenderer(new RecordingsListCellRenderer()); + } + + public File getSelectedFile(){ + return (File)filesComboBox.getSelectedItem(); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + mainPanel = new javax.swing.JPanel(); + jPanel2 = new javax.swing.JPanel(); + jLabel1 = new javax.swing.JLabel(); + jPanel1 = new javax.swing.JPanel(); + filesComboBox = new javax.swing.JComboBox<>(); + buttonPanel = new javax.swing.JPanel(); + addSelectedButton = new javax.swing.JButton(); + cancelButton = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setTitle("Add a recording"); + + mainPanel.setLayout(new javax.swing.BoxLayout(mainPanel, javax.swing.BoxLayout.Y_AXIS)); + + jLabel1.setText("The following media files were found in the directory of the transcription file.
Do you want to add one of them? "); + jPanel2.add(jLabel1); + + mainPanel.add(jPanel2); + + filesComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); + filesComboBox.setMinimumSize(new java.awt.Dimension(400, 50)); + filesComboBox.setPreferredSize(new java.awt.Dimension(500, 50)); + jPanel1.add(filesComboBox); + + mainPanel.add(jPanel1); + + getContentPane().add(mainPanel, java.awt.BorderLayout.CENTER); + + addSelectedButton.setText("Add selected file"); + addSelectedButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + addSelectedButtonActionPerformed(evt); + } + }); + buttonPanel.add(addSelectedButton); + + cancelButton.setText("Cancel"); + cancelButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + cancelButtonActionPerformed(evt); + } + }); + buttonPanel.add(cancelButton); + + getContentPane().add(buttonPanel, java.awt.BorderLayout.SOUTH); + + pack(); + }//
//GEN-END:initComponents + + private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed + this.dispose(); + }//GEN-LAST:event_cancelButtonActionPerformed + + private void addSelectedButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addSelectedButtonActionPerformed + approved = true; + this.dispose(); + }//GEN-LAST:event_addSelectedButtonActionPerformed + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(SelectMediaFileDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(SelectMediaFileDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(SelectMediaFileDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(SelectMediaFileDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the dialog */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + SelectMediaFileDialog dialog = new SelectMediaFileDialog(new javax.swing.JFrame(), true, null); + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + @Override + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton addSelectedButton; + private javax.swing.JPanel buttonPanel; + private javax.swing.JButton cancelButton; + private javax.swing.JComboBox filesComboBox; + private javax.swing.JLabel jLabel1; + private javax.swing.JPanel jPanel1; + private javax.swing.JPanel jPanel2; + private javax.swing.JPanel mainPanel; + // End of variables declaration//GEN-END:variables +} diff --git a/src/org/exmaralda/partitureditor/jexmaraldaswing/TypesDialog.form b/src/org/exmaralda/partitureditor/jexmaraldaswing/TypesDialog.form index 0d763695..99ca32cc 100644 --- a/src/org/exmaralda/partitureditor/jexmaraldaswing/TypesDialog.form +++ b/src/org/exmaralda/partitureditor/jexmaraldaswing/TypesDialog.form @@ -71,7 +71,7 @@ - + @@ -79,7 +79,7 @@ - + diff --git a/src/org/exmaralda/partitureditor/jexmaraldaswing/TypesDialog.java b/src/org/exmaralda/partitureditor/jexmaraldaswing/TypesDialog.java index 0b46e630..800df1b0 100644 --- a/src/org/exmaralda/partitureditor/jexmaraldaswing/TypesDialog.java +++ b/src/org/exmaralda/partitureditor/jexmaraldaswing/TypesDialog.java @@ -88,7 +88,7 @@ public Class getColumnClass(int columnIndex) { getContentPane().add(mainPanel, java.awt.BorderLayout.CENTER); - okButton.setText("OK"); + okButton.setText("OK (Map types)"); okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { okButtonActionPerformed(evt); @@ -96,7 +96,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { }); okCancelPanel.add(okButton); - cancelButton.setText("Cancel"); + cancelButton.setText("Close"); cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelButtonActionPerformed(evt); diff --git a/src/org/exmaralda/partitureditor/jexmaraldaswing/fileFilters/MediaFileFilter.java b/src/org/exmaralda/partitureditor/jexmaraldaswing/fileFilters/MediaFileFilter.java index 56ce17d5..5579e477 100644 --- a/src/org/exmaralda/partitureditor/jexmaraldaswing/fileFilters/MediaFileFilter.java +++ b/src/org/exmaralda/partitureditor/jexmaraldaswing/fileFilters/MediaFileFilter.java @@ -30,6 +30,7 @@ private String getExtension(File f) { return ext; } + @Override public boolean accept(File f) { if (f.isDirectory()) { return true; @@ -37,16 +38,17 @@ public boolean accept(File f) { String extension = getExtension(f); if (extension != null) { - for (int i=0; itimeline.getNumberOfTimelineItems()-1){ + timeline.addTimelineItem(); + fireColumnsAdded(col,col); + } String tli = timeline.getTimelineItemAt(col).getID(); String previousTLI = ""; if (col>0){ diff --git a/src/org/exmaralda/partitureditor/partiture/PartiturEditor.java b/src/org/exmaralda/partitureditor/partiture/PartiturEditor.java index 15549dc5..79459599 100644 --- a/src/org/exmaralda/partitureditor/partiture/PartiturEditor.java +++ b/src/org/exmaralda/partitureditor/partiture/PartiturEditor.java @@ -494,7 +494,7 @@ private void loadSettings(){ int optionChosen = JOptionPane.showConfirmDialog(rootPane, message); if (optionChosen == JOptionPane.YES_OPTION){ settings.put("PlayerType", defaultPlayer); - JOptionPane.showMessageDialog(rootPane, "Please restart the Partitur-Editor \nfor the changes to take effect."); + JOptionPane.showMessageDialog(rootPane, "Please restart the Partitur-Editor
for the changes to take effect."); } settings.putBoolean("PlayerTypeConfirmed", true); } diff --git a/src/org/exmaralda/partitureditor/partiture/editActions/CleanupAction.java b/src/org/exmaralda/partitureditor/partiture/editActions/CleanupAction.java index 8c17b1d4..67b862ce 100644 --- a/src/org/exmaralda/partitureditor/partiture/editActions/CleanupAction.java +++ b/src/org/exmaralda/partitureditor/partiture/editActions/CleanupAction.java @@ -6,6 +6,9 @@ package org.exmaralda.partitureditor.partiture.editActions; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.JOptionPane; import org.exmaralda.partitureditor.jexmaralda.BasicTranscription; import org.exmaralda.partitureditor.jexmaralda.JexmaraldaException; import org.exmaralda.partitureditor.jexmaralda.TierFormat; @@ -35,21 +38,51 @@ public void actionPerformed(java.awt.event.ActionEvent actionEvent) { private void cleanup(){ CleanupDialog dialog = new CleanupDialog(table.parent, true); + + int howManyUnusedSpeakers = 0; + int howManyEmptyEvents = 0; + int howManyGapsBridged = 0; + int howManyUnusedTimelineItems = 0; + int howManySmoothed = 0; + int howManyGapsRemoved = 0; + if (dialog.editCleanupParameters()){ if (table.undoEnabled){ UndoInformation undoInfo = new UndoInformation(table, "Cleanup"); undoInfo.memorizeTranscription(table); table.addUndo(undoInfo); } + + + + if (dialog.removeUnusedSpeakers()){ + try { + howManyUnusedSpeakers = table.getModel().getTranscription().removeUnusedSpeakers(); + } catch (JexmaraldaException ex) { + Logger.getLogger(CleanupAction.class.getName()).log(Level.SEVERE, null, ex); + } + } + + for (int pos=0; pos"; + message+= Integer.toString(howManyEmptyEvents) + " empty events removed.
"; + message+= Integer.toString(howManyGapsBridged) + " gaps bridged.
"; + message+= Integer.toString(howManyUnusedTimelineItems) + " unused timeline items removed.
"; + message+= Integer.toString(howManySmoothed) + " timeline items smoothed.
"; + message+= Integer.toString(howManyGapsRemoved) + " gaps removed.
"; + message+=""; + + JOptionPane.showMessageDialog(table, message, "Clenup performed", JOptionPane.INFORMATION_MESSAGE); + table.getModel().setTranscription(table.getModel().getTranscription()); + table.status("Cleanup performed. "); } } diff --git a/src/org/exmaralda/partitureditor/partiture/editActions/EditPreferencesAction.java b/src/org/exmaralda/partitureditor/partiture/editActions/EditPreferencesAction.java index f5cea37c..66b35df5 100644 --- a/src/org/exmaralda/partitureditor/partiture/editActions/EditPreferencesAction.java +++ b/src/org/exmaralda/partitureditor/partiture/editActions/EditPreferencesAction.java @@ -204,9 +204,9 @@ private void editPreferences(java.awt.event.ActionEvent evt){ table.status("Preferences changed"); if (!newValues[16].equals(oldMediaPlayer)){ - String message = "You have changed the player from \n" - + oldMediaPlayer + " to " + newValues[16] + ".\n" - + "You must restart the Partitur-Editor \nfor this change to take effect."; + String message = "You have changed the player from
" + + oldMediaPlayer + " to " + newValues[16] + ".
" + + "You must restart the Partitur-Editor
for this change to take effect."; JOptionPane.showMessageDialog(table, message); } diff --git a/src/org/exmaralda/partitureditor/partiture/fileActions/ImportAction.java b/src/org/exmaralda/partitureditor/partiture/fileActions/ImportAction.java index 134fbdf5..9611c694 100644 --- a/src/org/exmaralda/partitureditor/partiture/fileActions/ImportAction.java +++ b/src/org/exmaralda/partitureditor/partiture/fileActions/ImportAction.java @@ -15,15 +15,22 @@ import org.exmaralda.partitureditor.jexmaralda.*; import org.exmaralda.partitureditor.jexmaralda.convert.*; import java.io.*; +import java.util.Arrays; +import java.util.Comparator; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JFrame; +import javax.swing.JOptionPane; import org.exmaralda.common.ExmaraldaApplication; import org.exmaralda.common.dialogs.ProgressBarDialog; import org.exmaralda.folker.utilities.PreferencesUtilities; import org.exmaralda.partitureditor.jexmaraldaswing.ChooseTextSplitterDialog; +import org.exmaralda.partitureditor.jexmaraldaswing.SelectMediaFileDialog; import org.exmaralda.partitureditor.jexmaraldaswing.fileDialogs.WhisperImportPostProcessDialog; +import org.exmaralda.partitureditor.jexmaraldaswing.fileFilters.MediaFileFilter; import org.jdom.JDOMException; import org.xml.sax.SAXException; @@ -421,6 +428,14 @@ public void run() { table.stratify(importedTranscription); } + //System.out.println("RF: " + importedTranscription.getHead().getMetaInformation().getReferencedFile()); + // weird check to really know whether or not there is a referenced file + if (importedTranscription.getHead().getMetaInformation().getReferencedFile()==null + || importedTranscription.getHead().getMetaInformation().getReferencedFile().trim().length()==0 + || importedTranscription.getHead().getMetaInformation().getReferencedFiles().isEmpty()){ + guessMedia(importedTranscription, filename); + } + table.getModel().setTranscription(importedTranscription); table.setupMedia(); table.setupPraatPanel(); @@ -442,5 +457,46 @@ public void run() { } } + private void guessMedia(BasicTranscription importedTranscription, String filename) { + Set permissibleSuffixes = new HashSet<>(); + permissibleSuffixes.addAll(Arrays.asList(MediaFileFilter.ACCEPTED_SUFFIXES)); + File file = new File(filename); + File[] mediaFileCandidates = file.getParentFile().listFiles(new FilenameFilter(){ + @Override + public boolean accept(File dir, String name) { + int index = name.lastIndexOf("."); + if (index<0) return false; + String suffix = name.substring(index+1); + return permissibleSuffixes.contains(suffix.toLowerCase()); + } + }); + if (mediaFileCandidates.length>0){ + Arrays.sort(mediaFileCandidates, new Comparator(){ + @Override + public int compare(File o1, File o2) { + String name1 = o1.getName().substring(0, o1.getName().lastIndexOf(".")); + String name2 = o2.getName().substring(0, o2.getName().lastIndexOf(".")); + if (filename.startsWith(name1)){ + return -1; + } + if (filename.startsWith(name2)){ + return 1; + } + return 0; + } + + }); + + SelectMediaFileDialog dialog = new SelectMediaFileDialog(table.parent, true, mediaFileCandidates); + dialog.setLocationRelativeTo(table); + dialog.setVisible(true); + if (dialog.approved){ + importedTranscription.getHead().getMetaInformation().setReferencedFile(dialog.getSelectedFile().getAbsolutePath()); + } + } + + + } + } \ No newline at end of file diff --git a/src/org/exmaralda/partitureditor/partiture/tierActions/TypesAction.java b/src/org/exmaralda/partitureditor/partiture/tierActions/TypesAction.java index 9bc21058..a76261bb 100644 --- a/src/org/exmaralda/partitureditor/partiture/tierActions/TypesAction.java +++ b/src/org/exmaralda/partitureditor/partiture/tierActions/TypesAction.java @@ -67,7 +67,7 @@ private void types(){ typesDialog.setLocationRelativeTo(table); typesDialog.setVisible(true); if (typesDialog.approved){ - Map mappings = typesDialog.getMappings(); + Map mappings = typesDialog.getMappings(); int count = 0; for (String sourceType : mappings.keySet()){ String targetType = mappings.get(sourceType);