Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
berndmoos committed May 27, 2024
1 parent c52b1dc commit 8d707d2
Show file tree
Hide file tree
Showing 24 changed files with 692 additions and 103 deletions.
74 changes: 74 additions & 0 deletions src/org/exmaralda/common/corpusbuild/ReplaceTypesInCategory.java
Original file line number Diff line number Diff line change
@@ -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<String, String> replacementMap;
public int allReplacementCounts = 0;

public ReplaceTypesInCategory(String c, String t, Map<String, String> rm) {
super();
category = c;
type = t;
replacementMap = rm;
}


@Override
public void processTranscription(BasicTranscription bt, String currentFilename) throws URISyntaxException, SAXException {
for (int i=0; i<bt.getBody().getNumberOfTiers(); i++){
Tier tier = bt.getBody().getTierAt(i);
boolean isRelevantTier = (type==null || type.equals(tier.getType())) && category.equals(tier.getCategory());
if ((!isRelevantTier)) continue;

int c = 0;
for (String sourceType : replacementMap.keySet()){
String targetType = replacementMap.get(sourceType);
if (!(sourceType.equals(targetType))){
for (int pos=0 ; pos<tier.getNumberOfEvents(); pos++){
Event event = tier.getEventAt(pos);
if (sourceType.equals(event.getDescription())){
event.setDescription(targetType);
c++;
}
}
}
}

if (c>0){
try {
bt.writeXMLToFile(currentFilename, "none");
} catch (IOException ex) {
Logger.getLogger(ReplaceTypesInCategory.class.getName()).log(Level.SEVERE, null, ex);
throw new SAXException(ex);
}
}
allReplacementCounts+=c;



}
}


}
2 changes: 1 addition & 1 deletion src/org/exmaralda/folker/application/ApplicationFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<html>Preferences reset.<br/><b>Restart the editor.</b></html>");
} catch (BackingStoreException ex) {
Logger.getLogger(ApplicationFrame.class.getName()).log(Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(rootPane, "Problem resetting preferences:\n" + ex.getLocalizedMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<html>Preferences reset.<br/><b>Restart the editor.</b></html>");
}
}

Expand Down
22 changes: 17 additions & 5 deletions src/org/exmaralda/partitureditor/jexmaralda/AbstractEventTier.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<getNumberOfEvents()-1; pos++){
Expand All @@ -311,12 +315,16 @@ public void bridgeGaps(double maxDiff, Timeline tl){
try {
endTime = tl.getTimelineItemWithID(event.getEnd()).getTime();
startTime = tl.getTimelineItemWithID(nextEvent.getStart()).getTime();
} catch (JexmaraldaException je) {return;}
} catch (JexmaraldaException je) {
return -1;
}
if (endTime>=0 && startTime>=0 && startTime-endTime<maxDiff){
event.setEnd(nextEvent.getStart());
count++;
}
updatePositions();
}
return count;
}

/** returns the IDs of all start points of the events contained in this tier */
Expand Down Expand Up @@ -503,16 +511,20 @@ public String repair(Timeline timeline){


/** removes all empty events from this tier, i.e.
* all events that contain nothing but white space */
public void removeEmptyEvents(){
* all events that contain nothing but white space
* @return */
public int removeEmptyEvents(){
int count=0;
for (int pos=0; pos<getNumberOfEvents(); pos++){
Event event = getEventAt(pos);
if (event.getDescription().trim().length()<=0){
this.removeElementAt(pos);
pos--;
count++;
}
}
updatePositions();
return count;
}

/** checks whether this tier is stratified, i.e. whether it does not contain any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class MetaInformation extends Object {
private String projectName;
private String transcriptionName;
//private String referencedFile;
private Vector<String> referencedFiles = new Vector<String>();;
private Vector<String> referencedFiles = new Vector<>();;
private UDInformationHashtable udMetaInformation;
private String comment;
private String transcriptionConvention;
Expand Down
1 change: 1 addition & 0 deletions src/org/exmaralda/partitureditor/jexmaralda/Tier.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ public List<List<Event>> getSegmentChains(Timeline commonTimeline) {
return result;
}





Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 8d707d2

Please sign in to comment.