corpus-services  1.0
ExbStructureChecker.java
Go to the documentation of this file.
1 
10 package de.uni_hamburg.corpora.validation;
11 
17 import java.io.IOException;
18 import java.io.File;
19 import java.util.Hashtable;
20 import java.util.Collection;
21 import org.xml.sax.SAXException;
23 import java.net.URISyntaxException;
24 import javax.xml.parsers.ParserConfigurationException;
25 import javax.xml.transform.TransformerException;
26 import javax.xml.xpath.XPathExpressionException;
27 import org.exmaralda.partitureditor.jexmaralda.BasicTranscription;
28 import org.exmaralda.partitureditor.jexmaralda.JexmaraldaException;
29 import org.jdom.JDOMException;
30 
35 public class ExbStructureChecker extends Checker implements CorpusFunction {
36 
37  BasicTranscription bt;
38  File exbfile;
39  ValidatorSettings settings;
40  String filename;
41 
43  //fixing is not possible
44  super(false);
45  }
46 
51  @Override
52  public Report function(CorpusData cd, Boolean fix)
53  throws SAXException, JDOMException, IOException, JexmaraldaException {
54  Report stats = new Report();
56  filename = cd.getFilename();
57  bt = btd.getEXMARaLDAbt();
58 
59  String[] duplicateTranscriptionTiers
60  = bt.getDuplicateTranscriptionTiers();
61  String[] orphanedTranscriptionTiers
62  = bt.getOrphanedTranscriptionTiers();
63  String[] orphanedAnnotationTiers = bt.getOrphanedAnnotationTiers();
64  String[] temporalAnomalies
65  = bt.getBody().getCommonTimeline().getInconsistencies();
66  Hashtable<String, String[]> annotationMismatches
67  = bt.getAnnotationMismatches();
68  if (duplicateTranscriptionTiers.length == 0 && orphanedTranscriptionTiers.length == 0 && orphanedAnnotationTiers.length == 0 && temporalAnomalies.length == 0) {
69  stats.addCorrect(function, cd, "No structure errors found.");
70  } else {
71  for (String tierID : duplicateTranscriptionTiers) {
72  stats.addCritical(function, cd,
73  "More than one transcription tier for one "
74  + "speaker. Tier: " + tierID + "Open in PartiturEditor, "
75  + "change tier type or merge tiers.");
76  exmaError.addError(function, filename, tierID, "", false,
77  "More than one transcription tier for one speaker. Tier: "
78  + tierID + ". Change tier type or merge tiers.");
79  }
80  for (String tliID : temporalAnomalies) {
81  stats.addCritical(function, cd,
82  "Temporal anomaly at timeline item: " + tliID);
83  exmaError.addError(function, filename, "", "", false,
84  "Temporal anomaly at timeline item: " + tliID);
85  }
86  for (String tierID : orphanedTranscriptionTiers) {
87  stats.addCritical(function, cd,
88  "Orphaned transcription tier:" + tierID);
89  exmaError.addError(function, filename, tierID, "", false,
90  "Orphaned transcription tier:" + tierID);
91  }
92  for (String tierID : orphanedAnnotationTiers) {
93  stats.addCritical(function, cd,
94  "Orphaned annotation tier:" + tierID);
95  exmaError.addError(function, filename, tierID, "", false,
96  "Orphaned annotation tier:" + tierID);
97  }
98  for (String tierID : annotationMismatches.keySet()) {
99  String[] eventIDs = annotationMismatches.get(tierID);
100  for (String eventID : eventIDs) {
101  stats.addCritical(function, cd,
102  "Annotation mismatch: tier " + tierID
103  + " event " + eventID);
104  exmaError.addError(function, filename, tierID, eventID, false,
105  "Annotation mismatch: tier " + tierID
106  + " event " + eventID);
107  }
108  }
109  }
110 
111  return stats;
112  }
113 
119  @Override
120  public Collection<Class<? extends CorpusData>> getIsUsableFor() {
121  try {
122  Class cl = Class.forName("de.uni_hamburg.corpora.BasicTranscriptionData");
123  IsUsableFor.add(cl);
124  } catch (ClassNotFoundException ex) {
125  report.addException(ex, " usable class not found");
126  }
127  return IsUsableFor;
128  }
129 
134  @Override
135  public String getDescription() {
136  String description = "This class checks basic transcription files for structural anomalies. ";
137  return description;
138  }
139 
140  @Override
141  public Report function(Corpus c, Boolean fix) throws SAXException, IOException, ParserConfigurationException, URISyntaxException, JDOMException, TransformerException, XPathExpressionException, JexmaraldaException {
142  Report stats = new Report();
143  for (CorpusData cdata : c.getBasicTranscriptionData()) {
144  stats.merge(function(cdata, fix));
145  }
146  return stats;
147  }
148 }
void merge(Report sr)
Definition: Report.java:73
void addCritical(String description)
Definition: Report.java:104
void addCorrect(String statId, String description)
Definition: Report.java:217
Collection< Class<?extends CorpusData > > getIsUsableFor()
void addException(Throwable e, String description)
Definition: Report.java:287